PostgreSQL 57014: canceling statement
The query was cancelled, either because it ran past statement_timeout or because a client or administrator sent a cancel request.
- SQLSTATE
57014- Name
query_canceled- Category
- Operator Intervention
What it means
57014 means the running statement was cancelled before it finished. The message says why: canceling statement due to statement timeout when it ran longer than statement_timeout, and canceling statement due to user request when a client pressed cancel (Ctrl+C in psql, a driver's cancel call) or someone ran pg_cancel_backend() on it.
Only the statement is cancelled; the session stays connected. Inside a transaction block the transaction is now failed and must be rolled back.
Common causes
- A
statement_timeoutset on the server, database, role or session that the query exceeded. - You or your tool cancelled the query.
- An administrator or monitoring job cancelled it with
pg_cancel_backend(pid). - A slow query: a missing index, a bad plan, or waiting on a lock until the timeout fired.
How to fix it
-
Check which timeout applies and where it was set.
SHOW statement_timeout; SELECT name, setting, source FROM pg_settings WHERE name = 'statement_timeout';
-
Raise it for the one session or transaction that legitimately needs longer, rather than globally.
SET statement_timeout = '10min'; -- or only for this transaction: BEGIN; SET LOCAL statement_timeout = '10min'; -- long-running work COMMIT;
-
Make the query faster: look at its plan for sequential scans on big tables and add the index it needs.
EXPLAIN (ANALYZE, BUFFERS) SELECT * FROM orders WHERE customer_id = 42;
-
If it was waiting on a lock, find the blocker.
SELECT pid, pg_blocking_pids(pid) AS blocked_by, wait_event_type, query FROM pg_stat_activity WHERE cardinality(pg_blocking_pids(pid)) > 0;
Reproduce it safely
SET statement_timeout = '1s'; SELECT pg_sleep(5); -- ERROR: canceling statement due to statement timeout RESET statement_timeout;
Related errors
55P03lock not available57P01terminating connection due to administrator25P02current transaction is aborted3024MySQL: Maximum statement execution time exceeded
More operator intervention errors
The code and message text are from the PostgreSQL documentation, Appendix A: PostgreSQL Error Codes. Browse the full PostgreSQL error list or search every database error.
Work on PostgreSQL in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for PostgreSQL and the other databases you use.