25P04ERRORTier 2 — Caution✅ HIGH confidencetransaction 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
- 1A transaction (BEGIN...COMMIT) runs longer than the transaction_timeout setting
How to reproduce
Long-running transaction exceeding transaction_timeout.
-- In postgresql.conf or session:
-- transaction_timeout = 30s
-- Any transaction running longer than 30s raises 25P04Fix 1: Break long transactions into smaller units
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 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.
Version notes
Postgres 17+transaction_timeout parameter and SQLSTATE 25P04 introduced in Postgres 17.Sources
📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html
🔧 Source ref: Class 25 — Invalid Transaction State (Postgres-specific)
Confidence assessment
✅ HIGH confidence
Postgres-specific, added in Postgres 17. Behaviour documented in release notes.
See also
🔗 Related errors
📄 Reference pages