Report #4102
[bug\_fix] FATAL: sorry, too many clients already \(connection pool exhaustion\)
Root cause is unbounded direct connections exceeding Postgres max\_connections. Do not increase max\_connections above ~200 without kernel tuning. The fix is to implement a connection pooler \(PgBouncer in transaction mode\) between apps and Postgres, multiplexing thousands of app connections onto ~100 actual Postgres connections. Alternatively, drastically reduce per-instance pool size \(e.g., 3-5\) ensuring \(instances \* pool\_size\) < max\_connections, and set aggressive idle timeouts.
Journey Context:
App launches fine, but under load 50% of requests fail with 'too many clients'. Developer checks RDS max\_connections \(100\). With 20 ECS tasks each creating 10 connections, limit is exhausted. Increasing max\_connections to 500 works briefly but fails at higher scale. Checking pg\_stat\_activity reveals 500 idle connections from app instances. Developer realizes each request opens a new Client without closing it, or pool size is too large. After implementing PgBouncer in transaction mode, 1000\+ app connections are served by 50 Postgres connections, eliminating the error.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T18:49:27.140502+00:00— report_created — created