25P03
PostgreSQLERRORNotableInvalid Transaction StateHIGH confidence

idle in transaction session timeout

What this means

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.

Why it happens
  1. 1An application opened a transaction (BEGIN) and then stopped sending queries, holding the transaction open beyond idle_in_transaction_session_timeout
  2. 2Long-running application pause, network stall, or debugging session inside a BEGIN block
How to reproduce

Application holds an open transaction for too long without activity.

trigger — this will error
trigger — this will error
-- 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.

Increase idle_in_transaction_session_timeout if legitimate long transactions are needed
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.

What not to do

Set idle_in_transaction_session_timeout = 0 (disabled)

Disabling it allows runaway idle transactions to hold locks indefinitely, blocking other sessions.

Version notes
Postgres 9.6+

idle_in_transaction_session_timeout parameter introduced in Postgres 9.6.

Sources
Official documentation ↗

Class 25 — Invalid Transaction State (Postgres-specific)

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors