> ## 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 工具

## 代码

```python cookbook/tools/postgres_tools.py theme={null}
from agno.agent import Agent
from agno.tools.postgres import PostgresTools

agent = Agent(
    tools=[PostgresTools(db_url="postgresql://user:pass@localhost:5432/db")],
    show_tool_calls=True,
    markdown=True,
)
agent.print_response("Show me all tables in the database")
```

## 用法

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="设置你的 API 密钥">
    ```bash theme={null}
    export OPENAI_API_KEY=xxx
    ```
  </Step>

  <Step title="设置你的数据库 URL">
    ```bash theme={null}
    export DATABASE_URL=postgresql://user:pass@localhost:5432/db
    ```
  </Step>

  <Step title="安装库">
    ```bash theme={null}
    pip install -U psycopg2-binary sqlalchemy openai agno
    ```
  </Step>

  <Step title="运行 Agent">
    <CodeGroup>
      ```bash Mac theme={null}
      python cookbook/tools/postgres_tools.py
      ```

      ```bash Windows theme={null}
      python cookbook/tools/postgres_tools.py
      ```
    </CodeGroup>
  </Step>
</Steps>
