25P04
PostgreSQLERRORNotableInvalid Transaction StateHIGH confidence

transaction timeout

What this means

SQLSTATE 25P04 is raised when a transaction exceeds the transaction_timeout setting. Postgres terminates the transaction to prevent excessively long-running transactions from holding locks.

Why it happens
  1. 1A transaction (BEGIN...COMMIT) runs longer than the transaction_timeout setting
How to reproduce

Long-running transaction exceeding transaction_timeout.

trigger — this will error
trigger — this will error
-- In postgresql.conf or session:
-- transaction_timeout = 30s
-- Any transaction running longer than 30s raises 25P04

expected output

ERROR:  terminating connection due to transaction timeout

Fix 1

Break long transactions into smaller units

WHEN When a business process requires many operations.

Why this works

Chunk large operations into smaller transactions so each completes within the timeout. Use application-level checkpointing to resume interrupted work.

Fix 2

Increase transaction_timeout for known long operations

WHEN When a specific process legitimately requires more time.

Increase transaction_timeout for known long operations
SET transaction_timeout = '10min';
BEGIN;
-- long operation
COMMIT;

Why this works

Setting transaction_timeout per session allows controlled exceptions for specific workflows.

Version notes
Postgres 17+

transaction_timeout parameter and SQLSTATE 25P04 introduced in Postgres 17.

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