Skip to main content

SQLSTATE 42501: permission denied for table

SQLSTATE 42501

PostgreSQL refused the statement because the role running it doesn't hold the privilege the statement needs on that table, such as SELECT, INSERT, UPDATE or DELETE.

From PostgreSQL's documentation, checked 21 Nov 2026.

PostgreSQL privileges (GRANT and REVOKE)AuthorisationWarning
Error text as PostgreSQL documents it
ERROR: permission denied for table <table_name>

Also searched as: insufficient_privilege · permission denied for table · postgres permission denied for table · 42501 insufficient privilege

What it means

Every table has an owner, normally the role that created it, and at first only the owner or a superuser can do anything with it. PostgreSQL grants nothing to PUBLIC on tables by default, so every other role needs an explicit GRANT for each kind of access. When a statement needs a privilege the current role doesn't hold, the statement fails with SQLSTATE 42501 (insufficient_privilege).

Common causes

  • The table was created by another role and nobody granted the current role the privilege the statement needs.
  • The role holds the privilege on only some columns, and the statement reads or writes others, for example SELECT * or TABLE against a table where SELECT was granted on named columns only.
  • The statement needs a second privilege as well: an UPDATE or DELETE that refers to column values also needs SELECT.
  • The table was created after the grants were made, and no ALTER DEFAULT PRIVILEGES rule gives the role access to new tables made by the table's creator.

From PostgreSQL's documentation

How to fix it

  1. Check which role is running the statement

    Run this in the same session that got the error. The privilege has to be held by this role, directly or through a role it inherits from.

    SELECT current_user;
  2. Ask PostgreSQL whether that role holds the privilege

    Put in the role, the table (schema-qualified if it isn't on the search path) and the privilege the statement needs. psql's \dp shows every grant on the table, including column privileges. To reach a table in a schema it doesn't own, the role also needs USAGE on that schema.

    SELECT has_table_privilege('<role>', '<schema>.<table>', 'SELECT');
    SELECT has_schema_privilege('<role>', '<schema>', 'USAGE');
    \dp <schema>.<table>
  3. Grant the privilege, as the table owner

    Normally only the owner (or a superuser) can grant privileges on a table. Grant only what the role needs. GRANT changes tables that already exist; ALTER DEFAULT PRIVILEGES sets the privileges for tables created later by the role that runs it, or by the role named with FOR ROLE, and doesn't change existing ones.

    GRANT USAGE ON SCHEMA <schema> TO <role>;
    GRANT SELECT, INSERT, UPDATE, DELETE ON <schema>.<table> TO <role>;
    ALTER DEFAULT PRIVILEGES IN SCHEMA <schema> GRANT SELECT ON TABLES TO <role>;

How to confirm it's fixed

  • has_table_privilege returns true for the role, table and privilege the statement needs.
  • \dp <schema>.<table> lists the role in Access privileges with the letters for the granted privileges (r for SELECT, a for INSERT, w for UPDATE, d for DELETE).
  • The statement that failed now runs as the same role without the permission error.

Related notes

Table privileges are separate from row security. With row-level security enabled, a role that holds the privilege may still see or change no rows unless a policy allows them, and that doesn't raise this error. Granting on a table doesn't extend to sequences it uses, such as those behind SERIAL columns: they need their own GRANT.

Copyable operational controls

Related engineering templates

Continue the investigation

The KBY Brief

Follow PostgreSQL failures and fixes

A short email about twice a week with new runbooks, configuration traps and fixes from KBY Technologies.