scribase
SQLSTATE 57014query_canceledHTTP 500

Postgres error 57014: query canceled

canceling statement due to statement timeout

The statement ran longer than statement_timeout (or was cancelled by the user) and was stopped.

Common causes

  • A slow query: missing index, sequential scan of a big table, or a plan gone wrong.
  • A short timeout on the API role, which is common on hosted backends to protect the database.
  • Waiting on a lock held by another long transaction.

How to fix it

  • EXPLAIN (ANALYZE, BUFFERS) the query and add the index it needs; pg_stat_statements shows which queries are slow overall.
  • Paginate large reads with keyset pagination instead of OFFSET.
  • For known long jobs, raise the timeout only where needed: set local statement_timeout = '60s'; inside the transaction.

Through a REST API

PostgREST, the REST layer behind supabase-js and Scribase, answers HTTP 500 for this error and returns the SQLSTATE in the code field of the JSON error body.

Questions

What does Postgres error 57014 mean?

57014 is query_canceled in class 57 (Operator Intervention). The statement ran longer than statement_timeout (or was cancelled by the user) and was stopped.

How do I fix 57014?

EXPLAIN (ANALYZE, BUFFERS) the query and add the index it needs; pg_stat_statements shows which queries are slow overall. Paginate large reads with keyset pagination instead of OFFSET. For known long jobs, raise the timeout only where needed: set local statement_timeout = '60s'; inside the transaction.

What HTTP status does a REST API return for 57014?

PostgREST, the REST layer behind supabase-js, answers 500.

Other class 57 errors

  • 57P01 terminating connection due to administrator command