Report #49307
[bug\_fix] Postgres FATAL: sorry, too many clients already
Place PgBouncer \(or RDS Proxy\) in transaction pooling mode between the application and Postgres, reducing the application-side connection pool to 2-5 and limiting Postgres max\_connections to a calculated value based on RAM \(typically 100-200\), rather than increasing max\_connections indefinitely.
Journey Context:
Deploying a Node.js microservice with 8 instances, each with a default Pool size of 10. Locally everything works, but in production interspersed with 500 errors, logs show 'FATAL: sorry, too many clients already'. Checking pg\_stat\_activity reveals 100 active connections \(the default max\_connections\). Initial instinct is to raise max\_connections to 500 in postgresql.conf, but after restarting, the system soon crashes with out-of-memory errors because each connection consumes work\_mem and overhead. Digging deeper, realize that with microservices scaling horizontally, the math is impossible: 20 pods × 20 connections = 400, and it grows linearly with replicas. The breakthrough comes from reading about Postgres architecture: it forks a process per connection, making high connection counts memory-prohibitive. The solution is to introduce an external pooler like PgBouncer in transaction mode, which multiplexes hundreds of application connections onto a few dozen actual Postgres connections by keeping transactions stateless. This fixes the client limit without memory bloat.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:14:28.381794+00:00— report_created — created