ERROR: permission denied for table (PostgreSQL) — how to fix
ERROR: permission denied for table users
ERROR: permission denied for sequence users_id_seq
Quick fix: As the table owner or a superuser run GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO app; and GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO app;. Add ALTER DEFAULT PRIVILEGES so tables created later are covered too.
What it means
In PostgreSQL, a table is owned by the role that created it. Other roles can only use it after a GRANT. Being able to connect to the database and see the schema is not enough. Typical setup that triggers it: migrations run as postgres or admin, while the app connects as app.
Check who you are and who owns the table:
SELECT current_user;
\dt users -- shows Owner
\dp users -- shows Access privileges
Fix 1: grant privileges on existing tables
Connect as the owner or a superuser, to the right database:
GRANT USAGE ON SCHEMA public TO app;
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO app;
For a read-only role, grant only SELECT.
ON ALL TABLES only affects tables that exist right now.
Fix 2: sequences (permission denied for sequence)
Inserting into a serial column calls nextval() on its sequence, which needs its own privilege:
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO app;
Fix 3: cover tables created in the future
Without this, the error comes back after the next migration:
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;
FOR ROLE must be the role that will create the tables (here migrator). Default privileges set by another role don't apply.
Fix 4: make the app role the owner
If one role creates and uses the tables, simplest is to have it own them:
ALTER TABLE users OWNER TO app;
Or run migrations as the same role the app uses. To transfer everything at once, REASSIGN OWNED BY old_role TO app; (run in each database).
Fix 5: you are in the wrong database or schema
Grants are per database. GRANT run while connected to postgres does nothing for tables in mydb:
psql -U postgres -d mydb -c "GRANT SELECT ON ALL TABLES IN SCHEMA public TO app;"
If tables live in another schema, grant USAGE on that schema and use its name instead of public.
Related: permission denied for schema public
That is a different error, common on PostgreSQL 15+, where ordinary users can no longer create objects in public by default. See permission denied for schema public.
Last updated 2026-12-01.