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

# PostgreSQL

> PostgreSQL adapter configuration for SQLBuild.

PostgreSQL requires the optional `psycopg` dependency:

```bash theme={null}
pip install 'sqlbuild[postgres]'
# or
uv pip install 'sqlbuild[postgres]'
```

## Connection config

```toml theme={null}
adapter = "postgres"

[connection]
host = "localhost"
port = 5432
user = "my_user"
password = "my_password"
dbname = "my_database"
```

| Field      | Description                                       |
| ---------- | ------------------------------------------------- |
| `host`     | PostgreSQL server hostname (default: `localhost`) |
| `port`     | PostgreSQL server port (default: `5432`)          |
| `user`     | Database user                                     |
| `password` | Database password                                 |
| `dbname`   | Database name                                     |

All fields in `connection` are passed to `psycopg.connect()`. See the [psycopg documentation](https://www.psycopg.org/psycopg3/docs/api/connections.html) for all available options.

## Per-target connections

```toml theme={null}
adapter = "postgres"

[connection]
host = "localhost"
user = "my_user"
password = "${ENV:PG_PASSWORD}"

[targets.prod]
schema = "prod"

[targets.prod.connection]
host = "prod-db.example.com"
dbname = "analytics"

[targets.dev]
schema = "dev"

[targets.dev.connection]
dbname = "analytics_dev"
```
