What it means
The statement ran longer than the statement_timeout for the database role it ran as,
so Postgres cancelled it. Supabase sets short defaults on purpose, so one slow API request can't hold a
connection for minutes:
| Role | Default timeout | Used by |
|---|---|---|
anon | 3 s | API requests without a signed-in user |
authenticated | 8 s | API requests with a user JWT |
service_role | none set; falls back to the authenticator role's 8 s | server code with the secret key |
postgres | none, capped by a 2 min global default | SQL Editor, direct connections |
Supabase's docs also say Dashboard and client queries can be raised to at most 60 seconds; longer work belongs on a direct or pooled connection.
Step 1: find out why it is slow
Run the same query with explain analyze in the SQL Editor. For an API query, also run it as the API role, because RLS policies are part of the cost:
begin;
set local role authenticated;
select set_config('request.jwt.claims', '{"sub":"<user-uuid>","role":"authenticated"}', true);
explain analyze
select * from public.orders where status = 'open' order by created_at desc limit 50;
rollback;Look for Seq Scan on a big table, a large Rows Removed by Filter, and a SubPlan that runs once per row (often an RLS policy). The dashboard's Query Performance report lists the slowest statements over time.
Step 2: the usual fixes
- Add the missing index for the filter and sort columns, and for every column an RLS policy compares:
create index concurrently if not exists orders_status_created_at_idx
on public.orders (status, created_at desc);
create index concurrently if not exists orders_user_id_idx
on public.orders (user_id);Run each create index concurrently on its own: it can't run inside a transaction block, so don't combine it with other statements in one run.
- Make RLS cheap: write
(select auth.uid())instead ofauth.uid()in policies so it is evaluated once per statement. - Paginate:
.range(0, 49)instead of fetching everything. - Avoid exact counts on big tables:
count: 'exact'scans every visible row;count: 'estimated'or'planned'is far cheaper. - Batch big writes: update or delete 1,000–10,000 rows per statement in a loop instead of one huge statement.
Step 3: raise the limit only where it is justified
If a query is as fast as it can be and still needs more time, raise the timeout for that role, then tell the API layer to reload its settings:
alter role authenticated set statement_timeout = '15s';
notify pgrst, 'reload config';This applies to every request from that role, so keep it modest. For one long admin or migration job, set it for that transaction only with SET LOCAL inside BEGIN … COMMIT. That works over a direct connection, session mode, and the transaction-mode pooler on port 6543 (one transaction keeps one connection). A plain session-level SET is the one that doesn't stick through the transaction-mode pooler:
begin;
set local statement_timeout = '10min';
-- the long statement
commit;Where it shows up besides the API
The SQL Editor runs as postgres, so a heavy one-off query is limited by the global cap. Cron jobs run as the role that scheduled them, so they hit that role's limit too. Creating an index on a large table can exceed it; use a direct connection for that kind of migration.
How to verify
explain analyze shows an index scan and an execution time well under the role's limit. The same API call returns data instead of 57014, and the timeout no longer appears when you search the Postgres logs for statement timeout.
FAQ
What is the default statement timeout in Supabase?
3 seconds for anon, 8 seconds for authenticated, and service_role falls back to the authenticator role's 8 seconds. The postgres role has no role-level timeout but is capped by a 2 minute global default.
Related guides
- Slow Supabase queries with RLS – (select auth.uid()), indexes and the other fixes
- Postgres “deadlock detected” (40P01) – read it, then remove the lock-order problem
- Supabase “too many connections” – Postgres slots, Supavisor limits and serverless pools
- Postgres “new row for relation … violates check constraint” – find the rule and fix it
More in Postgres errors and performance · all guides