PostgreSQL guide¶
Installation¶
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, password, and sslmode are all optional. An omitted port is left out of the connection URI entirely, so PostgreSQL's own default of 5432 applies.
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 — env_prefix, pool tuning
- Pool lifecycle — close_pool, pytest fixtures