DB Internals AtlasPostgreSQL 18.6 Home About

Parameter · Client Connection Defaults / Statement Behavior

statement_timeout

Sets the maximum allowed duration of any statement. 0 disables the timeout.

  • Default: 0
  • Type: integer (ms)
  • Range: 0 … max (2147483647)
  • Applies: Session (any user)

In plain words

A stopwatch for each statement. If a query is still running when the time is up, PostgreSQL cancels it with an error and the session can continue. It protects the server from runaway queries.

For DBAs and operators

Measured from when the command arrives at the server until it completes, including time spent waiting for locks. On expiry:

ERROR: canceling statement due to statement timeout

The statement is cancelled and the current transaction is aborted (until ROLLBACK); the session stays connected. If log_min_error_statement is ERROR or lower (default), the statement text is logged too.

Details: in a multi-statement simple-query string each statement is timed separately (since PostgreSQL 13). With the extended protocol the timer starts when any query-related message (Parse, Bind, Execute, Describe) arrives and is cancelled by completion of an Execute or by Sync. The setting does not apply to idle time.

Guidance: setting it in postgresql.conf affects every session, including manual VACUUM and index builds started by DBAs, which then fail mysteriously (pg_dump sets it to 0 for its own session). Prefer per role or per database:

ALTER ROLE webapp SET statement_timeout = '30s';
SET LOCAL statement_timeout = '5min';   -- just this transaction

Autovacuum workers ignore it. For lock waits use the more precise lock_timeout, for whole transactions transaction_timeout.

How to change it

Any user can change it for their session with SET.

See it in context

Life of a query Client backend Life of a SELECT Locking and deadlocks

Related parameters

lock_timeout transaction_timeout idle_in_transaction_session_timeout log_min_error_statement

All Client Connection Defaults parameters