Report #45775
[bug\_fix] PostgreSQL FATAL: sorry, too many clients already
Implement a connection pooler \(PgBouncer, RDS Proxy, or pgpool\) between the application and database, or reduce application connection churn. Root cause: PostgreSQL creates a full OS process per connection \(default max 100\); without pooling, concurrent requests exhaust the backend slots, and idle connections from connection leaks compound the issue.
Journey Context:
The application performs flawlessly in development with a single user, but upon production launch with moderate traffic, interspersed FATAL errors crash the API with "sorry, too many clients already." Initial investigation via pg\_stat\_activity reveals nearly 100 idle connections from the app server that were never properly closed, despite the app using a connection pool. Realizing the pool size was set to 50 per worker process and there are 4 workers, quickly saturating the default max\_connections of 100. Attempting to simply raise max\_connections to 500 seems to work until the OOM killer terminates PostgreSQL due to excessive shared memory usage per backend process. Installing PgBouncer in transaction mode and reducing direct app connections to 20 multiplexed slots immediately resolves the saturation without memory pressure.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T07:18:38.053630+00:00— report_created — created