Connection pooling and configuration

Maria Garcia Feb 2026
2 tabs
; PgBouncer configuration file

[databases]
; Database connection strings
mydb = host=localhost port=5432 dbname=mydb
analytics = host=replica.example.com port=5432 dbname=mydb

; Fallback database
* = host=localhost port=5432

[pgbouncer]
; Listen on all interfaces
listen_addr = *
listen_port = 6432

; Authentication
auth_type = md5
auth_file = /etc/pgbouncer/userlist.txt

; Pool mode
; session: Client stays connected to same server (most compatible)
; transaction: Server assigned per transaction (more efficient)
; statement: Server assigned per statement (most efficient, breaks some features)
pool_mode = transaction

; Connection limits
max_client_conn = 1000
default_pool_size = 25
min_pool_size = 10
reserve_pool_size = 5
reserve_pool_timeout = 3

; Server connection limits
server_lifetime = 3600
server_idle_timeout = 600
server_connect_timeout = 15

; Client connection limits
client_idle_timeout = 0
client_login_timeout = 60

; DNS
dns_max_ttl = 15
dns_zone_check_period = 0

; Logging
log_connections = 1
log_disconnections = 1
log_pooler_errors = 1

; Admin console
admin_users = admin
stats_users = stats

; Performance
max_packet_size = 2147483647
pkt_buf = 4096
listen_backlog = 128

; TLS/SSL
; server_tls_sslmode = prefer
; client_tls_sslmode = disable
2 files · ini, sql Explain with highlit

Connection pooling reuses database connections across requests. Creating connections is expensive—pooling amortizes overhead. I use PgBouncer for PostgreSQL, ProxySQL for MySQL. Session pooling maintains session state. Transaction pooling is more efficient but stateless. Statement pooling shares single connection. Pool sizing depends on workload—too few causes queuing, too many overwhelms database. Understanding max_connections limits prevents failures. Connection timeout configuration prevents hung connections. Idle connection cleanup frees resources. Health checks remove broken connections. Proper pooling enables thousands of app connections with hundreds of database connections. Load balancing distributes across read replicas. Connection pooling is essential for web applications at scale.