SQLSTATE 25P03Severity mediumLab verified

Incident brief

Idle in transaction session timeout

A session left an open transaction sitting idle (no query in flight) for longer than idle_in_transaction_session_timeout. PostgreSQL terminated the connection instead of letting it hold locks and a snapshot indefinitely.

What lands in your log

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

Reproduced on PostgreSQL 16.14Verified 2026-07-16 (Docker lab, PostgreSQL 16.14)Verified against PostgreSQL 16.14 in an isolated lab environment

In 10 seconds

What triggers it
SET idle_in_transaction_session_timeout to a short value.
Fix
Don't leave a BEGIN open while waiting on something outside the database (user input, an external API call). Commit or roll back first, then reopen a transaction when you're ready to continue.
Proof
Reproduced on PostgreSQL 16.14 → A transaction left genuinely idle (no query sent, only a client-side pause) past the configured timeout was terminated by the server with SQLSTATE 25P03.

Fix

What to do right now

Application-level steps for this error.

  • Don't leave a BEGIN open while waiting on something outside the database (user input, an external API call). Commit or roll back first, then reopen a transaction when you're ready to continue.
  • Set idle_in_transaction_session_timeout as a safety net so a forgotten open transaction can't hold locks and an old snapshot forever.
Fix SQL
-- application pattern: don't hold BEGIN open across an external wait
COMMIT; -- release the transaction before waiting on something external
-- ... do the external work here, outside any transaction ...
BEGIN;  -- reopen only when ready to continue

Verification

PG 16.14
Last verified
2026-07-16 (Docker lab, PostgreSQL 16.14)
Verification scope
Verified against PostgreSQL 16.14 in an isolated lab environment
Audit status
reviewed
ShareLinkedInX

Went further?

Pro unlocks the second lab proof

Free page stops the bleeding. Pro adds the operational test, SQLSTATE audit, and deeper evidence, same error, more certainty.

FollowSubstackLinkedInnew errors · lab notes · hiring loops