列relacl システムカタログのpg_class 特権に関するすべての情報が含まれています。
スキーマpublicのサンプルデータ postgresが所有 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;
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)
コメント:
-
coalesce(relacl::text[], format('{%s=arwdDxt/%s}', rolname, rolname))-relaclがヌル 所有者がすべての特権を持っていることを意味します。 -
unnest(...) acl-relaclaclitemの配列です 、ユーザー用の1つの配列要素; -
regexp_split_to_array(acl, '=|/') s-aclitemを分割します に:s [1]ユーザー名、s[2]特権; -
coalesce(nullif(s[1], ''), 'public') as grantee-空のユーザー名はpublicを意味します 。
クエリを変更して、個々のユーザー、特定の種類の関係、または別のスキーマなどを選択します...
ドキュメントを読む:
- カタログ
pg_class、 -
GRANTaclシステムの説明付き。
同様の方法で、スキーマに付与された特権に関する情報を取得できます(列 nspacl pg_namespace内
)およびデータベース( datacl pg_database内
)