La colonna relacl del catalogo di sistema pg_class contiene tutte le informazioni sui privilegi.
Dati di esempio nello schema public di proprietà di postgres con sovvenzioni a newuser :
create table test(id int);
create view test_view as select * from test;
grant select, insert, update on test to newuser;
grant select on test_view to newuser;
Interrogazione di pg_class :
select
relname,
relkind,
coalesce(nullif(s[1], ''), 'public') as grantee,
s[2] as privileges
from
pg_class c
join pg_namespace n on n.oid = relnamespace
join pg_roles r on r.oid = relowner,
unnest(coalesce(relacl::text[], format('{%s=arwdDxt/%s}', rolname, rolname)::text[])) acl,
regexp_split_to_array(acl, '=|/') s
where nspname = 'public'
and relname like 'test%';
relname | relkind | grantee | privileges
-----------+---------+----------+------------
test | r | postgres | arwdDxt <- owner postgres has all privileges on the table
test | r | newuser | arw <- newuser has append/read/write privileges
test_view | v | postgres | arwdDxt <- owner postgres has all privileges on the view
test_view | v | newuser | r <- newuser has read privilege
(4 rows)
Commenti:
coalesce(relacl::text[], format('{%s=arwdDxt/%s}', rolname, rolname))- Null inrelaclsignifica che il proprietario ha tutti i privilegi;unnest(...) acl-relaclè un array diaclitem, un elemento dell'array per un utente;regexp_split_to_array(acl, '=|/') s- dividereaclitemin:s[1] nome utente, s[2] privilegi;coalesce(nullif(s[1], ''), 'public') as grantee- nome utente vuoto significapublic.
Modifica la query per selezionare un singolo utente o un tipo specifico di relazione o un altro schema, ecc...
Leggi nella documentazione:
- Il catalogo
pg_class, GRANTcon la descrizione del sistema acl.
In modo simile puoi ottenere informazioni sui privilegi concessi sugli schemi (la colonna nspacl in pg_namespace
) e database (datacl in pg_database
)