In this article
Choose the timeout by the state it bounds, distinguish statement abort from session termination and leave prepared transactions to their explicit recovery protocol.
A request stops executing but keeps its transaction open
A service protects expensive SQL with statement_timeout. Its client then pauses between statements while leaving a transaction open. The statement limit does not describe that idle interval, so locks or old snapshots can remain despite the apparently strict query timeout.
The client-configuration reference defines different clocks for statement execution, whole transactions and idle sessions within transactions. Start recovery design by identifying the interval that stalled, rather than applying every setting as an interchangeable request deadline.
Bound the executing statement
Statement timeout measures server-side command handling through completion. The reference also describes protocol-specific details for simple and extended query messages. It is not a general stopwatch for all client-side work before submission or after receiving the result.
A lock timeout is narrower still: it bounds waiting for each lock acquisition attempt. A statement can spend time on other work outside that condition. Setting a lock limit does not create an equal execution limit for the complete operation.
Bound the whole transaction separately
Transaction timeout covers the duration spent in an explicit or implicit transaction and terminates the session when exceeded. That is a different effect from aborting an individual statement. A client connection pool must be prepared for the actual session outcome.
The reference describes precedence when transaction timeout is shorter than or equal to the other relevant limits. Do not add configured durations as if each necessarily grants a fresh sequential budget. Record effective settings and the resulting error path at the application boundary.
Bound client silence inside a transaction
Idle-in-transaction session timeout addresses waiting for the client’s next query while a transaction remains open. The manual explains that such transactions can retain locks and prevent cleanup of old row versions even without an actively executing query.
Distinguish this from an idle session outside a transaction, whose resource implications and separate setting differ. A dashboard showing no active statement must not automatically classify every connected session as harmless or every terminated idle connection as evidence of an expensive query.
Preserve the prepared-state exception
The configuration reference explicitly excludes prepared transactions from transaction timeout. The PREPARE TRANSACTION manual explains why: their state is detached from the original session and resolved through the external transaction manager’s decision.
Shared PostgreSQL resources gives the workload context. Ambiguous outcome recovery explains why a timeout response cannot settle every external business effect. Do not advertise a session timeout as cleanup for all unresolved transactional state.
Accept the clock and the failure effect
Use isolated cases for an executing statement, lock wait, client pause within a transaction and an overlong transaction spanning multiple statements. Observe which setting applies and whether the statement or session ends. These are proposed checks, not measured results. Acceptance includes connection-pool handling, explicit application recovery and unresolved outcome reconciliation. A short configured number alone does not prove that every part of a stalled service transaction has a bounded and correct recovery path.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.