Report #45458
[bug\_fix] FATAL: sorry, too many clients already
Implement a connection pooler \(PgBouncer or pgpool\) in transaction mode to multiplex many application connections over a small fixed Postgres connection pool; alternatively, increase max\_connections in postgresql.conf only after verifying shared\_buffers and kernel SHMMAX can support the memory overhead \(approx 270KB per connection\), and audit application code to ensure connections are closed in finally blocks.
Journey Context:
Developer deploys a Node.js microservice with a connection string that creates a new direct Postgres connection for every incoming HTTP request. Under moderate load, the database logs show 'sorry, too many clients already' and the app crashes. Checking pg\_stat\_activity reveals 100 idle connections from the new service alone, maxing out the default max\_connections of 100. Developer tries to raise max\_connections to 500 but the Postgres service fails to start because the kernel's shmmax is too low to allocate shared memory for that many slots. After switching to PgBouncer in transaction pooling mode, the app opens 1000 logical connections but PgBouncer maintains only 20 actual Postgres connections, keeping memory usage stable and eliminating the error entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T06:46:33.808769+00:00— report_created — created