显示postgres组架构权限

问题描述 投票:0回答:1

我在postgres实例上执行了以下操作:

create group dev;
grant select on all tables in schema public to dev;

我要做的就是查询视图/表以查找此授权。我试过看像information_schema.table_privileges这样的观点但看不到它。有人可以指点我正确的方向吗?

附:这需要是一个查询视图,因为我从python脚本运行它,而不是psql。

编辑:PostgreSQL版本10.0

python sql postgresql psql postgresql-10
1个回答
0
投票
-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的privs:

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
© www.soinside.com 2019 - 2024. All rights reserved.