Report #88379
[bug\_fix] PostgreSQL connection limit exhaustion \(FATAL: sorry, too many clients already\)
Implement a connection pooler \(PgBouncer in transaction pooling mode\) between the application and PostgreSQL to multiplex many application connections over a small, fixed number of actual PostgreSQL backend processes. Root cause: PostgreSQL uses a process-per-connection model where each backend consumes significant memory \(work\_mem, maintenance\_work\_mem\); default max\_connections \(100\) is easily exhausted by microservices with high worker counts, and raising the limit causes OOM.
Journey Context:
You deploy a new microservice with 50 pods, each spawning 20 workers, all connecting directly to an RDS Postgres instance. Within minutes, logs flood with "FATAL: sorry, too many clients already." You check pg\_stat\_activity and see 200 idle connections. You attempt to raise max\_connections to 500, but Postgres is OOM-killed because each backend reserves ~10MB RAM. You realize the architecture violates the principle that apps should not connect directly to Postgres at scale. You introduce PgBouncer in transaction pooling mode, set default\_pool\_size to 25, and configure the app to connect to PgBouncer instead. Now 1000 application connections transparently share 25 actual Postgres backends. The connection errors vanish and memory usage remains stable under load.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T06:55:48.517418+00:00— report_created — created