Skip to content

Supabase database errorSupabase: “canceling statement due to statement timeout” (57014)

“canceling statement due to statement timeout” is Postgres error 57014. The query ran longer than its role allows, so Postgres stopped it. Supabase sets 3 seconds for anon and 8 for authenticated. Make the query faster first, and raise the limit only when the work is truly long.

Short answer

Find the slow query in the Dashboard’s query performance report or with explain analyze. Add the missing index, select fewer rows, and make RLS policies cheap. If the work really needs longer, raise statement_timeout for the role that runs it (raising authenticated doesn’t change anon), reload PostgREST, or run it from a server with a direct connection.

Rather not fix it yourself? App Fix Ticket starts with a fixed-price diagnosis, then a fixed price for the fix before any fix work.

Why the query runs too long, and the fix

  1. 01

    The API roles have short limits

    “The default role timeouts are: anon: 3s authenticated: 8s” Supabase, Timeouts

    Postgres stops any statement that runs past statement_timeout, and supabase-js returns it as an error with code 57014. Calls from supabase-js run as anon or authenticated, with short limits so one slow query can’t hold the database. A report or export that is fine in the SQL editor can time out from the app.

  2. 02

    A missing index

    A filter or sort on a column with no index reads the whole table. Check the plan and add the index the query needs. explain analyze really runs the query, and in the SQL editor it runs as postgres, so it shows the plan but not the timeout.

    explain analyze
    select * from public.orders where customer_id = 'abc' order by created_at desc limit 20;
    
    create index if not exists orders_customer_created_idx
      on public.orders (customer_id, created_at desc);
  3. 03

    An RLS policy runs on every row

    A policy that calls auth.uid() or a function per row can make a simple select slow. Wrap the call as (select auth.uid()) so Postgres runs it once, and index the columns the policy filters on.

    create policy "own orders" on public.orders
      for select to authenticated
      using (customer_id = (select auth.uid()));
  4. 04

    The work really is long

    “If you are changing the timeout for the Supabase Client API calls, you will need to reload PostgREST to reflect the timeout changes by running the following script:” Supabase, Timeouts

    Raise the limit for the role that runs it, then reload PostgREST so the API uses it. Keep the limit as low as the job allows. For one-off jobs, a direct connection with a session setting is safer.

    alter role authenticated set statement_timeout = '15s';
    notify pgrst, 'reload config';
  5. 05

    Big updates and deletes in one statement

    Updating or deleting a large part of a table in one call can run past any limit. Split it into batches by id range, and page large reads with limit and range instead of fetching everything.

Checked against the vendor’s docs on : Supabase docs: Timeouts; PostgreSQL docs: Client connection defaults.

Rather hand it over?

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

“Very responsive, attentive to fixing bugs, and completed the project as needed! Thank you!”
A buyer in the United States, July 2022. Shopify on Fiverr
All 127 Fiverr reviews

Related: Supabase too many connections · Supabase Edge Function timeout · Supabase value too long for character varying · Prisma prepared statement already exists

Questions

More on this error

Why does the query work in the SQL editor?

The SQL editor runs as postgres, which has a longer limit than the API roles. The same query from the app runs as anon or authenticated.

Should I set the timeout to zero?

No. Zero turns the limit off, so one bad query can tie up the database. Fix the query, or raise the limit for one role by as little as the job needs.

Can you fix it for me?

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.

A different error?

Describe it and get a written quote

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; Simon replies by email, usually within one business day.