Report #13615
[bug\_fix] FATAL: sorry, too many clients already
Reduce per-instance connection pool size to 2-3 and introduce PgBouncer in transaction pooling mode to multiplex many application connections onto fewer PostgreSQL backends, or increase max\_connections \(requires restart\). Root cause: Horizontal pod autoscaling creates more instances than the max\_connections limit can support when each instance maintains its own persistent connection pool.
Journey Context:
The team deployed a microservices architecture on Kubernetes with Horizontal Pod Autoscaler \(HPA\). During a traffic spike, pods scaled from 3 to 20 instances. Each pod had a connection pool configured for 10 connections. Suddenly, the application logs showed 'FATAL: sorry, too many clients already' and cascading service failures. The developer checked \`SELECT count\(\*\) FROM pg\_stat\_activity;\` and saw 100\+ active connections, hitting the default max\_connections limit. They realized that connection pooling in the app was per-pod, not shared, and there was no external pooler. Checking \`pg\_stat\_activity\` revealed that 80% of connections were idle in transaction state, merely holding slots. The 'why' of the fix is that PgBouncer in transaction pooling mode decouples the client connection from the backend connection, allowing 1000s of app connections to share a pool of 20-50 actual Postgres backends, while reducing per-pod pools prevents connection hoarding during scale-up.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T19:14:41.090703+00:00— report_created — created