Report #97194
[bug\_fix] FATAL: sorry, too many clients already \(SQLSTATE 53300\)
Introduce a connection pooler such as PgBouncer in transaction-pooling mode, or a correctly sized application-level pool, so that the sum of all app-instance pools stays well below PostgreSQL's max\_connections minus superuser\_reserved\_connections. Audit pg\_stat\_activity for idle or leaked connections, set idle\_in\_transaction\_session\_timeout, and close connections promptly. Only raise max\_connections after pooling is in place, because each backend consumes a process slot and shared memory.
Journey Context:
A FastAPI service running behind ten uvicorn workers on a single VM started throwing FATAL: sorry, too many clients already during a traffic spike. The developer first checked SHOW max\_connections and saw 100, then counted backends in pg\_stat\_activity and found 98 idle connections from the app. They realized each worker opened its own SQLAlchemy QueuePool with pool\_size=10 and max\_overflow=20, so ten workers times 30 connections overshot Postgres. Raising max\_connections to 500 briefly hid the error but caused memory pressure and slower autovacuum. The real fix was to run PgBouncer on localhost:6432 in transaction mode with default\_pool\_size=20, point all workers at the pooler, shrink each worker pool to a small overflow, and add idle\_in\_transaction\_session\_timeout='30s'. After the change the app served the same load with about 25 actual Postgres backends.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T04:42:32.905077+00:00— report_created — created