ERROR: canceling statement due to statement timeout

A query ran longer than statement_timeout and PostgreSQL cancelled it.

Seen on: PostgreSQL

Meaning

Timeouts are set per role/database/session (often by hosting providers or ORMs). Missing indexes and huge scans are the usual root cause.

Common causes

  • Slow query (missing index, large scan)
  • statement_timeout set low by provider/role
  • Lock waits counted in the duration

⚡ Quick fix

  1. EXPLAIN ANALYZE the query and add indexes
  2. Raise statement_timeout for specific jobs: SET statement_timeout = '5min'
  3. Batch large operations

Detailed fix by platform

PostgreSQL

  1. EXPLAIN (ANALYZE, BUFFERS) SELECT …;

How to diagnose

  1. Query — How long does it take?
  2. Timeout — SHOW statement_timeout

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.