Report #69001
[bug\_fix] FATAL: terminating connection due to idle-in-transaction timeout
Set the PostgreSQL parameter idle\_in\_transaction\_session\_timeout \(e.g., to '5min'\) in postgresql.conf or via SET command to automatically terminate connections holding transactions open without activity. Simultaneously, fix application logic to ensure transactions are committed or rolled back immediately after work completes, avoiding waiting for user input or external APIs while inside a transaction block. Root cause: Open transactions hold row locks and block vacuum operations, causing table bloat and performance degradation; idle connections waste resources.
Journey Context:
A Rails admin panel allows managers to edit complex reports. A developer wraps the edit action in a transaction block to ensure atomicity. However, the view renders a form and waits for the user to submit, keeping the database transaction open for the entire HTTP request duration. As more admins use the tool, the database accumulates connections in 'idle in transaction' state \(visible in pg\_stat\_activity\). Autovacuum cannot clean dead tuples, tables bloat, and queries slow down. Eventually, the DBA sees FATAL: terminating connection due to idle-in-transaction timeout in logs after implementing the timeout setting. The developer realizes the transaction was held open across user think-time, refactors to use optimistic locking outside the transaction block, and sets idle\_in\_transaction\_session\_timeout as a safety net.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T22:18:03.343359+00:00— report_created — created