SQLSTATE 25P04 ERROR Class 25: Invalid Transaction State

transaction_timeout Transaction Timeout — SQLSTATE 25P04

A transaction exceeded transaction_timeout and was aborted (PostgreSQL 17+).

PG 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Symptoms

A transaction exceeded transaction_timeout and was aborted (PostgreSQL 17+).

  • The error is written to the server log and returned to the client carrying SQLSTATE 25P04.
  • Any driver (libpq, JDBC, psycopg, npgsql, pgx) surfaces this code in its error object so you can branch on it programmatically.
  • PL/pgSQL can trap it by name: EXCEPTION WHEN transaction_timeout THEN.

Environment

Severity: ERROR  |  PostgreSQL versions: 12, 13, 14, 15, 16, 17

Reproduce with the exact statement and read the full message in the server log (raise log_min_messages / set log_min_error_statement for more context).

Root Cause

PostgreSQL 17 added transaction_timeout; a transaction running longer than the limit (idle or active) is terminated.

Diagnostic Queries

Recovery

Steps to resolve 25P04:

  1. Shorten the transaction or raise transaction_timeout for the workload.
  2. Split long batch work into smaller transactions.

Reference: PostgreSQL error codes — Class 25 (Invalid Transaction State).

Was this helpful?