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

# Postgres Agent 存储

Agno 支持使用 `PostgresStorage` 类将 PostgreSQL 作为 Agent 的存储后端。

## 用法

### 运行 PgVector

安装 [docker desktop](https://docs.docker.com/desktop/install/mac-install/) 并使用以下命令在端口 **5532** 上运行 **PgVector**：

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

```python postgres_storage_for_agent.py theme={null}
from agno.storage.postgres import PostgresStorage

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

# 使用 Postgres 数据库创建存储后端
storage = PostgresStorage(
    # 将会话存储在 agent_sessions 表中
    table_name="agent_sessions",
    # db_url: Postgres 数据库 URL
    db_url=db_url,
)

# 将存储添加到 Agent
agent = Agent(storage=storage)
```

## 参数

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

## 开发者资源

* 查看 [Cookbook](https://github.com/agno-agi/agno/blob/main/cookbook/storage/postgres_storage/postgres_storage_for_agent.py)
