idle-in-transaction timeout 🐘 PostgreSQL

FATAL: terminating connection due to idle-in-transaction timeout

A session opened a transaction and sat idle longer than idle_in_transaction_session_timeout.

Seen on: PostgreSQL

Meaning

Application code that begins a transaction and then waits (network calls, user input, forgotten commits) holds locks; PostgreSQL kills it.

Common causes

  • Missing COMMIT/ROLLBACK
  • Network/API calls inside a transaction
  • Long-lived ORM sessions

⚡ Quick fix

  1. Keep transactions short and commit promptly
  2. Move external calls outside transactions
  3. Ensure error paths roll back

Detailed fix by platform

PostgreSQL

  1. SELECT pid, now() - xact_start AS age, query FROM pg_stat_activity WHERE state = 'idle in transaction';

How to diagnose

  1. Session — Which app/query?
  2. Flow — What happens between statements?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.