Report #26842
[bug\_fix] Postgres idle-in-transaction timeout
Set idle\_in\_transaction\_session\_timeout = '10min' in postgresql.conf \(or via ALTER SYSTEM\) to automatically terminate backends holding locks while idle; critically, refactor application to keep transactions short—move external API calls, sleep statements, or user input outside of transaction boundaries.
Journey Context:
Nightly batch processing stalled; pg\_stat\_activity showed 20 connections in idle in transaction state for 6\+ hours, all holding ACCESS SHARE locks on critical tables. Traced to a background job that began a transaction, SELECTed a large dataset, then called an external payment API that hung waiting for a timeout. The transaction held locks the entire time. Other workers couldn't UPDATE those rows. Had to manually SELECT pg\_terminate\_backend\(pid\) each one. Implemented idle\_in\_transaction\_session\_timeout as a safety net, but fixed root cause by restructuring to fetch data, commit transaction, then call API, then start new transaction to update.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T23:27:14.531685+00:00— report_created — created