Deutsch
Error messageSupabase · Grants

Fix “permission denied for table” in Supabase (error 42501)

Why Supabase says permission denied for table, why new tables hit it since the 2026 Data API change, and the grants that fix it without opening your data.

The message you seePostgres · 42501

permission denied for table notes

By Tim GeithnerPublished 5 min read

Short answer

Postgres refused the query because the role behind the request has no privilege on the table. Since Supabase’s 2026 Data API change, the most common cause is a new table: tables created in public no longer get grants for anon, authenticated and service_role automatically. Other causes are a migration that revoked grants, a table in another schema, a request running as the wrong role, or columns the role may not read. Fix it with explicit grants per role plus RLS policies, never with grant all to anon.

Ask an AI about this page:ChatGPTClaude

On this page

Postgres checks two things before a query touches a row. First: may this role use the table at all? That is a grant. Only then: which rows may it see or write? That is row level security. permission denied for table fails the first check, so RLS never even runs. The request runs as one of Supabase’s roles (anon without a session, authenticated with one, service_role with the secret key), and that role has no grant for what the query wants. Through the Data API the response carries code 42501 and HTTP status 403 when signed in, 401 when signed out.

Find your cause in 30 seconds

What you seeMost likely cause
The table was created recently, older tables workThe table is new
It broke right after a security or cleanup migrationA migration revoked the grants
The table is not in publicThe table lives in another schema
It fails only when signed out, or only in an Edge FunctionThe request runs as the wrong role
select('*') fails, a short column list worksSome columns are off limits

We reproduced every cause on Postgres with Supabase’s roles. The table on this page already has RLS and owner policies, so the only thing missing is the grant:

The table used on this page
create table public.notes (
  id uuid primary key default gen_random_uuid(),
  user_id uuid not null default auth.uid() references auth.users (id) on delete cascade,
  body text not null,
  created_at timestamptz not null default now()
);

alter table public.notes enable row level security;

create policy "Users can read their notes"
  on public.notes for select
  to authenticated
  using ((select auth.uid()) = user_id);

create policy "Users can add their own notes"
  on public.notes for insert
  to authenticated
  with check ((select auth.uid()) = user_id);

The five causes

1. The table is new

This is the number one cause today. Supabase changed how new tables reach the Data API. From 28 April 2026 you could opt out when creating a project, from 30 May 2026 it was the default for new projects, and since 30 October 2026 it applies to all projects. A table created in public after that gets no grants for anon, authenticated or service_role. Tables that existed before keep theirs.

So the AI builder writes a migration with a perfect table, RLS and policies, and the first request still fails. The policies are fine. The role is simply not allowed through the door.

2. A migration revoked the grants

A security review, the Security Advisor or an AI asked to “harden the database” may add a line like revoke all on all tables in schema public from anon, authenticated. That closes every table, including the ones your app needs. Look for revoke in your recent migrations.

3. The table lives in another schema

Default grants only ever covered public. A table in a schema of your own (app, billing, private) needs grant usage on schema and a grant on the table, and the schema must be listed under Exposed schemas in the Data API settings. Without usage on the schema the message is permission denied for schema app instead.

4. The request runs as the wrong role

Grants are per role. If you granted authenticated only, a request that runs before the session is restored runs as anon and fails. The reverse happens on the server: since the 2026 change, service_role gets no automatic grant on new tables either, so an Edge Function using the secret key fails with the same message. Check which role the request really uses before you add a grant.

5. Some columns are off limits

Grants can be per column. If a migration granted select (id, body), then select('*') asks for columns the role may not read, and Postgres refuses the whole query with the same table message. Either select only the granted columns or grant the column you need.

How to fix it

Grant each role exactly what it needs, and keep RLS doing the row-level work. For a table of private notes:

SafeFix: grant each role only what it needs
grant select, insert, update, delete on table public.notes to authenticated;
grant select, insert, update, delete on table public.notes to service_role;

What each part does:

  • authenticated may now use the table, and the policies decide which rows. Without the select policy, this grant still shows nothing.
  • service_role is for your server code and webhooks. Leave it out if nothing on the server touches the table.
  • anon gets nothing. Grant select to anon only for a table that signed-out visitors may read, such as published blog posts, and only with a select policy that limits the rows. This follows the least privilege rule.

