PostgreSQL: canceling statement due to statement timeout
ERROR: canceling statement due to statement timeoutThe query ran longer than statement_timeout, so Postgres cancelled it. Either the query is too slow and needs an index or rewrite, or the timeout is set too low for legitimate work. Optimize the query, or raise the timeout for that job.
What this error means
statement_timeout caps how long a single statement may run. When a query exceeds it, Postgres aborts the statement with this error to protect the server from runaway queries.
It is usually a performance signal: a missing index, a bad plan, or a query blocked waiting on a lock while the clock ran out.
How to fix it
The query is genuinely slow
Find the slow part and add an index or rewrite it.
EXPLAIN ANALYZE SELECT ...;The timeout is too low for this work
Raise it for the session or the specific statement, not globally.
SET statement_timeout = '60s';The statement is blocked on a lock
Something else holds a lock it needs. Check pg_stat_activity for the blocker.
SELECT pid, state, wait_event_type, query
FROM pg_stat_activity
WHERE state <> 'idle';How to avoid it next time
- Index the queries that run hot, and confirm plans with EXPLAIN ANALYZE.
- Set timeouts per role or per transaction rather than one high global value.
Frequently asked questions
Should I just raise statement_timeout globally?
Prefer raising it only for the specific session or job that needs it. A high global timeout lets any slow query tie up resources.
How do I find why the query is slow?
Run EXPLAIN ANALYZE on it. It shows where time goes and whether an index is missing.
Stop struggling with SQL
Use FluentDB, the AI database client for macOS.
Related errors
Part of the PostgreSQL error reference. Last reviewed 2026-07-31.