Diagnostic Queries
Symptoms
A transaction was cancelled because it ran longer than transaction_timeout (introduced in PostgreSQL 17). PostgreSQL terminates it with SQLSTATE 25P04.
- The whole transaction exceeded
transaction_timeout. - Caps total transaction duration (active plus idle).
- Complements statement and idle-in-transaction timeouts.
What the server log shows
FATAL: terminating connection due to transaction timeout
Why PostgreSQL raises this — what the manual says
Section 19.11.1 Statement Behavior (transaction_timeout):
“Terminate any session that spans longer than the specified amount of time in a transaction.”
transaction_timeout bounds the total wall-clock time a transaction may run, regardless of whether it is executing or idle. When a transaction exceeds it, PostgreSQL terminates the session with 25P04.
Common causes
- A transaction (active or idle) running past the configured limit.
- Long batch operations within a single transaction.
transaction_timeoutset lower than legitimate transaction durations.
Relevant GUC parameters
| Parameter | Default | Effect |
|---|---|---|
transaction_timeout |
0 | Maximum total duration of any transaction; 0 disables (PG17+). |
How to fix it
- Break long work into smaller transactions.
- Raise
transaction_timeoutfor workloads that legitimately need it. - Investigate why the transaction runs so long (locks, slow steps, idle waits).
Related & next steps
Reference: PostgreSQL 18 Section 20.10 “Client Connection Defaults”.
Thanks — noted. This helps keep the database accurate.