statement_timeout
Abort any statement that runs longer than this; 0 disables.
- Predeterminado
0 (disabled)- Range
- 0 to about 24 days, in ms
- Restart needed
- No
- Default checked on
- PostgreSQL 18
Lo que hace
Measured from when the command arrives at the server. Each statement in a multi-statement query string gets its own limit; statements run inside a function count toward the statement that called it. Best set per role or per database rather than server-wide.
Valor predeterminado
0 (disabled). 0 (PostgreSQL 18).
Check the current value
SHOW statement_timeout; SELECT setting, unit, boot_val, context, source, pending_restart FROM pg_settings WHERE name = 'statement_timeout';
Change it
SET statement_timeout = '30s'; -- this session ALTER ROLE reporting SET statement_timeout = '30s'; -- new sessions of one role ALTER SYSTEM SET statement_timeout = '30s'; SELECT pg_reload_conf();
No restart. Any role can SET it for a session or with SET LOCAL for one transaction; a server-wide ALTER SYSTEM change applies after a reload (context is user).
When to change it
Set it for application and reporting roles (ALTER ROLE app SET statement_timeout = '30s') so a bad query cannot run for hours.
What can go wrong
Server-wide it also cancels legitimate long jobs: index builds, migrations and batch jobs need it overridden (pg_dump already sets it to 0 for its own session).
The closest setting on other engines
| Motor | Ajuste | Predeterminado | Restart |
|---|---|---|---|
| PostgreSQL |
statement_timeout this page
|
0 (disabled) |
No |
| MySQL |
max_execution_time
|
0 (disabled) |
No |
Questions about statement_timeout
What is the default value of statement_timeout in PostgreSQL?
0 (disabled). 0 (PostgreSQL 18).
Does changing statement_timeout require a restart?
No. No restart. Any role can SET it for a session or with SET LOCAL for one transaction; a server-wide ALTER SYSTEM change applies after a reload (context is user).
When should I change statement_timeout?
Set it for application and reporting roles (ALTER ROLE app SET statement_timeout = '30s') so a bad query cannot run for hours.
Back to all PostgreSQL settings, or check the PostgreSQL manual for every option.
Check statement_timeout on your own server
SQLly runs the query above against PostgreSQL and the other engines in this reference, from one desktop app on macOS, Windows and Linux.