查询 postgres 中表的授权
如何查询 postgres 中授予某个对象的所有 GRANTS?
例如,我有表“mytable”:
GRANT SELECT, INSERT ON mytable TO user1
GRANT UPDATE ON mytable TO user2
我需要一些可以给我的东西:
user1: SELECT, INSERT
user2: UPDATE
How can I query all GRANTS granted to an object in postgres?
For example I have table "mytable":
GRANT SELECT, INSERT ON mytable TO user1
GRANT UPDATE ON mytable TO user2
I need somthing which gives me:
user1: SELECT, INSERT
user2: UPDATE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我已经找到了:
I already found it:
psql 中的
\z mytable
为您提供表中的所有授权,但您必须将其按单个用户拆分。\z mytable
from psql gives you all the grants from a table, but you'd then have to split it up by individual user.下面的查询将为您提供所有用户及其对架构中表的权限的列表。
有关
has_table_privilages
的更多详细信息,请访问此处 。The query below will give you a list of all users and their permissions on the table in a schema.
More details on
has_table_privilages
can be found here.如果您确实希望每个用户一行,您可以按受让人分组(string_agg 需要 PG9+)
这应该输出类似以下内容的内容:
If you really want one line per user, you can group by grantee (require PG9+ for string_agg)
This should output something like :
此查询将列出所有数据库和架构中的所有表(取消注释
WHERE
子句中的行以过滤特定数据库、架构或表),其权限如下所示以便很容易地查看是否授予了特定权限:示例输出:
This query will list all of the tables in all of the databases and schemas (uncomment the line(s) in the
WHERE
clause to filter for specific databases, schemas, or tables), with the privileges shown in order so that it's easy to see if a specific privilege is granted or not:Sample output:
添加@shruti的答案
查询给定用户模式中所有表的授权
Adding on to @shruti's answer
To query grants for all tables in a schema for a given user
这是一个为特定表生成授权查询的脚本。它忽略了所有者的特权。
如果您想获取视图,请执行以下声明:
Here is a script which generates grant queries for a particular table. It omits owner's privileges.
Here the statement if you want to get it for views: