-bash-4.2$ psql t -E
psql (9.3.14)
Type "help" for help.
t=# \dp+ schema_name.*
********* QUERY **********
SELECT n.nspname as "Schema",
c.relname as "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'S' THEN 'sequence' WHEN 'f' THEN 'foreign table' END as "Type",
pg_catalog.array_to_string(c.relacl, E'\n') AS "Access privileges",
pg_catalog.array_to_string(ARRAY(
SELECT attname || E':\n ' || pg_catalog.array_to_string(attacl, E'\n ')
FROM pg_catalog.pg_attribute a
WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL
), E'\n') AS "Column access privileges"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r', 'v', 'm', 'S', 'f')
AND n.nspname ~ '^(schema_name)$'
ORDER BY 1, 2;
**************************
したがって、クエリに同じロジックを使用できます。たとえばf
、スキーマ内のユーザーの特権を一覧表示するにはschema_name
:
with l as (select relname,unnest(relacl) from pg_class c join pg_catalog.pg_namespace n ON n.oid = c.relnamespace where nspname = 'schema_name')
select * from l where unnest::text like 'f=%';
relname | unnest
-----------------------------------------------------+--------------
a_b | f=r/postgres
b_c | f=r/postgres