Report #79372
[bug\_fix] FATAL: terminating connection due to idle-in-transaction timeout
Set idle\_in\_transaction\_session\_timeout to a reasonable value \(e.g., '5min'\) to automatically kill hung transactions, and fix application logic to commit or rollback transactions promptly without long pauses between queries.
Journey Context:
You notice the database disk usage growing rapidly and VACUUM unable to reclaim space \(bloat\). Checking pg\_stat\_activity, you see dozens of connections in state 'idle in transaction' for hours, some holding row locks. You trace them to a background job that opens a transaction, fetches a batch of rows, processes them in Python \(taking 30 minutes due to an external API call\), then commits. During this time, the transaction holds row locks and prevents vacuum from cleaning dead tuples. You set idle\_in\_transaction\_session\_timeout = '10min' in postgresql.conf and reload. The next day, those long jobs are killed with 'FATAL: terminating connection due to idle-in-transaction timeout'. The application logs show the error, and you fix the code to process in smaller batches with frequent commits, eliminating the idle-in-transaction state.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T15:49:28.262717+00:00— report_created — created