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:
- Shorten the transaction or raise
transaction_timeoutfor the workload. - Split long batch work into smaller transactions.
Reference: PostgreSQL error codes — Class 25 (Invalid Transaction State).
Thanks — noted. This helps keep the database accurate.