idle in transaction session timeout
SQLSTATE 25P03 is raised when a session has been idle inside a transaction for longer than the idle_in_transaction_session_timeout setting. Postgres terminates the session to reclaim resources held by the open transaction.
- 1An application opened a transaction (BEGIN) and then stopped sending queries, holding the transaction open beyond idle_in_transaction_session_timeout
- 2Long-running application pause, network stall, or debugging session inside a BEGIN block
Application holds an open transaction for too long without activity.
-- In postgresql.conf: -- idle_in_transaction_session_timeout = 30s
expected output
FATAL: terminating connection due to idle-in-transaction timeout
Fix 1
Keep transactions short and release them promptly
WHEN Always in production.
Why this works
Complete transactions quickly — do not hold open transactions across user-facing latency, network calls, or sleep() delays. Commit or rollback immediately after the last query.
Fix 2
Increase idle_in_transaction_session_timeout if legitimate long transactions are needed
WHEN When a known long-running transaction process is expected.
SET idle_in_transaction_session_timeout = '5min';
Why this works
Raising the timeout gives the session more time, but should be accompanied by ensuring the transaction eventually completes.
✕ Set idle_in_transaction_session_timeout = 0 (disabled)
Disabling it allows runaway idle transactions to hold locks indefinitely, blocking other sessions.
idle_in_transaction_session_timeout parameter introduced in Postgres 9.6.
Class 25 — Invalid Transaction State (Postgres-specific)
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev