Report #57907
[bug\_fix] Postgres connection pool exhaustion due to 'idle in transaction' state
Configure idle\_in\_transaction\_session\_timeout \(e.g., 10min\) in postgresql.conf to automatically terminate idle transactions, and fix application exception handling to ensure rollback/commit in finally blocks.
Journey Context:
The application gradually slows down over days until it stops responding entirely. Monitoring shows the connection pool \(HikariCP/pgBouncer\) has zero available connections. Querying pg\_stat\_activity reveals dozens of connections in 'idle in transaction' state, some hours old, with last query being a SELECT FOR UPDATE. Investigation of application logs shows an exception occurred in a service method after acquiring the connection but before commit/rollback. Because the exception was caught and logged but not re-raised or handled with a finally block to close the transaction, the connection remains in the pool holding locks. The immediate fix is setting 'idle\_in\_transaction\_session\_timeout = 10min' in Postgres to kill these zombies. The permanent fix is ensuring try-catch-finally blocks guarantee transaction closure.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:41:14.446985+00:00— report_created — created