Sloupec relacl systémového katalogu pg_class obsahuje všechny informace o oprávněních.
Příklad dat ve schématu public ve vlastnictví postgres s udělením oprávnění 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;
Dotaz na 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)
Komentáře:
coalesce(relacl::text[], format('{%s=arwdDxt/%s}', rolname, rolname))- Null vrelaclznamená, že vlastník má všechna oprávnění;unnest(...) acl-relaclje poleaclitem, jeden prvek pole pro uživatele;regexp_split_to_array(acl, '=|/') s- rozděleníaclitemdo:s[1] uživatelské jméno, s[2] oprávnění;coalesce(nullif(s[1], ''), 'public') as grantee- prázdné uživatelské jméno znamenápublic.
Upravte dotaz tak, abyste vybrali jednotlivého uživatele nebo konkrétní druh vztahu nebo jiná schémata atd...
Přečtěte si dokumentaci:
- Katalog
pg_class, GRANTs popisem systému acl.
Podobným způsobem můžete získat informace o oprávněních udělených pro schémata (sloupec nspacl v pg_namespace
) a databáze (datacl v pg_database
)