> ## Documentation Index
> Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# PostgreSQL

> PostgreSQL conversation store setup

# PostgreSQL

PostgreSQL is the recommended production database for conversation persistence.

## Installation

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
pip install "praisonaiagents[tools]"
```

## Docker Setup

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
docker run -d --name praison-postgres -p 5432:5432 \
    -e POSTGRES_PASSWORD=praison123 \
    -e POSTGRES_DB=praisonai \
    postgres:16
```

## Quick Start

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

agent = Agent(
    name="Bot",
    memory={"db": "postgresql://user:password@host:5432/mydb"}
)
```

## Environment Variables

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
export PRAISON_CONVERSATION_URL="postgresql://postgres:praison123@localhost:5432/praisonai"
```

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import os
from praisonaiagents import Agent

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

## CLI

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# 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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# 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
