Report #4340
[bug\_fix] FATAL: sorry, too many clients already
Implement a connection pooler \(PgBouncer or pgpool\) between the application and PostgreSQL, or increase max\_connections in postgresql.conf if system resources permit. The root cause is that each application instance creates direct connections, exhausting PostgreSQL's max\_connections limit \(default 100\).
Journey Context:
Developer deploys a microservice with 10 instances, each configured with a connection pool of 20. Under load, the application starts throwing 'sorry, too many clients already' errors. Checking pg\_stat\_activity shows 200\+ connections. They try increasing max\_connections to 500 in postgresql.conf, but PostgreSQL fails to restart because the kernel SHMMAX limit is too low. After raising kernel shared memory limits, they realize 500 connections consume too much memory per connection \(work\_mem, etc.\). The actual fix is introducing PgBouncer as a sidecar container, pooling 1000s of application connections into ~50 actual PostgreSQL connections, dramatically reducing memory usage and eliminating the error.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:16:02.162047+00:00— report_created — created