PostgreSQL

PostgreSQL conversation store setup

PostgreSQL

PostgreSQL is the recommended production database for conversation persistence.

Installation

bash
pip install "praisonaiagents[tools]"

Docker Setup

bash
docker run -d --name praison-postgres -p 5432:5432 \
    -e POSTGRES_PASSWORD=praison123 \
    -e POSTGRES_DB=praisonai \
    postgres:16

Quick Start

python
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/database

Example:

python
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:

python
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

bash
export PRAISON_CONVERSATION_URL="postgresql://postgres:praison123@localhost:5432/praisonai"
python
import os
from praisonaiagents import Agent

agent = Agent(
    name="Assistant",
    memory={"db": os.getenv("PRAISON_CONVERSATION_URL")}
)

CLI

bash
# 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 metadata
  • praison_messages – Conversation messages

Troubleshooting

Connection refused:

bash
# Check if PostgreSQL is running
docker ps | grep postgres

# Check logs
docker logs praison-postgres

Authentication failed:

  • Verify username/password
  • Check pg_hba.conf for connection rules