PostgreSQL
PostgreSQL conversation store setup
PostgreSQL
PostgreSQL is the recommended production database for conversation persistence.
Installation
pip install "praisonaiagents[tools]"Docker Setup
docker run -d --name praison-postgres -p 5432:5432 \
-e POSTGRES_PASSWORD=praison123 \
-e POSTGRES_DB=praisonai \
postgres:16Quick Start
from praisonaiagents import Agent
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant.",
memory={
"db": "postgresql://postgres:praison123@localhost:5432/praisonai",
"session_id": "my-session"
}
)
response = agent.start("Hello!")
print(response)Connection String Format
postgresql://username:password@host:port/databaseExample:
from praisonaiagents import Agent
agent = Agent(
name="Bot",
memory={"db": "postgresql://user:password@host:5432/mydb"}
)Credentials with special characters “just work” through the structured constructor:
from praisonaiagents import Agent, MemoryConfig
from praisonaiagents.db import PostgresDB
# Password contains '@' — the structured constructor handles the escaping.
agent = Agent(
name="Assistant",
memory=MemoryConfig(
session_id="my-session",
db=PostgresDB(
host="localhost",
port=5432,
database="praisonai",
user="postgres",
password="p@ss/w0rd!",
),
),
)Environment Variables
export PRAISON_CONVERSATION_URL="postgresql://postgres:praison123@localhost:5432/praisonai"import os
from praisonaiagents import Agent
agent = Agent(
name="Assistant",
memory={"db": os.getenv("PRAISON_CONVERSATION_URL")}
)CLI
# Validate connection
praisonai persistence doctor \
--conversation-url "postgresql://postgres:praison123@localhost/praisonai"
# Run with persistence
praisonai persistence run \
--conversation-url "postgresql://postgres:praison123@localhost/praisonai" \
--session-id "cli-session" \
"Hello!"Schema
Tables are auto-created:
praison_sessions– Session metadatapraison_messages– Conversation messages
Troubleshooting
Connection refused:
# Check if PostgreSQL is running
docker ps | grep postgres
# Check logs
docker logs praison-postgresAuthentication failed:
- Verify username/password
- Check
pg_hba.conffor connection rules