App Finishers

Fix guide · updated 2026-11-16

Supabase "canceling statement due to statement timeout" (57014)

{"code":"57014","details":null,"hint":null,"message":"canceling statement due to statement timeout"}

A Supabase query fails with "canceling statement due to statement timeout", code 57014, HTTP 500. Usually after exactly 3 seconds for visitors who aren't signed in, or 8 seconds for signed-in users. Nothing is broken: the query ran longer than its time limit, so Postgres stopped it. We measured the limits, the ways to change them, and what row level security costs on 2 million rows, on Postgres 16 behind Supabase's Data API (PostgREST 13), November 2026.

What the error means

Each request through the Data API runs as a database role, and each role has a time limit. Supabase's docs give the defaults: anon, a visitor who isn't signed in, 3 seconds; authenticated, a signed-in user, 8 seconds; service_role, none of its own, so the 8 seconds of the role it connects through apply. In our test, a 4-second query failed after 3 seconds for a visitor and worked for a signed-in user, and a 9-second query failed after 8 seconds.

So there are two ways out: make the query faster, which is almost always possible, or give it more time. Supabase's docs cap API queries at 60 seconds whatever you set.

Cause 1: a policy that runs a function on every row

A row level security policy is checked for every row Postgres looks at. A policy like using (private.is_member(team_id)), with a helper function written in plpgsql, runs that function once per row. We counted the 4,000 rows a user could see in a table of 2 million:

That gap is what decides a timeout. Through the API, a list of 5 rows still loaded at once, because Postgres stops looking when it has 5, but the same list with the total count failed after 8 seconds.

Cause 2: auth.uid() without select

The most common policy, user_id = auth.uid(), also calls a function per row. Wrapped in select, Postgres runs it once for the whole query. On the same 2 million rows:

Cause 3: asking for the total count

select('*', { count: 'exact' }) makes Postgres count every row the user may see, checking the policy on each one, even when you only show 10. In our test, that's what turned a fast list into a timeout. supabase-js also has count: 'planned', which uses Postgres's statistics, and count: 'estimated', which counts exactly only when the number is small.

Cause 4: a function that really takes long

A report or a batch job called with rpc() can need more than 8 seconds even when written well. Give that one function its own limit (Fix 4) instead of raising it for everything.

The one-minute check

The SQL Editor runs as postgres, which owns your tables, and table owners skip row level security, so the query looks fast there. Run it as a signed-in user instead, with a real user id:

begin;
set local role authenticated;
select set_config('request.jwt.claims', '{"sub":"USER-ID-HERE"}', true);
explain analyze select count(*) from public.tasks;
rollback;

Read the total at the bottom, "Execution Time". A line like Filter: (user_id = auth.uid()) or Filter: private.is_member(team_id) under a Seq Scan means the function runs on every row the scan reads.

Fix 1: call policy functions once

drop policy "own tasks" on public.tasks;
create policy "own tasks" on public.tasks for select to authenticated
  using (user_id = (select auth.uid()));

For team or role checks, make the helper return the list once and compare against it:

create policy "team tasks" on public.tasks for select to authenticated
  using (team_id in (select private.my_team_ids()));

Fix 2: index the columns your policies and filters use

create index on public.tasks (user_id);

In our test, this took the signed-in user's count from 105 milliseconds to 1.

Fix 3: drop the exact count on big tables

Use count: 'planned' or 'estimated', or show "next page" instead of "page 3 of 2,000".

Fix 4: more time for one function

alter function public.monthly_report() set statement_timeout = '30s';

In our test, a 4-second function with its own 10-second limit worked for a visitor, whose limit is 3 seconds.

Fix 5: more time for a whole role, last

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

Don't skip the second line. In our test, without it the old limit still applied, and after it the new one did. Think twice before raising the limit for anon: anyone on the internet can send those queries.

If an AI tool built your app

Give your AI tool this prompt, with your table's name:

My Supabase query on public.tasks fails with "canceling statement due to statement timeout" (57014). Review the RLS policies on this table: wrap auth.uid() and auth.jwt() in (select ...), and replace helper functions that run on every row with a helper that returns the allowed ids once (column in (select helper())). Add indexes on the columns the policies and my filters use. Replace count: 'exact' with count: 'planned' where the table is large. Write it as a migration and show me the SQL before running it.

Not quite your error?

Still stuck?

Run the check above for each table the slow request touches, including tables your policies read. The one with the biggest "Execution Time" is the one to fix first.

Other Supabase problems? See Supabase fixes.