{"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"}],"derived_content_hash":"6c55737b3fd874b470b12dbf660ef4c299ea4fc1d994214bd0de2774619425ca","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"],"repair_provenance":{"original_source_revision":"english-manuals:9baca19b9fd45a8da430156b8e9a7d2ab701c8ead77fef43a15ba8ca4c01ad84","receipt_sha256":"1509ef108bc12f9b9debd8b11d16c522164662a889cf3f6292f7775bd065fd2d","repair":"wiki-repair-20261023"},"short_desc":"Abort any statement that takes more than the specified amount of time.","short_desc_zh":"","source_rev":"wiki-repair-20261023:143e10464be5c3ba8639464010cbd272f2a3b42f953811d2c040f3c21431bd3b","unit":"","vartype":"integer"}},"Definition":{"Collection":"guc","Key":"statement_timeout","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"statement_timeout","SourceRevision":"wiki-repair-20261023:143e10464be5c3ba8639464010cbd272f2a3b42f953811d2c040f3c21431bd3b","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.","description_zh":"中止任何使用了超过指定时间量的语句。如果 log_min_error_statement 被设置为 ERROR 或更低，语句如果超时也会被记录。如果指定值时没有单位，则以毫秒为单位。一个零值（默认）将禁用超时。 超时从命令到达服务器时开始计算，直到服务器完成该命令为止。如果单个简单查询消息中出现多个 SQL 语句，超时将分别应用于每个语句。（PostgreSQL 13 之前的版本通常将超时应用于整个查询字符串。）在扩展查询协议中，当任何与查询相关的消息（Parse、Bind、Execute、Describe）到达时开始计时，并在处理完 Execute 或 Sync 消息时取消计时。 我们不推荐在 postgresql.conf 中设置 statement_timeout，因为它会影响所有会话。","description_zh_html":"\u003cp\u003e\n        中止任何使用了超过指定时间量的语句。如果 \u003ccode class=\"varname\"\u003elog_min_error_statement\u003c/code\u003e 被设置为 \u003ccode class=\"literal\"\u003eERROR\u003c/code\u003e 或更低，语句如果超时也会被记录。如果指定值时没有单位，则以毫秒为单位。一个零值（默认）将禁用超时。\n       \u003c/p\u003e\u003cp\u003e\n        超时从命令到达服务器时开始计算，直到服务器完成该命令为止。如果单个简单查询消息中出现多个 SQL 语句，超时将分别应用于每个语句。（\u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 13 之前的版本通常将超时应用于整个查询字符串。）在扩展查询协议中，当任何与查询相关的消息（Parse、Bind、Execute、Describe）到达时开始计时，并在处理完 Execute 或 Sync 消息时取消计时。\n       \u003c/p\u003e\u003cp\u003e\n\t        我们不推荐在 \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e 中设置 \u003ccode class=\"varname\"\u003estatement_timeout\u003c/code\u003e，因为它会影响所有会话。\n\t       \u003c/p\u003e","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","translation_provenance":{"inputs":[{"kind":"current-pgdoc-translation","path":"/Users/vonng/pgsty/pgdoc/zh/18/html/runtime-config-client.html","sha256":"1882f8fd5576909c4fcc44af53077378871e05f5be67723f20fe300273024767"}],"kind":"same-version-pgdoc","locale":"zh-Hans","source_revision":"b1b500221dbe5437cfca004d6b04d3f6e422765d","version":"18"},"unit":"ms","vartype":"integer","zh_from":"same-version-pgdoc"},"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":"wiki-repair-20261023:143e10464be5c3ba8639464010cbd272f2a3b42f953811d2c040f3c21431bd3b","ContentHash":"2b424ebdf147a1afe3ab030c7345bc1c55558b5630e70065536710ed7e53b7c3","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":"en","Fallback":false,"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","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
