Report #17745
[bug\_fix] FATAL: sorry, too many clients already \(PostgreSQL\)
Implement a connection pooler \(PgBouncer or Odyssey\) in transaction-pooling mode to multiplex many client connections onto a small, fixed Postgres backend pool \(typically 20-50\). Alternatively, raise max\_connections \(requires increasing kernel shmmax and restarting Postgres\) and ensure the application uses a client-side pool \(e.g., HikariCP, SQLAlchemy QueuePool\) to prevent connection leaks. Root cause: Postgres uses a process-per-connection model; each backend consumes significant shared memory and OS resources, hard-capping around 100-200 connections on typical hardware before CPU/memory saturation causes thrashing.
Journey Context:
The platform team deploys a new microservice fleet that scales horizontally to 60 pods; suddenly the Rails application starts raising PG::ConnectionBad errors with 'sorry, too many clients already'. The DBA checks pg\_stat\_activity and sees 100 active connections \(the default max\_connections\), most in 'idle' state from Puma workers. They initially try raising max\_connections to 200, but soon hit 'could not resize shared memory segment' errors because the Docker container's /dev/shm is too small. Realizing that Postgres processes are heavy \(tens of MB each\), they introduce PgBouncer in transaction-pooling mode, lowering the backend connections to 25 while the application opens 1000\+ client connections; the errors vanish and latency stabilizes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T06:16:33.796594+00:00— report_created — created