permission denied for table "<your_table>" (Postgres 42501)

Filed under Supabase & databases

Most likely causeAbout 10 min · 6 steps

The role your app connects as (anon or authenticated) was never granted privileges on that table — usually because the table was created outside Supabase's Table Editor.

Grant the role table access
Cover the ID sequence too
Set default privileges

Fastest route

Give your AI this prompt

Copy it, replace the bracketed part with your error, and send it.

Preview the prompt
My app is getting Postgres error 42501: permission denied for table "[paste table name]" when it queries through Supabase. The table was created by [the Table Editor / pasted SQL / a migration tool / a restore — pick one], and the failing request is made as [a signed-in user / a signed-out visitor].

Here is how the app accesses the table: [paste the query code, and say whether the user is signed in].

Please: 1) confirm from the error wording that this is a privileges (GRANT) problem and not the row-level security policy error, 2) write the GRANT statements for the correct role (authenticated for signed-in users, anon only if visitors truly need it), including sequence grants if the table uses a serial ID, 3) write the follow-up statements to enable Row Level Security and add matching policies, so the grant does not expose every row, 4) add ALTER DEFAULT PRIVILEGES statements so future tables get the grants automatically.

Constraints: grant only the operations the app actually uses, do not suggest using the service role key in browser code as the fix, and do not turn off RLS. Show me each statement and tell me what it does in one plain sentence.

Fix it yourself

Follow the repair

  1. First, confirm this is not the RLS error. The two 42501 errors read differently, and they have opposite fixes. "Permission denied for table" means missing privileges — keep going here. "New row violates row-level security policy" means privileges are fine but no policy allows the row — that is the RLS fix, not this one. Adding policies will never fix a missing grant, and adding grants will never fix a missing policy; some unlucky tables need both, in this order.
  2. Grant the API roles access to the table. Run this in the Supabase SQL Editor, replacing the table name with yours. Grant what the app genuinely needs — read and write for signed-in users is the common case:
    grant select, insert, update, delete
    on table public.your_table
    to authenticated;
    
    -- Only if signed-out visitors truly need read access:
    grant select on table public.your_table to anon;
    Be deliberate with anon: that role represents anyone on the internet holding your public key, and step 5 is what keeps a broad grant safe.
  3. Grant the sequence too, if inserts are involved. If the table's ID is a serial or identity-style counter and the error names a sequence ("permission denied for sequence your_table_id_seq"), the role also needs:
    grant usage, select
    on sequence public.your_table_id_seq
    to authenticated;
    Tables with generated UUID IDs do not use a sequence and skip this step entirely.
  4. If the table is in a custom schema, grant schema usage first. Table grants cannot work until the role is allowed into the schema itself:
    grant usage on schema your_schema to authenticated;
    grant select, insert, update, delete
    on all tables in schema your_schema
    to authenticated;
    Note that Supabase's API only exposes certain schemas by default, so a custom schema may also need to be added to the API's exposed schemas in your project settings before any of this is reachable from the app.
  5. Now do the RLS half — do not skip it. A grant decides who can touch the table; with Row Level Security off, a signed-in user with a table grant can read and change every row, not just their own. Right after granting, make sure RLS is enabled on the table and policies exist for the operations you granted:
    alter table public.your_table enable row level security;
    -- then add policies per operation, e.g. for select:
    create policy "Users can read their own rows"
    on public.your_table for select to authenticated
    using (auth.uid() = user_id);
    Grants open the door; RLS decides which rooms inside each person may enter. Shipping the grant without RLS is the classic way a quick fix becomes a data leak.
  6. Set default privileges so the next table is born fixed. If you or your tools create tables regularly, tell Postgres to apply the standard grants automatically to future tables created by the postgres role in the public schema:
    alter default privileges in schema public
    grant select, insert, update, delete on tables to authenticated;
    alter default privileges in schema public
    grant select on tables to anon;
    This only affects tables created after you run it — existing tables still need step 2 individually, or a one-off grant on all tables in the schema, as in step 4.
Why this happensOptional explanation

Postgres has two separate permission systems, and mixing them up is why this error confuses everyone. The first is privileges: whether a role is allowed to touch a table at all — SELECT, INSERT, UPDATE, DELETE. The second is Row Level Security: once a role is allowed in, which individual rows it may see. "Permission denied for table" comes from the first system. Your app does not connect as you; through Supabase's API it connects as the anon role (visitors) or the authenticated role (signed-in users), and Postgres is saying that role holds no privileges on this table whatsoever.

Why would a table have no grants? Because of how it was born. Tables created in Supabase's Table Editor get the standard grants automatically. Tables created by raw SQL in some flows, by external migration tools, by restoring a backup, or by an AI following a tutorial written for plain Postgres often do not — the table exists, you can see it and query it in the SQL Editor (which runs with higher privileges), but the API roles were never let in. The same thing happens with sequences — the counters behind auto-incrementing IDs — and with tables in schemas other than public, which additionally need a schema-level usage grant before any table grant can work.

  • Table created outside the Table Editor: SQL scripts, migration tools, and restores can skip Supabase's automatic grants.
  • Grants given to the wrong role: access was granted to postgres or service_role, but your app connects as anon or authenticated.
  • Missing sequence permission: inserts fail with "permission denied for sequence" when the table's ID counter was left out.
  • Custom schema: the table lives outside the public schema, which also needs a usage grant on the schema itself.

Quick answers

How is this different from the row-level security error?

By the wording. 'Permission denied for table' is the privileges system: the role has no SELECT/INSERT/UPDATE/DELETE grant on the table at all. 'New row violates row-level security policy' is the RLS system: the grant exists, but no policy allows that row. Both share code 42501, and a table can need both fixes — grants first, then policies.

Why do some of my tables work and new ones do not?

Because of how they were created. Tables made in Supabase's Table Editor receive the standard grants to the anon and authenticated roles automatically. Tables created by pasted SQL in some flows, external migration tools, restores, or tutorials written for plain Postgres often do not, so the table exists but the API roles were never let in.

Once I grant access, can I skip Row Level Security?

No — they do different jobs. The grant decides whether the role can use the table at all; RLS then decides which rows that role may see or change. With a grant and no RLS, every signed-in user can reach every row. Grant first, then enable RLS with policies — the pair together is the safe configuration.

One fix, every Friday.

One real error, explained in plain English, with the fix — in your inbox every Friday. No spam, no jargon, unsubscribe anytime. Every issue closes with a verse and a word of encouragement.