Category: Supabase and databases

PostgreSQL: 57014 cancelling statement due to statement timeout

Read this guide in Polish

The query to the database is interrupted by code 57014, especially with a larger table. The database discontinued execution after exceeding the time limit or upon cancellation request.

How to determine the source of the error

View the EXPLAIN ANALYZE plan in a safe environment and time of execution with production filters.

Check the column indexes used in WHERE, the order of the connectors and whether the application does not download the entire table unnecessarily.

What to do step by step

1. Add an index matching the actual predicate or reduce the query range by pagination and column selection.

2 . Consider increasing the timeout only after measuring and excluding the performance problem.

How to check the score

The query is executed within the required time and returns the same correct record count.

What to do

Do not set unlimited timeout for each endpoint in response to a single free report.