PG
PRO
25P04ERRORTier 2 — Caution✅ HIGH confidence

transaction timeout

Category: Invalid Transaction StateVersions: Postgres 17+

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
-- In postgresql.conf or session:
-- transaction_timeout = 30s
-- Any transaction running longer than 30s raises 25P04
ERROR: terminating connection due to transaction timeout

Fix 1: Break long transactions into smaller units

When a business process requires many operations.

fix

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.

fix
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

⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →