57014 — query_canceled:查询已取消
语句被取消,含 statement_timeout 到期。
英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。
当前阅读 PG 18·选择有来源记录的版本
- aliases
- 未知
- class name
- Operator Intervention
- condition name
- query_canceled
- lang
- en
- sqlstate
- 57014
版本定义 PG 18
速览 {#at-a-glance}
57014 是 PostgreSQL 类别 57 operator_intervention 中的 query_canceled 条件。它表示服务器中断了某条语句。多个取消来源共用这个 SQLSTATE,因此必须结合主报文和服务器上下文,区分 statement timeout、客户端取消、恢复冲突或其他管理路径。
代表性案例在专用自动提交连接上设置 statement_timeout 为 100 ms,再执行 pg_sleep(1)。PostgreSQL 返回 canceling statement due to statement timeout;连接保持 IDLE,后续 SELECT 1 返回 1。这只证明本案例的超时路径及连接可用性,不能推断所有取消命令都没有副作用或拥有相同事务状态。
运行 57014-registry-final-20260909 在 PostgreSQL 18.6 和隔离的 PostgreSQL 10.21 上均通过。逐目标断言和结构化观察见公开证据 JSON。
含义与触发路径 {#meaning}
statement_timeout 为每条语句启动计时器,预算到期后请求 backend 处理中断。在固定源码路径中,ProcessInterrupts 使用 ERRCODE_QUERY_CANCELED 和 canceling statement due to statement timeout 报告错误。客户端取消使用相同 SQLSTATE 但主报文是 canceling statement due to user request;锁超时和某些恢复路径使用自己的报文或 detail。
取消会在可处理中断的点停止当前语句。它不等于所有关联请求的工作都已经停止,也不保证外部副作用已经撤销,更不保证无需回滚就能继续使用事务。必须结合事务边界、语句类型和取消来源确定清理方式。
报文与诊断 {#messages}
代表性操作是在专用自动提交连接上设置 100 ms 超时:
SET statement_timeout = '100ms';
SELECT pg_sleep(1);
SELECT 1;
PostgreSQL 18.6 返回:
SQLSTATE: 57014
severity: ERROR
message_primary: canceling statement due to statement timeout
source: postgres.c / ProcessInterrupts / line 3446
PG10 返回相同的主报文,对应源码行号为 3018。57014 没有统一的 detail 模板;如果客户端提供,应保存 message_detail、message_hint、上下文及被中断的语句。
诊断 {#diagnosis}
记录 SQLSTATE、严重级别、主报文、detail、hint、上下文、backend PID、语句文本、超时设置和取消来源。区分 statement timeout、lock timeout、客户端取消、管理员请求以及备用机恢复冲突。客户端诊断不完整时,可使用 SQLSTATE 和 backend PID 检查服务器日志。
检查错误后的事务状态。本案例的自动提交超时后为 IDLE,并成功执行 SELECT 1;显式事务中的错误可能让事务进入 INERROR,需要回滚。如果语句在出错前已改变行,应检查数据库实际状态,不要假定数据库之外的整个请求都能自动回滚。
处理与修复 {#response}
根据原因调整操作和预算:
- 优化或拆分过长查询,设置符合服务预算的超时。
- 将客户端或管理员取消视为控制决策,再判断应用是否应重试。
- 如果报文指向 lock timeout,应独立解决锁竞争;提高 statement timeout 不会修复锁队列。
- 显式事务中止后先回滚,再发送无关命令;对生命周期不受 PostgreSQL 控制的外部工作进行验证。
代表性后续查询返回 1,连接状态为 IDLE。这是自动提交 sleep 案例的修复断言,不保证被取消的写入、游标或事务都能原地继续。
版本与边界 {#versions}
目录在 PostgreSQL 7.4 的锁定定义中已观察到 57014,并持续到 8.4.22 的 pre-9.0 定义;随后在列出的所有正式快照直到 PostgreSQL 18.6 以及 PostgreSQL 19 Beta 3 预览中存在。这是 definition_only 的存在边界,不是确切实现引入版本或运行时使用断言。扫描范围内没有记录该条件的定义变化。
statement timeout 案例在 PostgreSQL 18.6 和 10.21 上均通过。该 SQLSTATE 还用于其他取消机制,而它们的报文和事务影响不同;本证据范围限定为自动提交连接上的服务器 statement timeout。
相关 {#related}
40P01 — deadlock_detected 是锁管理器发现环后解决的死锁,不是超时预算。53300 — too_many_connections 是启动阶段容量失败。42P01 — undefined_table 是解析阶段的名称错误。25P02 — in_failed_sql_transaction 可能在取消使周围显式事务中止后出现。
来源 {#sources}
结构化证据记录在公开证据 JSON中。源码记录固定到 PostgreSQL commit 724edf9bde9d356724ad384a2e196edc3c9f80f7;运行记录保留两个目标 ID 和结构化观察。
src.errcodes.18.6—errcodes.txtsrc.postgres.18.6—postgres.cdoc.config.18— 语句行为和 statement_timeout- Runtime:latest 与 pg10 均为
57014-registry-final-20260909,结构化观察见公开证据 JSON
比较版本
SQLSTATE 证据与已记录的运行版本
cases · statement_timeout_cancel
{
"assertions": [
"SQLSTATE is 57014",
"The message identifies statement timeout",
"The autocommit connection is usable for a subsequent query"
],
"case_id": "statement_timeout_cancel",
"cleanup": "Drop the case schema with an owner connection.",
"has_snippet": true,
"position": 0,
"preconditions": [
"A dedicated connection",
"statement_timeout set to 100 ms"
],
"repair": "Classify timeout by operation and budget; tune the timeout or query, and do not treat cancellation as proof that all server work has stopped without checking the operation.",
"trigger": "Run pg_sleep(1) and let the server cancel the statement at the configured timeout.",
"versions": [
"10",
"18"
]
}claims · identity.class-and-condition
{
"claim_id": "identity.class-and-condition",
"limits": "The directory condition covers several cancellation sources.",
"method": "Read the Class 57 section and 57014 row in the frozen errcodes.txt snapshot.",
"position": 0,
"runtime": [],
"sources": [
"src.errcodes.18.6"
],
"statement": "57014 is the query_canceled condition in Class 57 operator_intervention."
}claims · mechanism.statement-timeout
{
"claim_id": "mechanism.statement-timeout",
"limits": "User cancel, lock timeout, recovery conflict, and administrative cancel paths can use the same SQLSTATE with different messages or effects.",
"method": "Read the ProcessInterrupts timeout branch and the official statement_timeout behavior documentation.",
"position": 1,
"runtime": [],
"sources": [
"src.postgres.18.6",
"doc.config.18"
],
"statement": "The statement-timeout interrupt path reports ERRCODE_QUERY_CANCELED with canceling statement due to statement timeout."
}claims · runtime.autocommit-followup
{
"claim_id": "runtime.autocommit-followup",
"limits": "The run covers statement timeout on an autocommit connection and does not establish transaction effects for canceled writes or explicit transactions.",
"method": "Set statement_timeout, execute the long sleep, capture diagnostics and status, and assert the follow-up query and final status.",
"position": 2,
"runtime": [],
"sources": [
"case-manifest.57014",
"snippet-registry.57014.final",
"runtime.57014-registry-final-20260909.latest",
"runtime.57014-registry-final-20260909.pg10"
],
"statement": "A 100 ms statement_timeout canceled pg_sleep(1) with SQLSTATE 57014 and left the autocommit connection IDLE; SELECT 1 then returned 1 on both targets."
}claims · versions.catalogue-boundary
{
"claim_id": "versions.catalogue-boundary",
"limits": "The first scanned release is a lower bound, not an asserted introduction version.",
"method": "Read the manifest snapshots and definition references for the code.",
"position": 3,
"runtime": [],
"sources": [
"manifest.57014"
],
"statement": "The locked catalogue records 57014 in every listed formal snapshot from 9.0.23 through 18.6 and in 19beta3; pre-9.0 history is not scanned."
}messages · message.statement-timeout
{
"limits": "This template identifies the statement_timeout path; other query-canceled paths have their own messages.",
"message_id": "message.statement-timeout",
"path": "",
"position": 0,
"raw": {
"id": "message.statement-timeout",
"limits": "This template identifies the statement_timeout path; other query-canceled paths have their own messages.",
"primary_template": "canceling statement due to statement timeout",
"severity_source": "explicit ERROR",
"sources": [
"src.postgres.18.6"
],
"sqlstate": "57014"
},
"severity": "explicit ERROR",
"sources": [
"src.postgres.18.6"
],
"templates": [
{
"kind": "primary",
"literal": "canceling statement due to statement timeout",
"position": 0,
"role": "",
"template": "canceling statement due to statement timeout"
}
]
}runtimes · runtime.57014-registry-final-20260909.latest · 18.6 (Homebrew) · passed
{
"cases": [
"statement_timeout_cancel"
],
"limits": "",
"position": 0,
"raw": {
"cases": [
"statement_timeout_cancel"
],
"id": "runtime.57014-registry-final-20260909.latest",
"observed": {
"diagnostic": {
"message_primary": "canceling statement due to statement timeout",
"severity": "ERROR",
"source_file": "postgres.c",
"source_function": "ProcessInterrupts",
"source_line": "3446",
"sqlstate": "57014"
},
"followup": 1,
"statuses": {
"after_cancel": "IDLE",
"after_followup": "IDLE"
}
},
"raw": "verify/results/57014-registry-final-20260909/latest/raw.jsonl",
"raw_sha256": "dabaaf0b01d0c45133ea2d3e85ba3272e436cf75b95c7681b608b1b96cb9a99f",
"run_id": "57014-registry-final-20260909",
"server_version": "18.6 (Homebrew)",
"server_version_num": 180006,
"snippet_registry": {
"path": "verify/cases/57014/snippets.json",
"sha256": "f6cf9d26837aae084280538fc4283418b23f160838b581c67eaf0e22d8c6715d"
},
"status": "passed",
"summary": "verify/results/57014-registry-final-20260909/latest/summary.json",
"summary_sha256": "8e310974fb6160095bd37df9c259419289e44a2c62ab42d72218e906a2ef8bbc",
"target": "latest"
},
"run_id": "57014-registry-final-20260909",
"runtime_id": "runtime.57014-registry-final-20260909.latest",
"server_version": "18.6 (Homebrew)",
"status": "passed",
"target": "latest"
}runtimes · runtime.57014-registry-final-20260909.pg10 · 10.21 (Debian 10.21-1.pgdg90+1) · passed
{
"cases": [
"statement_timeout_cancel"
],
"limits": "",
"position": 1,
"raw": {
"cases": [
"statement_timeout_cancel"
],
"id": "runtime.57014-registry-final-20260909.pg10",
"image": "postgres@sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc",
"observed": {
"diagnostic": {
"message_primary": "canceling statement due to statement timeout",
"severity": "ERROR",
"source_file": "postgres.c",
"source_function": "ProcessInterrupts",
"source_line": "3018",
"sqlstate": "57014"
},
"followup": 1,
"statuses": {
"after_cancel": "IDLE",
"after_followup": "IDLE"
}
},
"raw": "verify/results/57014-registry-final-20260909/pg10/raw.jsonl",
"raw_sha256": "85c6bb64d7e6178c4b2300d5f24d15c356339662f40573180dd230b2c65a3b80",
"run_id": "57014-registry-final-20260909",
"server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
"server_version_num": 100021,
"snippet_registry": {
"path": "verify/cases/57014/snippets.json",
"sha256": "f6cf9d26837aae084280538fc4283418b23f160838b581c67eaf0e22d8c6715d"
},
"status": "passed",
"summary": "verify/results/57014-registry-final-20260909/pg10/summary.json",
"summary_sha256": "fa02b6c80d94c75f63912def8ffd13dd794792d403749f57de45dd6f860d2dbb",
"target": "pg10"
},
"run_id": "57014-registry-final-20260909",
"runtime_id": "runtime.57014-registry-final-20260909.pg10",
"server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
"status": "passed",
"target": "pg10"
}sources · src.errcodes.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "",
"location": "lines 432-438",
"path": "src/backend/utils/errcodes.txt",
"position": 0,
"sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
"source_id": "src.errcodes.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt"
}sources · src.postgres.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "",
"location": "lines 3441-3446",
"path": "src/backend/tcop/postgres.c",
"position": 1,
"sha256": "9fb62275b1badf94d01ab351337b60410cd9b3ab1fe63fa9f23d6d2185a21061",
"source_id": "src.postgres.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/tcop/postgres.c#L3441-L3446"
}sources · doc.config.18
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "",
"location": "statement_timeout configuration",
"path": "doc/src/sgml/config.sgml",
"position": 2,
"sha256": "ffca322c15315ba670733d6b320f23cbba7374db0d18937298ffc07b58799ef6",
"source_id": "doc.config.18",
"tag": "PG18-docs",
"url": "https://www.postgresql.org/docs/18/runtime-config-client.html#GUC-STATEMENT-TIMEOUT"
}sources · doc.protocol.18
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "",
"location": "ErrorResponse fields",
"path": "doc/src/sgml/protocol.sgml",
"position": 3,
"sha256": "745339e07ebbc2bb67d98b258e25772ada644ef26011e3cd6b3fcbb435235f89",
"source_id": "doc.protocol.18",
"tag": "PG18-docs",
"url": "https://www.postgresql.org/docs/18/protocol-error-fields.html"
}sources · manifest.57014
{
"commit": "",
"docs_url": "",
"kind": "local_artifact",
"location": "snapshots and definition_blobs entries for the 57014 definition",
"path": "sources/manifest.lock.json",
"position": 4,
"sha256": "1727a275f336988ff96b4f9990a4ca253080f73fc5d316e7def165c8cf3708a8",
"source_id": "manifest.57014",
"tag": "",
"url": "../sources/manifest.lock.json"
}sources · case-manifest.57014
{
"commit": "",
"docs_url": "",
"kind": "local_artifact",
"location": "statement_timeout_cancel",
"path": "verify/cases/57014/cases.json",
"position": 5,
"sha256": "af2f28389fba25445dae975fda3a035ef9d69d7210f8f414585801aaf8c0282d",
"source_id": "case-manifest.57014",
"tag": "",
"url": "../verify/cases/57014/cases.json"
}sources · snippet-registry.57014.final
{
"commit": "",
"docs_url": "",
"kind": "local_artifact",
"location": "statement_timeout_cancel ordered SQL",
"path": "verify/cases/57014/snippets.json",
"position": 6,
"sha256": "f6cf9d26837aae084280538fc4283418b23f160838b581c67eaf0e22d8c6715d",
"source_id": "snippet-registry.57014.final",
"tag": "",
"url": "../verify/cases/57014/snippets.json"
}来源引用
定义来源
center · PostgreSQL 18 · english-manuals:d5b6b4d4896e93753cc414820696c25e427f6248fddb49e2d2d4352b852a67c7
正文语言: zh-Hans · english-manuals:d5b6b4d4896e93753cc414820696c25e427f6248fddb49e2d2d4352b852a67c7