You can do the same in the dashboard under Integrations → Data API. If your table uses serial or bigserial ids instead of uuid or generated ... as identity, inserts need the sequence too, or the next error is permission denied for sequence:

SafeOnly for serial ids: the sequence
grant usage on sequence public.items_id_seq to authenticated, service_role;

For a table in another schema, grant usage on the schema first, then the table, and add the schema under Exposed schemas:

SafeFix: a table in another schema
grant usage on schema app to authenticated, service_role;
grant select, insert, update, delete on table app.notes to authenticated, service_role;

Then check the table’s RLS: a grant without policies opens nothing, but a grant on a table without RLS opens everything. The guide on roles and permissions in Supabase explains how grants and policies work together.

VulnerableThe fix that opens every table
alter table public.notes disable row level security;
grant all on all tables in schema public to anon;
Fix permission denied for table without opening the data

My Supabase app fails with “permission denied for table your_table” (code 42501). Find the table in the migrations and every place in the code that uses it, and tell me which role each call runs as (anon, authenticated or service_role). Then write a new migration that grants only what is needed: select, insert, update, delete to authenticated if signed-in users use the table, the same to service_role only if server code uses it, and nothing to anon unless signed-out visitors must read it. If the id uses serial, grant usage on its sequence. Make sure row level security is enabled on the table and that there are policies for the authenticated role that limit rows to the owner with (select auth.uid()).

Do not grant all on all tables, do not grant anything to anon that is not needed, do not disable row level security and do not use the service role key in client code. Show me the migration before applying it.

Check that the fix works

In the SQL Editor, list what each API role may do on the table:

Check: who may use the table
select grantee, string_agg(privilege_type, ', ' order by privilege_type) as privileges
from information_schema.role_table_grants
where table_schema = 'public'
  and table_name = 'notes'
  and grantee in ('anon', 'authenticated', 'service_role')
group by grantee
order by grantee;

You should see authenticated and service_role with DELETE, INSERT, SELECT, UPDATE and no row for anon. Then read the table as a signed-in user. Use a real user id from Authentication → Users:

Check: read as a user
begin;
set local role authenticated;
set local request.jwt.claims = '{"sub": "11111111-1111-1111-1111-111111111111", "role": "authenticated"}';
select count(*) from public.notes;
rollback;

The count is the number of that user’s notes, not an error. Run it once more with another user’s id: the count must not include the first user’s notes. If it does, the grant worked but a policy is too open, and the guide to testing RLS policies shows what to check next.

Frequently asked questions

My app worked last month. Why do new tables suddenly fail?

Supabase stopped granting new tables in the public schema to the API roles automatically. New projects got the new default from 30 May 2026, and all existing projects from 30 October 2026. Tables you created before keep their grants; tables created after need an explicit grant.

Is this the same as the row-level security error?

No. Both use code 42501, but permission denied for table means the role may not touch the table at all, so RLS never runs. new row violates row-level security policy means the role may use the table, but no policy allows this row.

Should I just grant everything to anon so it works?

No. The anon role is what anyone with your public key gets. Grant anon only what signed-out visitors may really do, usually nothing or select on a public table, and always keep RLS on with policies that limit the rows.

Why does the query work in the SQL editor?

The SQL editor runs as the postgres role, which owns the tables and needs no grants. Your app runs as anon, authenticated or service_role, and each of them needs its own grant.

Sources

  1. 1.Breaking change: tables not exposed to Data and GraphQL API automatically — Supabase Changelog
  2. 2.Database API 42501 errors — Supabase Docs
  3. 3.Securing your API — Supabase Docs
  4. 4.Using custom schemas — Supabase Docs
  5. 5.GRANT — PostgreSQL Documentation

Find this in your own app

ShipRely reads your repository (read-only), proves each finding with file and line, and gives you a fix prompt to paste into your AI builder.

Run a demo audit
  • Read-only access to your repository
  • Every finding with file and line
  • Fix prompts for Lovable, Cursor, Claude Code and Bolt