Report #44902
[bug\_fix] Postgres idle-in-transaction timeout blocking queries
Set idle\_in\_transaction\_session\_timeout to a reasonable value \(e.g., 5 minutes\) and ensure application code has proper error handling that always calls rollback\(\) in finally blocks. Root cause: Application opens a transaction, encounters an exception or early return that skips commit/rollback, and returns the connection to the pool with the transaction still open, holding locks indefinitely.
Journey Context:
Your web API starts having sporadic 30-second timeouts on random endpoints. You check pg\_stat\_activity and see queries stuck in 'idle in transaction' state for 10\+ minutes, holding ExclusiveLock on critical tables and blocking all new queries. You kill the connection and the system recovers. You look at your Node.js code using node-postgres. You see you're using a manual transaction block with BEGIN. In one error handling path, you catch an error, log it, and return early without calling client.query\('COMMIT'\) or 'ROLLBACK'. The connection goes back to the generic pool with the transaction still open. Postgres's idle\_in\_transaction\_session\_timeout eventually kills it, but by then the damage is done. You fix the code to ensure rollback\(\) is called in a finally block, and you add SET idle\_in\_transaction\_session\_timeout = '5min' as a safety net in postgresql.conf.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T05:50:14.067894+00:00— report_created — created