Re: catalog views to check on grants - Mailing list pgsql-admin

From Juan José Santamaría Flecha
Subject Re: catalog views to check on grants
Date
Msg-id CAC+AXB1KNGHMuWs2-FOLjkSxacG=OmCsODDqA1Aomv2s=odenA@mail.gmail.com
Whole thread Raw
In response to catalog views to check on grants  (Ankush Chawla <ankushchawla03@gmail.com>)
Responses Re: catalog views to check on grants
List pgsql-admin

On Thu, Apr 16, 2020 at 2:11 PM Ankush Chawla <ankushchawla03@gmail.com> wrote:

Please share the dictionary tables to view the grants on objects, system and object privileges etc.

Different objects have a different set of privileges, and there is not a single view for then all. You can check the system catalogs [1] for a specific object and check its privileges as an aclitem[] [2], e.g. for relations you can check pg_class grants using a query like so:

select relname,
       (select rolname from pg_roles where oid = grantor) as grantor,
       (select rolname from pg_roles where oid = grantee) as grantee,
       privilege_type,
       is_grantable
from (select relname,
       (aclexplode(relacl)).grantor,
       (aclexplode(relacl)).grantee,
       (aclexplode(relacl)).privilege_type,
       (aclexplode(relacl)).is_grantable
  from pg_class
  where relacl is not null) as pg_class_privs;

[1] https://www.postgresql.org/docs/current/catalogs.html
[2] https://www.postgresql.org/docs/current/ddl-priv.html#PRIVILEGE-ABBREVS-TABLE

Regards,

Juan José Santamaría Flecha

pgsql-admin by date:

Previous
From: Ankush Chawla
Date:
Subject: catalog views to check on grants
Next
From: Brandon Hsu
Date:
Subject: Re: pgAdmin4 dependency package "python3-psycopg2" should be place in"pgdg-common" repo.