SQLSTATE 42501Severity mediumLab verified

Incident brief

Permission denied

A role tried to use a table it has not been granted privileges on. PostgreSQL denied the action instead of falling back to the owner's or a broader role's access.

What lands in your log

ERROR: permission denied for table secrets

Reproduced on PostgreSQL 16.14Verified 2026-07-15 (Docker lab, PostgreSQL 16.14)Verified against PostgreSQL 16.14 in an isolated lab environment

In 10 seconds

What triggers it
Create a table as its owner, then switch to a role with no privileges granted on it.
Fix
GRANT the specific privilege (e.g. SELECT) on the table to the role that needs it.
Proof
Reproduced on PostgreSQL 16.14 → A role with no privileges on a table was rejected with SQLSTATE 42501 when it tried to SELECT from it. The table's data was confirmed unaffected afterward.

Fix

What to do right now

Application-level steps for this error.

  • GRANT the specific privilege (e.g. SELECT) on the table to the role that needs it.
  • Grant only what's needed, column-level GRANTs are available if a role should see some columns but not others.
  • Don't assume ALTER DEFAULT PRIVILEGES retroactively fixes access to existing tables, see the premium test for its actual scope.
Fix SQL
GRANT SELECT ON vault.secrets TO analyst;

Connected

Everything this error touches

Every page this SQLSTATE connects to: the concept that explains it, the runbooks that fix it, the parameters you tune to prevent it, and the sibling errors it travels with. All real cross-references. Jump straight in, or open the full interactive map.

Open in the interactive map →

Verification

PG 16.14
Last verified
2026-07-15 (Docker lab, PostgreSQL 16.14)
Verification scope
Verified against PostgreSQL 16.14 in an isolated lab environment
Audit status
reviewed
ShareLinkedInX

Went further?

Pro unlocks the second lab proof

Free page stops the bleeding. Pro adds the operational test, SQLSTATE audit, and deeper evidence, same error, more certainty.

FollowSubstackLinkedInnew errors · lab notes · hiring loops