SQLSTATE 57014 ERROR Class 57: Operator Intervention

query_canceled Query Canceled — SQLSTATE 57014

The statement was canceled — by a timeout or an explicit cancel.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Symptoms

The statement was canceled — by a timeout or an explicit cancel.

  • The error is written to the server log and returned to the client carrying SQLSTATE 57014.
  • Any driver (libpq, JDBC, psycopg, npgsql, pgx) surfaces this code in its error object so you can branch on it programmatically.
  • PL/pgSQL can trap it by name: EXCEPTION WHEN query_canceled THEN.

Environment

Severity: ERROR  |  PostgreSQL versions: 12, 13, 14, 15, 16, 17

Commonly coincides with restarts, failover, maintenance, or network events; check server uptime and the log around the timestamp.

Root Cause

It exceeded statement_timeout, was canceled with pg_cancel_backend or by a user/tool, or hit a recovery conflict on a standby.

Common causes:

  • A slow query hitting statement_timeout.
  • An administrator cancel.
  • A lock-wait cancellation.
  • A standby recovery conflict (max_standby_streaming_delay).

Diagnostic Queries

Recovery

Steps to resolve 57014:

  1. Optimize the query (indexes, plan) so it finishes within the timeout.
  2. Raise statement_timeout per session or role for legitimately long operations.
  3. On standbys, tune max_standby_streaming_delay or enable hot_standby_feedback to reduce conflicts.
  4. Add retry logic for transient cancels.

Reference: PostgreSQL error codes — Class 57 (Operator Intervention).

Was this helpful?