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

# PostgresStorage

> PostgreSQL storage for production systems

## Overview

`PostgresStorage` provides a PostgreSQL-based storage backend. Ideal for production deployments, multi-node systems, and applications requiring ACID compliance.

## Install

<Note>
  Install the PostgreSQL storage optional dependency group:

  ```bash theme={null}
  uv pip install "upsonic[postgres-storage]"
  ```
</Note>

## Basic Usage

```python theme={null}
from upsonic import Agent, Task
from upsonic.storage.memory import Memory
from upsonic.storage.postgres import PostgresStorage

storage = PostgresStorage(
    db_url="postgresql://user:password@localhost:5432/mydb"
)

memory = Memory(
    storage=storage,
    session_id="session_001",
    user_id="user_123",
    full_session_memory=True,
    summary_memory=True,
    user_analysis_memory=True,
    model="anthropic/claude-sonnet-4-5"
)

agent = Agent("anthropic/claude-sonnet-4-5", memory=memory)

result1 = agent.do(Task("My name is Alice"))
result2 = agent.do(Task("What's my name?"))
print(result2)  # "Your name is Alice"
```

## Parameters

| Parameter | Type | Default | Description |
| - | - | - | - |
| `db_url` | `str \| None` | `None` | PostgreSQL connection URL |
| `db_engine` | `Engine \| None` | `None` | Pre-configured SQLAlchemy Engine |
| `db_schema` | `str \| None` | `"public"` | PostgreSQL schema to use |
| `session_table` | `str \| None` | `"upsonic_sessions"` | Session table name |
| `user_memory_table` | `str \| None` | `"upsonic_user_memories"` | User memory table name |
| `knowledge_table` | `str \| None` | `"upsonic_knowledge"` | Knowledge document registry table name (used by KnowledgeBase) |
| `create_schema` | `bool` | `True` | Auto-create schema if not exists |
| `id` | `str \| None` | auto-generated | Storage instance ID |

## Storage Type

`PostgresStorage` is a **synchronous** storage implementation using SQLAlchemy with psycopg2 driver.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.