Learning center

Verify whether a PostgreSQL role inherits a granted privilege

In PostgreSQL 16 and newer, check the membership's INHERIT and SET options when membership exists but the login role cannot use a privilege immediately. They answer different questions about how privileges can become effective.

In a fictional reporting database, report_job is a member of report_reader. The reader owns an approved read grant, but the job fails without a role switch. An authorized reader can use pg_has_role to check both properties from the existing session.

SELECT pg_has_role('report_job', 'report_reader', 'USAGE') AS inherits_now,
       pg_has_role('report_job', 'report_reader', 'SET') AS can_set_role;

If the result is false and true, the job can switch to the reader but does not have its privileges immediately. Inspect the intended session setup and membership options before adding a direct table grant. If both are false, read the membership chain for the relevant options. Keep the server version with the incident receipt because earlier PostgreSQL versions represent inheritance differently. Role membership and inheritance ยท pg_has_role

Trace another denied request.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading