↑↓ select↵ open⌫ change scopeOpen full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / SQLSTATE

57014 — query_canceled

57014 is PostgreSQL's querycanceled condition in Class 57, operatorintervention. It indicates that the server interrupted a statement. The same SQLSTATE covers several cancellation sources, so the primary message and server context are needed to distinguish a statement timeout, an explicit client cancel, a recovery conflict, or another administrative path.

English manual coverage begins with PostgreSQL 8.1. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

aliases
Unknown
class name
Operator Intervention
condition name
query_canceled
lang
en
sqlstate
57014

Definition PG 18

At a glance {#at-a-glance}

57014 is PostgreSQL's query_canceled condition in Class 57, operator_intervention. It indicates that the server interrupted a statement. The same SQLSTATE covers several cancellation sources, so the primary message and server context are needed to distinguish a statement timeout, an explicit client cancel, a recovery conflict, or another administrative path.

The representative case sets statement_timeout to 100 ms and executes pg_sleep(1). PostgreSQL returns canceling statement due to statement timeout; the autocommit connection remains IDLE, and a subsequent SELECT 1 returns 1. This proves the timeout path and connection usability for this case, not that every canceled command has no side effects or the same transaction state.

Run 57014-registry-final-20260909 passed on PostgreSQL 18.6 and isolated PostgreSQL 10.21. The per-target assertions and structured observations are retained in the public evidence JSON.

Meaning and trigger paths {#meaning}

statement_timeout starts a timer for each statement and asks the backend to process an interrupt when the budget expires. In the fixed source path, ProcessInterrupts emits ERRCODE_QUERY_CANCELED with canceling statement due to statement timeout. A client cancel uses the same SQLSTATE with canceling statement due to user request; lock timeout and some recovery paths use their own message or detail.

Cancellation stops the current statement at an interruptible point. It is not a general assertion that all work associated with a request has ceased, that an external side effect was undone, or that a transaction is usable without rollback. The transaction boundary, statement type, and cancellation source determine what must be cleaned up.

Messages and diagnostics {#messages}

The representative operation is a dedicated autocommit connection with a 100 ms timeout:

SET statement_timeout = '100ms';
SELECT pg_sleep(1);
SELECT 1;

PostgreSQL 18.6 returned:

SQLSTATE: 57014
severity: ERROR
message_primary: canceling statement due to statement timeout
source: postgres.c / ProcessInterrupts / line 3446

PG10 returned the same primary message with source line 3018. There is no universal detail template for 57014; preserve message_detail, message_hint, context, and the statement that was interrupted when present.

Diagnosis {#diagnosis}

Record SQLSTATE, severity, primary message, detail, hint, context, backend PID, statement text, timeout settings, and the source of cancellation. Distinguish statement_timeout from lock_timeout, a client cancel, an administrator request, and a standby recovery conflict. Search server logs with the SQLSTATE and backend PID when the client diagnostic is incomplete.

Check transaction status after the error. The autocommit timeout case was IDLE and accepted SELECT 1; an error inside an explicit transaction may leave it INERROR and require rollback. If the interrupted statement changed rows before an error, verify the database state rather than assuming a request-level rollback outside the current transaction.

Response and repair {#response}

Tune the operation and its budget based on the cause:

  • Optimize or batch an overlong query, and set a timeout that matches the work's service-level budget.
  • Handle a client or administrative cancel as a control decision, then inspect whether the application should retry.
  • Resolve lock contention separately when the message identifies lock timeout; increasing statement timeout does not repair a lock queue.
  • Roll back an aborted explicit transaction before issuing unrelated commands, and verify any external work whose lifetime is not controlled by PostgreSQL.

The representative follow-up query returned 1 with the connection IDLE. That is the repair assertion for this autocommit sleep case; it is not a promise that a canceled write, cursor, or transaction can always be resumed in place.

Versions and boundaries {#versions}

The catalogue has a definition-presence observation for 57014 at PostgreSQL 7.4 and through the locked 8.4.22 pre-9.0 definitions, then in every listed formal snapshot through PostgreSQL 18.6 and the PostgreSQL 19 Beta 3 preview. This is a definition-only presence boundary, not an exact implementation introduction or runtime-use claim. No condition definition change is recorded in the scanned range.

The statement-timeout case passed on PostgreSQL 18.6 and 10.21. The SQLSTATE is shared by other cancellation mechanisms whose messages and transaction effects differ, so this evidence is limited to a server-side statement timeout on an autocommit connection.

Related {#related}

40P01 — deadlock_detected is resolved by the lock manager as a cycle, not by a timeout budget. 53300 — too_many_connections is a startup capacity failure. 42P01 — undefined_table is a parse-time name error. 25P02 — in_failed_sql_transaction can follow a cancellation when the surrounding explicit transaction is aborted.

Sources {#sources}

Structured evidence is recorded in the public evidence JSON. Source records are fixed to PostgreSQL commit 724edf9bde9d356724ad384a2e196edc3c9f80f7; runtime records retain both target IDs and structured observations.

Compare versions

SQLSTATE evidence and recorded runtime versions

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"
}

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · english-manuals:d5b6b4d4896e93753cc414820696c25e427f6248fddb49e2d2d4352b852a67c7

Text language: en · english-manuals:d5b6b4d4896e93753cc414820696c25e427f6248fddb49e2d2d4352b852a67c7