Report #11196
[bug\_fix] FATAL: sorry, too many clients already \(SQLSTATE 53300\)
Introduce a connection pooler \(PgBouncer or pgpool\) in transaction mode to multiplex thousands of application connections over a small, fixed number of actual PostgreSQL backends \(e.g., 20-50\). Do not simply raise max\_connections, as each backend is an OS process consuming significant RAM \(work\_mem, shared\_buffers overhead\) and context-switching resources.
Journey Context:
A developer deploys a new microservice that spawns 100 worker processes, each maintaining a persistent connection to Postgres. Initially, everything works. Under load, the app starts throwing 'sorry, too many clients already' errors. The developer checks pg\_stat\_activity and sees 100 idle connections, hitting the default max\_connections=100 limit. They consider raising max\_connections to 500 in postgresql.conf, but after doing so, the OS starts OOM-killing Postgres processes because each connection uses several megabytes of private memory. After researching, they realize the architecture is wrong: the app should connect to PgBouncer \(pool\_mode=transaction\), which keeps only 20 actual connections open to Postgres, recycling them between the 100 app workers. The errors stop, and memory usage remains flat.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T12:45:16.776443+00:00— report_created — created