error: permission denied for table profiles

Node.js · updated 2026-11-10

Raised by Postgres (SQLSTATE 42501) when the role running the query lacks the table privilege (SELECT, INSERT, UPDATE or DELETE) for it. The same code with "permission denied for sequence" means an insert needs USAGE on the sequence behind a serial id. Grants are checked before policies, so a correct RLS policy does not help. node-postgres throws it, psycopg raises InsufficientPrivilege, supabase-js returns it in the error field.

error: permission denied for table profiles
    at node_modules/pg/lib/client.js:694:17
    at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
  code: '42501'

Quick fix

Grant the role the privilege it needs on that table, then retry. For inserts into a table with a serial id, also grant USAGE on its sequence. Then check that the table's row-level security policies allow the rows you expect, since grants only decide whether the command can run at all.

  1. Note which role the app connects as, or which role the request runs as (on Supabase, anon without a session and authenticated with one).
  2. See what it has: select grantee, privilege_type from information_schema.role_table_grants where table_name = 'profiles'.
  3. Grant only what the app needs: grant select, insert on public.profiles to authenticated.
  4. serial or identity ids: grant usage on sequence public.profiles_id_seq to the same role.
  5. Tables created by a migration role or another owner may not get your default privileges; set alter default privileges for future tables.
bash
grant select, insert, update on public.profiles to authenticated;
grant usage on sequence public.profiles_id_seq to authenticated;

-- Then row-level security decides which rows each user can touch
alter table public.profiles enable row level security;

Why it happens

Table created without grants for the app role

A migration or SQL editor session created the table as another owner, and the role the app uses was never granted access.

Missing sequence privilege

Inserting into a serial id column also needs USAGE on its sequence; the error then says permission denied for sequence profiles_id_seq.

Wrong role

The request runs as anon (no session) or as a read-only user, not the role you granted.

Revoked privileges

A security change revoked default privileges from public or from the API roles, and new tables no longer get them.

Other fixes

  • Don't grant all on everything to fix it: grant the commands the app uses and let row-level security limit the rows.
  • A row-level security failure reads differently: "new row violates row-level security policy". This one means the command never got that far.

Same error, other wording

  • error: permission denied for sequence profiles_id_seq
  • psycopg.errors.InsufficientPrivilege: permission denied for table profiles
  • {"code":"42501","message":"permission denied for table profiles"}

Let your coding agent catch the next one

Runheed records this error in production with the stack trace, the breadcrumbs before it and, when you set it, the agent session that shipped the code, and serves it to Claude Code, Cursor or any MCP client. With it connected, you can ask:

> Find the "permission denied for table" and "permission denied for sequence" errors, tell me which role and table each came from, and write the narrowest GRANT that fixes each.

Setup for Node.js and Express or Vercel Functions, then have your agent fix and resolve it.

Related errors

More in Databases

References: PostgreSQL docs: GRANT, PostgreSQL docs: ALTER DEFAULT PRIVILEGES, Supabase docs: Row Level Security (a missing grant fails before any policy runs)

Spotted a mistake? Email hello@greatwork.company. About Runheed.