Diagnostic Queries
Symptoms
A running statement was cancelled because something sent a cancel request — a user pressing Ctrl-C, an application statement timeout, or pg_cancel_backend(). PostgreSQL raises SQLSTATE 57014 (query_canceled).
- The query stops mid-execution and rolls back its work.
- Triggered by client cancel, admin cancel, or a timeout.
- Distinct from termination — the connection survives.
What the server log shows
ERROR: canceling statement due to user request
Why PostgreSQL raises this — what the manual says
Section 9.28.2 Server Signaling Functions:
“Cancels the current query of the session whose backend process has the specified process ID.”
A cancel request sets a flag the backend checks at safe interrupt points. On the next check the backend aborts the current statement with 57014 and rolls back its in-flight work, leaving the session open.
Common causes
- A user cancelled the query (Ctrl-C in psql).
- An admin ran
pg_cancel_backend(pid). - Application or driver cancellation (e.g. a client-side timeout).
How to fix it
- If unintended, investigate which client/timeout issued the cancel.
- Tune client/statement timeouts if cancellations are premature.
- For runaway queries, prefer cancel over terminate to keep the session alive.
Related & next steps
Reference: PostgreSQL 18 Section 9.28 “System Administration Functions”.
Thanks — noted. This helps keep the database accurate.