Supabase Permission Denied for Table (42501): The Safe Fix
"Permission denied for table" in Supabase, error code 42501, means the role making the request has no grant on that table. It is not a row level security problem: Postgres checks grants first and stops before any policy runs. Since 30 October 2026, new tables in public no longer get grants automatically, so every table you or your AI tool creates now needs them written out. The safe fix is three statements in this order: enable RLS, add the policies, then grant each role only what it uses.
The fix to avoid is the one-liner that makes the error go away everywhere, grant all on all tables in schema public to anon, authenticated. This post covers both, with SQL you can paste.
What "permission denied for table" means in Supabase
A request through the Supabase client passes two separate layers in the database:
- Grants decide whether a role may touch the table at all.
- Row level security decides which rows that role sees or changes.
The roles are anon (a visitor who isn't signed in), authenticated (a signed-in user) and service_role (your server, with the secret key). If the role has no grant, the request ends at layer 1 and the API returns this:
{
"code": "42501",
"message": "permission denied for table notes",
"hint": "Grant the required privileges to the current role with: GRANT SELECT ON public.notes TO anon;"
}That shape is from Supabase's changelog entry for the change, which describes the two layers the same way: "Grants are a separate layer: they control whether a role can access a table at all, while RLS controls which rows that role can see."
So rewriting your policies does nothing for this error. No policy has run yet.
Why new tables started returning 42501
Supabase used to grant select, insert, update and delete on every new table in public to all three roles. A table you created was reachable from the browser the moment it existed. That changed in steps:
- 28 April 2026: new projects could opt out of the automatic grants.
- 30 May 2026: opting out became the default for new projects, rolled out gradually.
- 30 October 2026: in the changelog's words, "the new behavior is enforced on all existing projects."
Three details from the same entry matter when you debug:
- Existing tables are not affected. "Existing objects keep their current grants, so your running app stays reachable." Only tables created after the change reached your project fail.
service_rolelost its automatic grants too. If your server code with the secret key gets42501on a new table, this is why. The secret key skips RLS, not grants.- Direct connections are not affected. If your app talks to Postgres with a connection string (an ORM,
psql), nothing changed. This is about the Data API thatsupabase-jscalls.
That's why the error tends to appear on the newest feature of an app that otherwise works: the old tables still carry their grants, the new one has none.
How to fix permission denied for table, in the safe order
Do these three things together, for the table in the error message. The example is a notes table where each user owns their rows.
-- 1. Turn on row level security
alter table public.notes enable row level security;
-- 2. Say which rows a signed-in user may touch
create policy "own notes" on public.notes
for all to authenticated
using (owner = (select auth.uid()))
with check (owner = (select auth.uid()));
-- 3. Grant the role what the app uses, and nothing else
grant select, insert, update, delete on public.notes to authenticated;Supabase's changelog lists the grant first and RLS second. The end state is the same. The order above is safer while you work, because a table is never reachable with RLS off, not even for the minute between two statements or when a migration fails halfway.
We ran this on Supabase's Postgres 17 image with the automatic grants revoked, the state every project is in now:
- Before the grant,
authenticatedgot42501with the hint above. - After it, the owner could insert and read their own row.
- A second signed-in user saw zero rows, and their attempt to insert a row under the owner's id failed with "new row violates row-level security policy".
anonstill got42501, because nothing granted it anything. That is the result you want for a private table.
Which grants each role needs
Grant per table and per role. Most apps need less than they think.
| Table is for | anon | authenticated | service_role |
|---|---|---|---|
| Each user's own data (notes, orders, profiles) | nothing | select, insert, update, delete | only if your server uses it |
| Public content (products, published posts) | select | select | what your server writes |
| Server-only data (webhook events, usage counters) | nothing | nothing | select, insert, update, delete |
For a table signed-out visitors should read, add the grant and a read policy:
grant select on public.products to anon, authenticated;
create policy "anyone can read products" on public.products
for select to anon, authenticated
using (true);For a table only your server touches, enable RLS, add no policies, and grant only service_role:
alter table public.stripe_events enable row level security;
grant select, insert, update, delete on public.stripe_events to service_role;In our test service_role got the same 42501 on a new table until it had its own grant.
Permission denied for sequence
If the next error is permission denied for sequence notes_id_seq, the table's id column is a serial or bigserial. Inserting takes the next number from a sequence, and the sequence needs its own grant:
grant usage, select on sequence public.notes_id_seq to authenticated;Identity columns (generated always as identity) and uuid ids with gen_random_uuid() don't need this. In our test the identity table accepted inserts with only the table grant, and the serial table failed until the sequence grant was added. For new tables, an identity or uuid id is one less thing to grant.
The fix to avoid: grant all on all tables
Search for this error, or ask an AI assistant, and you'll often get this:
-- Makes the error go away. Read on before you run it.
grant all on all tables in schema public to anon, authenticated;It works, and it is how a project gets back to the old behavior. The problem is what it does to any table that doesn't have RLS on, or has a policy like using (true). The grant was the only thing between that table and the internet.
We tested it. A customers table with two rows and RLS off returned 42501 to anon. After the blanket grant, anon read both rows and deleted one. The table with RLS on and an owner policy still returned nothing to anon. The grant is only as safe as the RLS behind it, for every table in the schema at once.
Two related shortcuts have the same effect:
- Restoring the default privileges.
alter default privileges ... grant select, insert, update, delete on tables to anon, authenticated, service_rolemakes every future table reachable on creation again. Supabase's changelog documents it as the rollback. We confirmed that after it, a new table with RLS off was readable byanonstraight away. If you roll back, you are again relying on remembering RLS for every new table. - Following the hint on its own. The error's hint gives you the
GRANTand nothing else. An AI tool that reads the hint and runs it has fixed the error and may have exposed the table. The hint is correct, but it's only step 3.
If you already ran the blanket grant, take it back for tables that should be private:
revoke all on table public.customers from anon, authenticated;Then check that every table that keeps a grant has RLS on. The query in the next section lists them.
Check which tables each role can reach
Paste this into the SQL Editor. It lists every table in public, whether RLS is on, and which roles can read it.
select
c.relname as table_name,
c.relrowsecurity as rls_on,
has_table_privilege('anon', c.oid, 'select') as anon_select,
has_table_privilege('authenticated', c.oid, 'select') as authenticated_select,
has_table_privilege('service_role', c.oid, 'select') as service_role_select
from pg_class c
where c.relnamespace = 'public'::regnamespace
and c.relkind = 'r'
order by c.relname;Read the result like this:
rls_onfalse andanon_selectorauthenticated_selecttrue: the table is open. Fix this first. Supabase RLS disabled in public walks through it.- All three select columns false: nobody can reach it through the API. That's the
42501table, or a table that is private on purpose. rls_ontrue and a grant: the policies decide. Test them as two different users, as in how to test Supabase RLS.
When 42501 is not a missing grant
The same code covers a second error, and the fix is different:
| Message | Cause | Fix |
|---|---|---|
permission denied for table notes | No grant for the role | The three steps above |
permission denied for sequence notes_id_seq | No grant on a serial sequence | The sequence grant |
new row violates row-level security policy for table "notes" | The grant is fine, the with check of a policy refused the row | Fix the policy or the row you send |
For the third one, the usual cause is an insert that doesn't set the owner column, or sets it to something other than the signed-in user's id. Supabase RLS policy examples covers using and with check.
Put the grants in the migration
A grant you ran once in the SQL Editor fixes today's database. The next environment, a branch or a fresh project, is built from your migration files, so the three statements belong next to the create table:
create table public.notes (
id bigint generated always as identity primary key,
owner uuid not null default auth.uid() references auth.users (id),
body text not null
);
alter table public.notes enable row level security;
create policy "own notes" on public.notes
for all to authenticated
using (owner = (select auth.uid()))
with check (owner = (select auth.uid()));
grant select, insert, update, delete on public.notes to authenticated;If an AI tool writes your tables, tell it the rule once so it stops guessing. Something like this in your project instructions:
Every new table in the public schema gets, in the same migration:
1. alter table ... enable row level security
2. policies that limit rows to their owner (never using (true) on user data)
3. grants per role: only the privileges the app uses, never "grant all",
never "on all tables in schema public", nothing for anon unless
signed-out visitors must read the table.
Never change default privileges.Fix checklist
- Read the error: the table name and the role are in the message and the hint.
- Enable RLS on that table.
- Add policies for the rows each role may see and change.
- Grant that role only the privileges the app uses.
- For a
serialid, grantusage, selecton the sequence. - Give
service_roleits own grant if your server reads or writes the table. - Don't run
grant all on all tables, and don't restore the default privileges. - Run the query above and confirm no table has a grant with RLS off.
- Put the same statements in the migration that creates the table.
Checking the migrations in your repository
The query above checks the database you're connected to. Your repository decides what the next one looks like. A free Tuvio scan needs no account and reads the Supabase migrations in your GitHub repo. It flags tables your migrations create and never turn RLS on for, policies open to anyone such as using (true), and a migration that restores the default privileges so every new table is exposed again.
It reads files, not your live project. A table made in the dashboard, or a grant run by hand in the SQL Editor, isn't in the repo and isn't seen. For the live side, use the query above and the Supabase Security Advisor. What Tuvio checks is listed on the coverage page.