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

# Async PostgreSQL

> Persist Agno sessions and other data asynchronously in PostgreSQL.

`AsyncPostgresDb` stores Agent, Team, and Workflow sessions, memories, knowledge, evaluations, and traces asynchronously in [PostgreSQL](https://www.postgresql.org/).

## Usage

Install the `sqlalchemy`, `psycopg`, and `openai` packages:

```shell theme={null}
uv pip install sqlalchemy psycopg openai
```

```python async_postgres_for_agent.py theme={null}
from agno.agent import Agent
from agno.db.postgres import AsyncPostgresDb

db_url = "postgresql+psycopg_async://ai:ai@localhost:5532/ai"

db = AsyncPostgresDb(db_url=db_url)
agent = Agent(db=db)
```

Use async methods such as `Agent.arun()` and `Agent.aprint_response()` with this database.

### Run PostgreSQL

Install [Docker Desktop](https://docs.docker.com/get-started/get-docker/), then start PostgreSQL with pgvector on port `5532`:

```bash theme={null}
docker run -d \
  -e POSTGRES_DB=ai \
  -e POSTGRES_USER=ai \
  -e POSTGRES_PASSWORD=ai \
  -e PGDATA=/var/lib/postgresql \
  -v pgvolume:/var/lib/postgresql \
  -p 5532:5432 \
  --name pgvector \
  agnohq/pgvector:18
```

## Parameters

<Snippet file="db-async-postgres-params.mdx" />
