Get Started Free

Fix "permission denied" errors in PostgreSQL

Fix PostgreSQL permission denied errors for tables, schema public (PostgreSQL 15+), sequences and new tables, plus "must be owner of table".

Updated November 26, 2026 · Tested on PostgreSQL 16.14, node-postgres 8.23, psycopg 3.3, psycopg2 2.9

Quick Answer

Your role is missing a privilege on the object named in the error. As the owner or a superuser, grant the one it asks for:

-- permission denied for table orders
GRANT SELECT, INSERT, UPDATE, DELETE ON orders TO app_user;

-- permission denied for sequence orders_id_seq
GRANT USAGE ON SEQUENCE orders_id_seq TO app_user;

-- permission denied for schema sales
GRANT USAGE ON SCHEMA sales TO app_user;

On PostgreSQL 15 and later, "permission denied for schema public" when creating a table needs GRANT CREATE ON SCHEMA public TO app_user;

Read the object type in the error

The error names the level that failed, which tells you which GRANT you need. The SQLSTATE is always 42501 (insufficient_privilege).

ErrorWhat is missingGrant
permission denied for table ordersThe action (SELECT, INSERT, UPDATE…) on that tableGRANT SELECT ON orders TO …
permission denied for schema publicCREATE on the schema (or USAGE on another schema)GRANT CREATE ON SCHEMA public TO …
permission denied for sequence orders_id_seqUSAGE on the sequence behind a serial columnGRANT USAGE ON SEQUENCE … TO …
must be owner of table ordersOwnership: ALTER, DROP and some others can't be grantedChange owner, or run as the owner

Check who you are connected as first. Apps often connect with a different role than the one you use in psql: SELECT current_user, session_user, current_database();

In VisuaLeaf

See a role's grants in VisuaLeaf

VisuaLeaf's SQL User Management shows grants without querying information_schema. Open User Management from the activity bar on your PostgreSQL connection:

  • If your own account can't manage users, the Dashboard shows an insufficient-privileges warning with your username, so you know to switch to an admin account first.
  • On the Users tab, expand a user to see its full grant list: the privilege, the schema.table it applies to, and whether it was granted WITH GRANT OPTION. Compare that list with the table above to see which privilege is missing.
  • On the Roles tab, expand a role to see its grants and members. Assign a role to a user from the Create or Edit User dialog.
VisuaLeaf SQL User Management Users tab with a search box, Create User button and a superuser row with edit, roles, lock and delete buttons
The Users tab: expand a row to see the grants for that user.

See the SQL User Management docs.

Cause 1: no privilege on the table

Creating a role doesn't give it access to anything. Each table needs an explicit grant for each kind of action:

GRANT SELECT, INSERT, UPDATE, DELETE ON orders TO app_user;

-- every existing table in a schema at once
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO app_user;

A role with only SELECT and INSERT gets the same error on its first UPDATE. \dp orders in psql shows what each role has. For read-only access to everything, PostgreSQL 14+ has the predefined role pg_read_all_data: GRANT pg_read_all_data TO analyst;

Cause 2: schema public on PostgreSQL 15 and later

ERROR:  permission denied for schema public
LINE 1: CREATE TABLE mine (id int);
                     ^

Up to PostgreSQL 14, every role could create tables in public. PostgreSQL 15 removed that default, so apps and migration tools that worked for years fail on a new server. Reading existing tables still works. Grant CREATE to the role that runs migrations, or make it the owner of the database:

-- connected to the app's database, not "postgres"
GRANT CREATE ON SCHEMA public TO app_user;

-- or
ALTER DATABASE myapp OWNER TO app_user;

The same error for any other schema, on a SELECT, means the role lacks USAGE on it: GRANT USAGE ON SCHEMA sales TO app_user;

Cause 3: the sequence behind a serial column

permission denied for sequence orders_id_seq surprises people because the table grant looks complete. An insert into a serial column calls nextval() on a separate sequence, which needs its own grant:

GRANT USAGE ON SEQUENCE orders_id_seq TO app_user;
GRANT USAGE ON ALL SEQUENCES IN SCHEMA public TO app_user;   -- or all of them

Identity columns (GENERATED ... AS IDENTITY) don't need a separate grant: INSERT on the table is enough.

Cause 4: tables created after the grant

GRANT ... ON ALL TABLES IN SCHEMA covers tables that exist right now. A table created by tomorrow's migration starts with no grants. Default privileges fix that for future objects:

ALTER DEFAULT PRIVILEGES IN SCHEMA public
  GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO app_user;
ALTER DEFAULT PRIVILEGES IN SCHEMA public
  GRANT USAGE ON SEQUENCES TO app_user;

Default privileges only apply to objects created by the role that ran the command. If migrations run as a different role, add FOR ROLE migrator after ALTER DEFAULT PRIVILEGES.

Cause 5: "must be owner of table"

ALTER TABLE, DROP TABLE, CREATE INDEX and a few others can't be granted. Only the owner (or a superuser) can run them. Change the owner, or make your role a member of the owning role:

ALTER TABLE orders OWNER TO app_user;
GRANT owner_role TO app_user;     -- or act as the current owner

The usual setup is one role that owns the tables and runs migrations, and a less privileged role the app uses at runtime.

What we found testing this

Each of these failed with permission denied for table for a role that had exactly the privilege you'd expect to be enough:

StatementPrivileges grantedResultWhy
UPDATE acct SET balance = 30 WHERE id = 1UPDATE (balance)DeniedThe WHERE reads id, which needs SELECT on it
UPDATE acct SET balance = 30UPDATE (balance)WorkedNothing is read
UPDATE ... RETURNING balanceUPDATE (balance)DeniedRETURNING needs SELECT
DELETE FROM logs WHERE id = 1DELETEDeniedThe WHERE needs SELECT; DELETE FROM logs worked
TRUNCATE logsDELETEDeniedTRUNCATE is its own privilege
INSERT ... ON CONFLICT DO UPDATEINSERT, SELECTDeniedNeeds UPDATE too; DO NOTHING worked
SELECT * FROM acctSELECT (id, balance)DeniedColumn grants don't cover *; SELECT id, balance worked
  • On a fresh PostgreSQL 16 database, \dn+ public shows the new owner. The schema is owned by pg_database_owner, with pg_database_owner=UC/pg_database_owner and =U/pg_database_owner: everyone gets USAGE, only the database owner gets CREATE. A fresh role got "permission denied for schema public" on CREATE TABLE, while the role named in CREATE DATABASE ... OWNER created tables without any grant. That's why ALTER DATABASE ... OWNER TO is a one-line fix.
  • node-postgres doesn't say which table. For this error, err.code is '42501' but err.table and err.schema are empty, unlike unique violations. The object name is only in err.message. psycopg raises psycopg.errors.InsufficientPrivilege (e.sqlstate), psycopg2 psycopg2.errors.InsufficientPrivilege (e.pgcode).

Frequently Asked Questions

Why do I get permission denied for schema public on a new database?

PostgreSQL 15 stopped letting every role create objects in the public schema. Only the database owner can by default. Grant CREATE ON SCHEMA public to your app role, or make it the database owner.

I granted UPDATE, so why does my UPDATE fail?

If the statement has a WHERE clause or RETURNING, the role also needs SELECT on the columns it reads. An UPDATE without WHERE needs only UPDATE.

I granted INSERT on the table, so why does the insert still fail?

If the table has a serial column, the role also needs USAGE on its sequence. If the insert uses ON CONFLICT DO UPDATE, it also needs UPDATE.

How do I give a user access to all tables, including future ones?

Use GRANT ... ON ALL TABLES IN SCHEMA for existing tables, plus ALTER DEFAULT PRIVILEGES IN SCHEMA for tables created later. For read-only access everywhere, grant pg_read_all_data (PostgreSQL 14+).

VisuaLeaf

Manage PostgreSQL tables without guessing names

VisuaLeaf shows every schema and table in one tree with exact names, includes table management for PostgreSQL, and runs your GRANT statements in a SQL editor with results you can read.