transaction_timeout
Read PG 18 manual ↗Terminate any session that spans longer than the specified amount of time in a transaction.
- Type
- integer
- Context
- user
- Measured default
- 0 ms
- Unit
- ms
- Metadata snapshot
- 18
Definition PG 18 manual
Terminate any session that spans longer than the specified amount of time in a transaction. The limit applies both to explicit transactions (started with BEGIN) and to an implicitly started transaction corresponding to a single statement. If this value is specified without units, it is taken as milliseconds. A value of zero (the default) disables the timeout.
If transaction_timeout is shorter or equal to idle_in_transaction_session_timeout or statement_timeout then the longer timeout is ignored.
Setting transaction_timeout in postgresql.conf is not recommended because it would affect all sessions.
Prepared transactions are not subject to this timeout.
Measured default history
| Version interval | Default |
|---|---|
| 17 – 19 | 0 ms |
Authored guidance from the GUC source snapshot; the version-specific manual above is the definition reference. View source ↗
How it works
transaction_timeout sets the maximum allowed duration of any transaction within a session (not a prepared transaction). 0 disables the timeout. It terminates the session rather than merely canceling one statement, excludes prepared transactions, and makes longer idle-in-transaction or statement timeouts ineffective when set lower.
transaction_timeout is a USER-context setting. An authorized role can change it for a session, while ALTER ROLE or ALTER DATABASE can establish a default for future sessions.
Timeouts overlap: the first applicable deadline wins, while client, pooler, TCP, and server cancellation behavior determines whether work is retried, canceled, or the session is closed.
Operational considerations
Changing transaction_timeout in one session and assuming role defaults, database defaults, or other pooled sessions changed with it.
Forgetting that zero usually disables the timeout or delegates behavior to the operating system.
Setting overlapping deadlines without deciding which layer owns retries, cancellation, and connection disposal.
Expecting it to resolve prepared transactions, which are explicitly excluded.
Workload guidance
OLAP: Analytical work usually needs a larger or job-specific transaction_timeout; preserve a finite guardrail for abandoned work without killing legitimate long scans.
OLTP: Set transaction_timeout from the service latency and failure budget, preferably per role or application. Test retries and cancellation paths before enforcing a cluster-wide value.
SMALL: Use a conservative finite transaction_timeout only when the client or operating system handles termination correctly; verify that maintenance still has a dedicated exception.
Version history 2
- PG 17 → 18changed
- PG 16 → 17added
Related entries
Further reading
Definition snapshot: english-manuals:fc78adf20f13dbaadf17ad670a6… · English manual source