检查用户的Postgres访问权限

80

我查看了这里找到的 GRANT 文档,并试图查看是否有内置函数可以让我查看我在数据库中具有的访问级别。当然是有的:

\dp\dp mytablename

但这不显示我的账户有哪些访问权限。我想看到我可以访问的所有表格。请问是否有可以检查我在Postgres中的访问级别(是否具有SELECT, INSERT, DELETE, UPDATE 权限)的命令?如果有,那么该命令是什么?


2
你可以输入\du命令来查询授权信息,或者直接查询information_schema中的grants表。 - Marc B
3个回答

147

您可以在信息模式中查询table_privileges表:

SELECT table_catalog, table_schema, table_name, privilege_type
FROM   information_schema.table_privileges 
WHERE  grantee = 'MY_USER'

8
您只能看到您的数据库用户被授权查看的行。 - HeyWatchThis
它仍然没有告诉我使用者是否为管理员? - N. Raj

5
针对特定数据库的所有用户,执行以下操作:
# psql
\c your_database
select grantee, table_catalog, privilege_type, table_schema, table_name from information_schema.table_privileges order by grantee, table_schema, table_name;

5
使用此功能列出Grantee列表,并在Postgres PaaS Azure中删除(PG_monitor和Public)。
SELECT grantee,table_catalog, table_schema, table_name, privilege_type
FROM   information_schema.table_privileges 
WHERE  grantee not in ('pg_monitor','PUBLIC');

只有这个命令对我有效,因为它显示了角色权限。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接