PostgreSQL Error 57014: Query Canceled Fix
In this article
Error 57014 means PostgreSQL canceled a running query because someone or something asked it to stop — usually a statement timeout, an operator pressing cancel, or a client disconnecting. The fix is not to "clear the error" but to find out who sent the cancel and why, then either give the query more time, make it faster, or stop whatever is canceling it. Before you touch anything, note the exact message: it often reads ERROR: canceling statement due to statement timeout or canceling statement due to user request, and that suffix tells you almost everything.
What You'll Need
- Access to the database as a user who can read server settings (a superuser or a role with
pg_read_all_settings), or a DBA who can run the checks for you. - A SQL client such as psql, pgAdmin, DBeaver or your application's console.
- Permission to edit
postgresql.confor runALTER ROLE/ALTER DATABASEif a timeout change is needed. - The application logs or APM traces around the failure time, so you can match the error to a specific query.
Step-by-Step
- Read the full error text. The part after "canceling statement due to" is the diagnosis. statement timeout means a configured time limit was hit. user request means a person or tool issued a cancel. lock timeout or idle-in-transaction timeout point at blocking, not slow SQL. Write it down before you change anything.
- Check the current timeout settings. Run
SHOW statement_timeout;,SHOW lock_timeout;andSHOW idle_in_transaction_session_timeout;. A value of0means disabled. Ifstatement_timeoutis something like30sand your query legitimately takes two minutes, you have found the cause. Remember that these can be set at server, database, role, or session level, so also runSELECT name, setting, source FROM pg_settings WHERE name = 'statement_timeout';— thesourcecolumn tells you where the value came from. - Find the query that failed. Search your application logs for the timestamp and the SQL text. If you only have the error, enable
log_min_duration_statementtemporarily (for exampleALTER SYSTEM SET log_min_duration_statement = '5s';thenSELECT pg_reload_conf();) so slow statements land in the server log. Turn it back off once you have what you need — it adds log volume. - Reproduce it in a client. Run the same statement with
EXPLAIN (ANALYZE, BUFFERS)in a non-production copy if possible. Look for sequential scans on large tables, nested loops with high row counts, or a plan that changed after a data growth spurt. This is where most "it used to work" cases are solved. - Decide between more time and a faster query. If the query is genuinely heavy but correct (monthly reports, bulk exports), raise the limit for that role or database only:
ALTER ROLE reporting_user SET statement_timeout = '10min';orALTER DATABASE analytics SET statement_timeout = '10min';. Avoid raising it globally; a runaway query then holds resources far longer. - If it is a web request, fix the query instead. Add or correct indexes, rewrite the query, add pagination, or move the work to a background job. A statement timeout on a user-facing request is usually a sign the request should not be doing that work synchronously.
- If the cancel came from a person or tool, find the source. Check for an operator pressing the cancel button in pgAdmin, a connection pooler killing long queries, a load balancer or proxy closing the connection, or a scheduled job that calls
pg_cancel_backend(). In PostgreSQL, a client disconnect can also cancel the running statement. Review pooler settings such as query timeouts and maximum connection lifetimes. - Confirm the fix. Re-run the query or the application flow and check that it completes. Watch the server log for the same error code. If it recurs at the same time each day, look for a concurrent job — a vacuum, backup, or bulk load can slow everything else and trigger timeouts indirectly.
Common Mistakes
- Setting
statement_timeout = 0everywhere. This disables the safety net and lets a bad query run until someone notices. Scope the change to the role or database that needs it. - Confusing 57014 with a crash. The query was canceled cleanly; the server is fine. Do not restart PostgreSQL for this error.
- Ignoring the source of the setting. Changing
postgresql.confdoes nothing if a role-level or pooler-level setting overrides it. Checkpg_settings.sourcefirst. - Raising the timeout without looking at the plan. A query that takes 40 seconds today may take 10 minutes next month as data grows. Fix the plan.
- Assuming the app is at fault. Sometimes the database is waiting on a lock held by another session, and the timeout is doing its job.
Tips
- Set a sensible
statement_timeoutat the database level (for example 30 seconds) and override it upward only for reporting roles. - Use
lock_timeoutalongsidestatement_timeoutso lock waits fail fast instead of consuming the whole budget. - Log slow queries with
log_min_duration_statementand review them weekly; timeouts are usually the tip of a performance problem. - When testing a fix, run the query in a transaction you can roll back:
BEGIN; EXPLAIN (ANALYZE, BUFFERS) ...; ROLLBACK;. - Keep an eye on
pg_stat_activityduring incidents to see what else is running at the same time.
Troubleshooting
The error persists after raising the timeout. Check whether the cancel is coming from the client side — a pooler, proxy, or application-level timeout — rather than PostgreSQL. The server log will show whether it received a cancel request.
Only one user sees the error. Compare role-level settings with SELECT rolname, rolconfig FROM pg_roles WHERE rolconfig IS NOT NULL;. Role settings override database settings.
Queries time out at the same time every day. Look for overlapping maintenance, backups, or batch jobs. Check pg_stat_activity and the server log around that window.
You cannot change settings. Ask a DBA or the managed database provider; on hosted services, some parameters are fixed or changed through the provider's console rather than SQL.
The query is fast in a client but times out in the app. The app may be using a different role, a different search_path, or a prepared statement with a bad generic plan. Compare SHOW statement_timeout; in both sessions.
Frequently Asked Questions
Is error 57014 dangerous?
No. It is a normal cancellation, not corruption or a crash. The transaction is aborted and rolled back; the server keeps running.
What does "canceling statement due to user request" mean?
Something sent a cancel signal — a person pressing cancel in a client, an application calling pg_cancel_backend(), or a client disconnecting mid-query.
Can I disable the statement timeout?
Yes, with SET statement_timeout = 0; for a session, but it is rarely a good idea globally. Prefer raising it for the specific role or database that needs longer queries.
Does 57014 mean my query is slow?
Often, but not always. It can also mean the query waited on a lock, or that a client-side timeout fired. Check the message suffix and the query plan.
Will restarting PostgreSQL help?
No, and it will interrupt other users. The error is per-query; fix the timeout setting or the query instead.
Where do I change the timeout for a hosted database?
Usually through the provider's console or parameter group, not by editing files on the server. Check the provider's documentation for the exact location, as labels vary.