Report #63672
[bug\_fix] FATAL: sorry, too many clients already
Implement PgBouncer \(or similar pooler\) in transaction pooling mode; reduce application-side connection pool size to 5-10; calculate max\_connections based on available RAM \(shared\_buffers \+ work\_mem \* max\_connections must fit\) or use an external pooler to multiplex thousands of app connections over ~20-50 actual Postgres connections.
Journey Context:
The Node.js service worked perfectly on a single dyno with a pool size of 20. After deploying to AWS ECS with 5 tasks, each with pool size 20, the database hit 100 connections immediately. Increasing max\_connections to 200 in postgresql.conf caused an OOM crash during the next traffic spike because shared\_buffers was fixed at 4GB and the kernel couldn't allocate more shared memory for the additional connection overhead. The developer checked pg\_stat\_activity and saw hundreds of idle connections from previous deploys that weren't being recycled fast enough. After reading the PgBouncer documentation, they switched the app to use PgBouncer in transaction mode \(pool\_mode=transaction\), reduced the app pool to 5, and set max\_client\_conn to 10000 in PgBouncer. This allowed the app to scale to hundreds of containers while Postgres saw only 25 actual connections, completely eliminating the error.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T13:21:44.807001+00:00— report_created — created