transaction timeout
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.
- 1A transaction (BEGIN...COMMIT) runs longer than the transaction_timeout setting
Long-running transaction exceeding transaction_timeout.
-- 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.
SET transaction_timeout = '10min'; BEGIN; -- long operation COMMIT;
Why this works
Setting transaction_timeout per session allows controlled exceptions for specific workflows.
transaction_timeout parameter and SQLSTATE 25P04 introduced in Postgres 17.
Class 25 — Invalid Transaction State (Postgres-specific)
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev