FluentDBFluentDB
PostgreSQL errors

PostgreSQL: permission denied for table

ERRORSQLSTATE 42501insufficient_privilege
ERROR: permission denied for table <name>

Your role can connect but is not allowed to perform this action on the table. Grant the needed privilege to the role. To stop it recurring on tables created later, set default privileges for the schema.

What this error means

Table privileges (SELECT, INSERT, UPDATE, DELETE, and more) are granted per role. If your role was never granted the privilege it is trying to use, Postgres blocks the statement with this error.

A common surprise: granting privileges on today's tables does nothing for tables created tomorrow. New tables start with no grants unless you set default privileges.

How to fix it

01

The role lacks privileges on the table

Grant the specific privileges the role needs.

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

You want to cover every existing table in a schema

Grant on all current tables in one statement.

sql
GRANT SELECT, INSERT, UPDATE, DELETE
ON ALL TABLES IN SCHEMA public TO app_user;
03

New tables keep losing access

Set default privileges so tables created later automatically grant to the role.

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

How to avoid it next time

  • Manage grants through roles: grant to a group role, then hand that role to users.
  • Set ALTER DEFAULT PRIVILEGES once per schema so new tables are covered automatically.

Frequently asked questions

Why can I read some tables but not others?

Privileges are per table. Tables created after your last GRANT have no grants unless you set default privileges for the schema.

Do I also need schema access?

Yes. A role needs USAGE on the schema in addition to table privileges. Missing schema access raises 'permission denied for schema'.

Stop struggling with SQL

Use FluentDB, the AI database client for macOS.