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:
- Optimize the query (indexes, plan) so it finishes within the timeout.
- Raise
statement_timeoutper session or role for legitimately long operations. - On standbys, tune
max_standby_streaming_delayor enablehot_standby_feedbackto reduce conflicts. - Add retry logic for transient cancels.
Reference: PostgreSQL error codes — Class 57 (Operator Intervention).
Thanks — noted. This helps keep the database accurate.