Parameter · Client Connection Defaults / Statement Behavior
transaction_timeout
Sets the maximum allowed duration of any transaction within a session (not a prepared transaction). 0 disables the timeout.
- Default:
0 - Type: integer (ms)
- Range: 0 … max (2147483647)
- Applies: Session (any user)
In plain words
New in PostgreSQL 17. Limits the total time of a transaction, from BEGIN to COMMIT, counting both running and idle time. When the limit is hit, the whole session is terminated, not just the statement.
For DBAs and operators
Applies to explicit transactions and to the implicit transaction of a single statement. On expiry the backend terminates:
FATAL: terminating connection due to transaction timeout
That is stronger than statement_timeout (ERROR, session survives). Use it to bound how long any transaction can hold locks and hold back the xmin horizon, which statement and idle timeouts alone cannot do (a transaction of many short statements with short pauses escapes both).
Interactions from the documentation: if transaction_timeout is shorter than or equal to idle_in_transaction_session_timeout or statement_timeout, the longer timeout is ignored. Prepared transactions (2PC) are not subject to it.
Setting it in postgresql.conf is discouraged since it affects every session, including long maintenance runs (pg_dump sets it to 0 for its own session). Set it per role: ALTER ROLE webapp SET transaction_timeout = '5min'. Make sure poolers and applications handle the terminated connection (reconnect and retry).
How to change it
Any user can change it for their session with SET.
See it in context
Related parameters
statement_timeout idle_in_transaction_session_timeout idle_session_timeout lock_timeout