# PgBouncer Configuration for mockupAWS v1.0.0
# Production-ready connection pooling

[databases]
# Main database connection
mockupaws = host=postgres port=5432 dbname=mockupaws

# Read replica (if configured)
# mockupaws_read = host=postgres-replica port=5432 dbname=mockupaws

[pgbouncer]
# Connection settings
listen_addr = 0.0.0.0
listen_port = 6432
unix_socket_dir = /var/run/postgresql

# Authentication
auth_type = md5
auth_file = /etc/pgbouncer/userlist.txt
auth_query = SELECT usename, passwd FROM pg_shadow WHERE usename=$1

# Pool settings - optimized for web workload
pool_mode = transaction
max_client_conn = 1000
default_pool_size = 25
min_pool_size = 5
reserve_pool_size = 5
reserve_pool_timeout = 3
max_db_connections = 100
max_user_connections = 100

# Connection limits (per pool)
server_idle_timeout = 600
server_lifetime = 3600
server_connect_timeout = 15
server_login_retry = 15

# Query timeouts (production safety)
query_timeout = 0
query_wait_timeout = 120
client_idle_timeout = 0
client_login_timeout = 60
idle_transaction_timeout = 0

# Logging
log_connections = 1
log_disconnections = 1
log_pooler_errors = 1
log_stats = 1
stats_period = 60
verbose = 0

# Administration
admin_users = postgres, pgbouncer
stats_users = stats, postgres

# TLS/SSL (enable in production)
# client_tls_sslmode = require
# client_tls_key_file = /etc/pgbouncer/server.key
# client_tls_cert_file = /etc/pgbouncer/server.crt
# server_tls_sslmode = prefer

# Extra features
application_name_add_host = 1
dns_max_ttl = 15
dns_nxdomain_ttl = 15

# Performance tuning
pkt_buf = 8192
max_packet_size = 2147483647
sbuf_loopcnt = 5
suspend_timeout = 10
tcp_keepalive = 1
tcp_keepcnt = 9
tcp_keepidle = 7200
tcp_keepintvl = 75
