{"Entry":{"collection":"guc","key":"statement_timeout","name":"statement_timeout","aliases":[],"metadata":{"baseline":true,"boot_human":"Not specified","boot_val":null,"category":"Client Connection Defaults / Statement Behavior","category_zh":"","changed_in":["18"],"changes":[{"documentation_changed":true,"fields":{},"from":"7.4","status":"changed","to":"8.0"},{"documentation_changed":true,"fields":{},"from":"8.0","status":"changed","to":"8.1"},{"documentation_changed":true,"fields":{},"from":"8.1","status":"changed","to":"8.2"},{"documentation_changed":true,"fields":{},"from":"8.2","status":"changed","to":"8.3"},{"documentation_changed":true,"fields":{},"from":"8.4","status":"changed","to":"9.0"},{"documentation_changed":true,"fields":{},"from":"9.2","status":"changed","to":"9.3"},{"documentation_changed":true,"fields":{},"from":"11","status":"changed","to":"12"},{"documentation_changed":true,"fields":{},"from":"12","status":"changed","to":"13"},{"documentation_changed":true,"fields":{},"from":"16","status":"changed","to":"17"},{"documentation_changed":false,"fields":{"extra_desc":{"from":"A value of 0 turns off the timeout.","to":"0 disables the timeout."}},"from":"17","status":"changed","to":"18"}],"content_hash":"dd62f2bd51d42c65b1eeb9ac02ab0d88afdee3311201cc5db31f40695b8456b2","context":"","default_changed_in":[],"default_history":[{"from":"9.0","to":"19","value":"0 ms"}],"editorial":{"advice":{"olap":"Analytical work usually needs a larger or job-specific statement_timeout; preserve a finite guardrail for abandoned work without killing legitimate long scans.","oltp":"Set statement_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 statement_timeout only when the client or operating system handles termination correctly; verify that maintenance still has a dedicated exception."},"mechanism":["statement_timeout sets the maximum allowed duration of any statement. 0 disables the timeout. The timer starts when a command arrives; in modern releases each statement in a simple-query string is timed separately, while extended-protocol timing follows Parse/Bind/Execute through Sync.","statement_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."],"pitfalls":["Changing statement_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.","Setting one global value that kills legitimate maintenance and analytical work along with runaway requests."],"references":[{"title":"PostgreSQL 19 Beta 4: statement_timeout","url":"https://www.postgresql.org/docs/19/runtime-config-client.html#GUC-STATEMENT-TIMEOUT"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["lock_timeout","transaction_timeout","idle_in_transaction_session_timeout","idle_session_timeout","deadlock_timeout"],"summary":"statement_timeout is the PostgreSQL setting that defines the maximum allowed duration of any statement."},"enumvals":[],"first_version":"7.4","group":"Client Connection Defaults","group_slug":"client","imported_at":"2026-09-27T17:57:32.05836+08:00","intro_commit":{},"key":"statement_timeout","last_version":"20","max_val":"","min_val":"","name":"statement_timeout","position":385,"present_in":["7.4","8.0","8.1","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6","10","11","12","13","14","15","16","17","18","19","20"],"short_desc":"Abort any statement that takes more than the specified amount of time.","short_desc_zh":"","source_rev":"english-manuals:9baca19b9fd45a8da430156b8e9a7d2ab701c8ead77fef43a15ba8ca4c01ad84","unit":"","vartype":"integer"}},"Definition":{"Collection":"guc","Key":"statement_timeout","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"statement_timeout","SourceRevision":"english-manuals:9baca19b9fd45a8da430156b8e9a7d2ab701c8ead77fef43a15ba8ca4c01ad84","Facts":{"boot_val":"0","category":"Client Connection Defaults / Statement Behavior","context":"user","description":"Abort any statement that takes more than the specified amount of time. If log_min_error_statement is set to ERROR or lower, the statement that timed out will also be logged. If this value is specified without units, it is taken as milliseconds. A value of zero (the default) disables the timeout. The timeout is measured from the time a command arrives at the server until it is completed by the server. If multiple SQL statements appear in a single simple-query message, the timeout is applied to each statement separately. (PostgreSQL versions before 13 usually treated the timeout as applying to the whole query string.) In extended query protocol, the timeout starts running when any query-related message (Parse, Bind, Execute, Describe) arrives, and it is canceled by completion of an Execute or Sync message. Setting statement_timeout in postgresql.conf is not recommended because it would affect all sessions.","doc":{"anchor":"GUC-STATEMENT-TIMEOUT","file":"runtime-config-client.html","lang":"en","sha256":"6be6cc70f29eca4695dc43b2b2b94c75b7e0eaaa2c00273d7a98488917a7edb7","slug":"18"},"documented":true,"enumvals":null,"extra_desc":"0 disables the timeout.","lang":"en","max_val":"2147483647","metadata_version":"18","min_val":"0","name":"statement_timeout","short_desc":"Sets the maximum allowed duration of any statement.","source":"pg-settings-source-snapshot","unit":"ms","vartype":"integer"},"ManualEvidence":{"doc":{"anchor":"GUC-STATEMENT-TIMEOUT","file":"runtime-config-client.html","lang":"en","sha256":"6be6cc70f29eca4695dc43b2b2b94c75b7e0eaaa2c00273d7a98488917a7edb7","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"statement_timeout","SourceDatabase":"center","Version":"18","Locale":"en","Title":"statement_timeout","Summary":"Abort any statement that takes more than the specified amount of time. If log_min_error_statement is set to ERROR or lower, the statement that timed out will also be logged. If this value is specified without units, it is taken as milliseconds. A value of zero (the default) disables the timeout. The timeout is measured from the time a command arrives at the server until it is completed by the server. If multiple SQL statements appear in a single simple-query message, the timeout is applied to each statement separately. (PostgreSQL versions before 13 usually treated the timeout as applying to the whole query string.) In extended query protocol, the timeout starts running when any query-related message (Parse, Bind, Execute, Describe) arrives, and it is canceled by completion of an Execute or Sync message. Setting statement_timeout in postgresql.conf is not recommended because it would affect all sessions.","BodyHTML":"\u003cp\u003eAbort any statement that takes more than the specified amount of time. If log_min_error_statement is set to ERROR or lower, the statement that timed out will also be logged. If this value is specified without units, it is taken as milliseconds. A value of zero (the default) disables the timeout. The timeout is measured from the time a command arrives at the server until it is completed by the server. If multiple SQL statements appear in a single simple-query message, the timeout is applied to each statement separately. (PostgreSQL versions before 13 usually treated the timeout as applying to the whole query string.) In extended query protocol, the timeout starts running when any query-related message (Parse, Bind, Execute, Describe) arrives, and it is canceled by completion of an Execute or Sync message. Setting statement_timeout in postgresql.conf is not recommended because it would affect all sessions.\u003c/p\u003e","SourceRevision":"english-manuals:9baca19b9fd45a8da430156b8e9a7d2ab701c8ead77fef43a15ba8ca4c01ad84","ContentHash":"004e1d5ba051e2be1f44eff737758c63afae640de4989e61dfae73bdac1e83c2","Payload":{"description":"Abort any statement that takes more than the specified amount of time. If log_min_error_statement is set to ERROR or lower, the statement that timed out will also be logged. If this value is specified without units, it is taken as milliseconds. A value of zero (the default) disables the timeout. The timeout is measured from the time a command arrives at the server until it is completed by the server. If multiple SQL statements appear in a single simple-query message, the timeout is applied to each statement separately. (PostgreSQL versions before 13 usually treated the timeout as applying to the whole query string.) In extended query protocol, the timeout starts running when any query-related message (Parse, Bind, Execute, Describe) arrives, and it is canceled by completion of an Execute or Sync message. Setting statement_timeout in postgresql.conf is not recommended because it would affect all sessions."}},"RequestedLocale":"zh-Hans","Fallback":true,"Versions":["10","11","12","13","14","15","16","17","18","19","20","7.4","8.0","8.1","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6"],"Locales":["en"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
