Postgres "ERROR: permission denied for table": Causes and Fixes
Postgres "permission denied for table" means your role lacks a privilege on it. How to check grants, fix future tables with default privileges, and sequences.
"permission denied for table X" means the role you're connected as doesn't have the privilege the statement needs on that table: SELECT to read, INSERT, UPDATE or DELETE to write. Usually the table was created by a different role (often the one that runs migrations), and only the owner gets privileges automatically. The fix is a GRANT from the owner or a superuser, plus ALTER DEFAULT PRIVILEGES FOR ROLE <creator> so tables created later get the same grants. It's a different problem from "permission denied for schema" and from row-level security, which hides rows instead of raising this error.
Checked against the PostgreSQL 19 documentation (privileges, GRANT, ALTER DEFAULT PRIVILEGES, predefined roles, row security policies, CREATE VIEW, UPDATE, sequence functions, pg_dump and the error codes appendix) and the PostgreSQL 14 and 17 release notes, with every error below reproduced on PostgreSQL 18.7 in Docker, in November 2026.
The error looks like this in psql:
ERROR: permission denied for table users
With \set VERBOSITY verbose you also see the SQLSTATE, 42501 (insufficient_privilege):
ERROR: 42501: permission denied for table users
Java apps show it as org.postgresql.util.PSQLException: ERROR: permission denied for table users; Node's pg sets err.code to '42501'. Related messages from the same family:
| Message | What's missing |
|---|---|
permission denied for table users |
A privilege on that table |
permission denied for sequence users_id_seq |
USAGE on the sequence behind a serial column |
permission denied for schema billing |
USAGE on the schema (or CREATE, to make tables) |
must be owner of table users |
Ownership: ALTER, DROP and similar can't be granted |
new row violates row-level security policy for table "users" |
A row security policy that allows the write |
Step 1: who are you, and what do you have?
Confirm the role the app actually connects as. It's often not the one you think:
SELECT current_user, session_user;
Then look at the table's privileges in psql:
\dp users
Access privileges
Schema | Name | Type | Access privileges | Column privileges | Policies
--------+-------+-------+----------------------------+-------------------+----------
public | users | table | app=arwd/migrator +| |
| | | migrator=arwdDxtm/migrator | |
Each entry reads grantee=privileges/grantor; here migrator owns the table and app can read and write it. The letters are r SELECT, a INSERT, w UPDATE, d DELETE, D TRUNCATE, x REFERENCES, t TRIGGER and, from PostgreSQL 17, m MAINTAIN. An empty column means only the owner has access. You can also ask directly:
SELECT has_table_privilege('app', 'users', 'SELECT');
Cause 1: the table belongs to another role
The docs put the rule simply: "For most kinds of objects, the initial state is that only the owner (or a superuser) can do anything with the object." If your migrations run as migrator (or as postgres) and the app connects as app, every new table starts out invisible to app.
Grant what the app needs, as the table's owner or a superuser:
GRANT SELECT, INSERT, UPDATE, DELETE ON users TO app;
For every table in a schema at once:
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO app;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO app;
ON ALL TABLES is a one-off: it covers the tables that exist when you run it. We created a table straight after granting SELECT ON ALL TABLES to a role, and that role got "permission denied" on the new one. That's what default privileges are for.
Cause 2: new tables don't inherit grants (the FOR ROLE gotcha)
ALTER DEFAULT PRIVILEGES sets the privileges given to objects created in the future. The catch is whose future objects. Without FOR ROLE, it applies to tables created by the role running the command. Run it as postgres while migrations run as migrator, and it does nothing for your tables. We reproduced this: default privileges set by postgres, a table created by the owner role, and the app still got "permission denied".
Name the role that creates the tables:
ALTER DEFAULT PRIVILEGES FOR ROLE migrator IN SCHEMA public
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO app;
ALTER DEFAULT PRIVILEGES FOR ROLE migrator IN SCHEMA public
GRANT USAGE, SELECT ON SEQUENCES TO app;
You can do this as a superuser or as a member of migrator. Check the result with \ddp, where the Owner column is the creating role the rule applies to:
Default access privileges
Owner | Schema | Type | Access privileges
----------+--------+----------+-------------------
migrator | public | sequence | app=rU/migrator
migrator | public | table | app=arwd/migrator
postgres | public | table | app=r/postgres
Two more details from the docs: default privileges do "not affect privileges assigned to already-existing objects", so existing tables still need the GRANT ... ON ALL TABLES from Cause 1. And they're "not inherited from any roles in which the current role is a member", so a rule on a group role doesn't apply to tables created by its members. If several roles create tables, add a rule for each, or have them all SET ROLE to one owning role before creating anything.
Cause 3: serial columns need the sequence too
Reading works and inserting fails, with a slightly different message:
ERROR: permission denied for sequence users_id_seq
A serial or bigserial column's default calls nextval() on a sequence, which per the docs "requires USAGE or UPDATE privilege on the sequence". Grant it:
GRANT USAGE, SELECT ON SEQUENCE users_id_seq TO app;
Columns declared GENERATED ... AS IDENTITY don't need this: in our test, a role with only INSERT on the table could insert into an identity column without any grant on its sequence.
Cause 4: the statement needs more than you think
Some statements check privileges you might not expect:
UPDATEandDELETEwith aWHEREalso needSELECT. The docs: "any nontrivial UPDATE command will require SELECT privilege as well, since it must reference table columns." A role withINSERT, UPDATE, DELETEbut noSELECTgets "permission denied" onUPDATE ... WHERE id = 5.TRUNCATEis its own privilege.DELETEdoesn't cover it. A test suite that truncates tables between runs needsGRANT TRUNCATE.- Column-level grants. If a role has
SELECT (id, name)only,SELECT id, nameworks andSELECT *fails with "permission denied for table". - Views check the view owner. "By default, access to the underlying base relations referenced in the view is determined by the permissions of the view owner." If the view's owner can't read the base table, querying the view fails with "permission denied for table" naming the base table, even though you have
SELECTon the view. Grant the owner access, or create the viewWITH (security_invoker = true)so the caller's own privileges are checked.
Cause 5: a restore dropped the grants
After moving a database with pg_dump/pg_restore, it's common for every table to be denied at once. Two options cause this: -x/--no-privileges skips the GRANT statements, and -O/--no-owner makes the restoring user the owner of everything. Either leaves the app role with nothing. Re-run the grants and default privileges from Causes 1 and 2 against the new database, or restore without those options when the roles exist on the target. Postgres backup and restore covers the commands.
Not this error: ownership, schemas and RLS
Ownership. ALTER TABLE, DROP TABLE and CREATE INDEX need you to own the table. The docs say that right "is inherent in being the object's owner, and cannot be granted". GRANT ALL doesn't include it; you get must be owner of table users. Run migrations as the owning role, or change the owner:
ALTER TABLE users OWNER TO migrator;
Schemas. Table privileges are useless without USAGE on the schema. We granted SELECT on billing.invoices but not the schema, and got permission denied for schema billing; GRANT USAGE ON SCHEMA billing TO app fixed it. If the message is about public and you're creating tables, it's the PostgreSQL 15 change covered in permission denied for schema public.
Row-level security. With RLS enabled and no matching policy, the docs describe "a default-deny policy": SELECT returns zero rows and inserts fail with new row violates row-level security policy. You never see "permission denied for table" from RLS. If a query unexpectedly returns nothing, run \d users: a line like Policies (row security enabled): (none) means RLS is on with no policies. Superusers, roles with BYPASSRLS and, normally, the table's owner skip RLS, which is why it can look fine in psql as postgres and empty in the app. Multi-tenant Postgres patterns shows how policies are usually set up.
Broad access: pg_read_all_data and pg_write_all_data
For a reporting user or a backup job, PostgreSQL 14 added two predefined roles:
GRANT pg_read_all_data TO reporter;
GRANT pg_write_all_data TO etl_job;
pg_read_all_data acts "as if having SELECT rights" on all tables, views and sequences and USAGE on all schemas, including tables created later. pg_write_all_data does the same for INSERT, UPDATE and DELETE. Two limits we confirmed: neither bypasses row-level security, and pg_write_all_data doesn't include SELECT, so its UPDATE ... WHERE statements fail until you also grant pg_read_all_data. They're also database-wide, which is more than an app should usually get. Postgres roles and permissions walks through a least-privilege setup with separate owner, app and read-only roles.
Quick checklist
- Run
SELECT current_userfrom the app's connection, not yourpsqlsession. \dp tablename: does that role appear, with the letters it needs?- Grant on the table, or
ON ALL TABLES IN SCHEMA, plus sequences forserialcolumns. - Add
ALTER DEFAULT PRIVILEGES FOR ROLE <the role that creates tables>and check\ddp. UPDATE/DELETEfailing? GrantSELECTtoo. Via a view? Check the view owner's access.- "must be owner", "permission denied for schema" or zero rows? That's ownership, schema
USAGEor RLS.
On EasySpawn, Postgres is provisioned on the same server as your app, with the connection details passed to it as environment variables. Claude Code works on that server, so when a new table is denied it can run \dp and \ddp as the app's role and write the grant and default-privilege migration. Which role owns the tables and how much the app may touch is still a choice you make, and the grants above are how you express it. See how it works or join the waitlist.
Related: Postgres "ERROR: permission denied for schema public": Why It Happens Since PostgreSQL 15 and How to Fix It · Postgres Roles and Permissions: CREATE USER, GRANT, and Least Privilege · Postgres "ERROR: relation does not exist": Causes and Fixes · Postgres "password authentication failed for user": How to Fix It
Keep reading
Supabase Error 406 "Not Acceptable" (PGRST116): Why .single() Fails and How to Fix It
A Supabase 406 almost always means .single() got zero rows or several. Why row-level security often causes it, and when to use .maybeSingle() or fix a policy.
pg_stat_statements: Find the Queries Slowing Down Your Postgres
pg_stat_statements records statistics for every distinct query your database runs — calls, total and mean time, rows, cache hits. How to enable it, the queries to find what costs the most, interpreting the results, resetting, and turning findings into indexes and fixes.