PostgreSQL guide¶
Install the PostgreSQL extra:
Or with uv:
Connection¶
PostgreSQLConfig supports URI-based and individual field connection specification.
URI mode¶
from adbc_poolhouse import PostgreSQLConfig, create_pool
config = PostgreSQLConfig(
uri="postgresql://me:s3cret@db.example.com:5432/mydb?sslmode=require", # pragma: allowlist secret
)
pool = create_pool(config)
Individual fields¶
from adbc_poolhouse import PostgreSQLConfig, create_pool
config = PostgreSQLConfig(
host="db.example.com",
user="me",
password="s3cret", # pragma: allowlist secret
database="mydb",
sslmode="require",
)
pool = create_pool(config)
port defaults to 5432 when omitted. password and sslmode are optional.
Loading from environment variables¶
PostgreSQLConfig reads fields from environment variables with the POSTGRESQL_ prefix:
export POSTGRESQL_HOST=db.example.com
export POSTGRESQL_USER=me
export POSTGRESQL_PASSWORD=s3cret # pragma: allowlist secret
export POSTGRESQL_DATABASE=mydb
See also¶
- Configuration reference — env_prefix, pool tuning
- Pool lifecycle — close_pool, pytest fixtures