Databases Practical By Samson Tanimawo, PhD Published May 22, 2025 4 min read

pgbouncer Deployment

Tactical setup.

Pooling modes

Session pooling: connection per client session. Lowest application impact; smallest connection multiplexing.

Transaction pooling: connection per transaction. Higher multiplexing; client cannot use prepared statements across transactions.

Statement pooling: connection per statement. Highest multiplexing; most application restrictions.

Configuration essentials

max_client_conn: max client connections to pgbouncer. Set higher than max database connections.

default_pool_size: connections to database per (user, database) pair. Match to actual database max_connections.

pool_mode: session, transaction, or statement. Match to application needs.

Deployment patterns

Sidecar per application pod. Local connectivity; failure isolated; scales with application.

Centralised pgbouncer cluster. Shared across applications; lower total cost; failure shared.

Hybrid: centralised primary; sidecar fallback. Resilience and efficiency.

Monitoring

SHOW POOLS in pgbouncer admin console: per-pool statistics.

Active vs idle connections. Connection wait time.

Database max_connections versus pgbouncer total connections. The math should always balance.