SQLSTATE 25P04 ERROR Class 25: Invalid Transaction State

idle_in_transaction_session_timeout canceling statement due to transaction timeout — 25P04

PostgreSQL error “canceling statement due to transaction timeout — 25P04” (SQLSTATE 25P04): what it means, common causes, and how to fix it.

PG 17, 18 Official docs
Last reviewed Jun 2026 Grounded in source

Diagnostic Queries

Symptoms

A transaction was cancelled because it ran longer than transaction_timeout (introduced in PostgreSQL 17). PostgreSQL terminates it with SQLSTATE 25P04.

  • The whole transaction exceeded transaction_timeout.
  • Caps total transaction duration (active plus idle).
  • Complements statement and idle-in-transaction timeouts.

What the server log shows

FATAL:  terminating connection due to transaction timeout

Why PostgreSQL raises this — what the manual says

Section 19.11.1 Statement Behavior (transaction_timeout):

“Terminate any session that spans longer than the specified amount of time in a transaction.”

transaction_timeout bounds the total wall-clock time a transaction may run, regardless of whether it is executing or idle. When a transaction exceeds it, PostgreSQL terminates the session with 25P04.

Common causes

  • A transaction (active or idle) running past the configured limit.
  • Long batch operations within a single transaction.
  • transaction_timeout set lower than legitimate transaction durations.

Relevant GUC parameters

Parameter Default Effect
transaction_timeout 0 Maximum total duration of any transaction; 0 disables (PG17+).

How to fix it

  1. Break long work into smaller transactions.
  2. Raise transaction_timeout for workloads that legitimately need it.
  3. Investigate why the transaction runs so long (locks, slow steps, idle waits).

Related & next steps

Reference: PostgreSQL 18 Section 20.10 “Client Connection Defaults”.

Was this helpful?