暂无图片
暂无图片
暂无图片
暂无图片
暂无图片
PG查看用户拥有的各类对象的操作权限.pdf
76
12页
0次
2024-05-06
10墨值下载
PostgreSQL数据库平时会赋予很多的权限,对于这些权限是否真正赋予,并且对于各个对象,用户到
底有着什么权限,有着不同的方式去验证,例如\dp+ , 查询视图,查询函数,或者使用extenson
PG_PERMISSIONS)等
一、元命令(\dp+)
通常可以使用\dp+ 列出用户,schema的默认权限。列出表、视图、序列的权限,但是它读起来比较不太方
便。
postgres=# \dp+
                     Access privileges
Schema |      Name      |  Type  |  Access privileges  | Column
privileges | Policies
--------+--------------------------+----------+-------------------------+--------
-----------+----------
public | a1            | view   | xmaster=arwdDxt/xmaster+|    
     |
   |             |     | chpt=r/xmaster     |    
     |
public | all_permissions     | view   | xmaster=arwdDxt/xmaster+|    
     |
   |             |     | =r/xmaster       |    
     |
public | column_permissions    | view   | xmaster=arwdDxt/xmaster+|    
     |
   |             |     | =r/xmaster       |    
     |
public | database_permissions   | view   | xmaster=arwdDxt/xmaster+|    
     |
   |             |     | =r/xmaster       |    
     |
public | demotable1        | table  | xmaster=arwdDxt/xmaster+|    
     |
   |             |     | chpt=r/xmaster     |    
     |
public | dual           | view   | xmaster=arwdDxt/xmaster+|    
     |
   |             |     | chpt=r/xmaster     |    
     |
public | factdns60        | table  | xmaster=arwdDxt/xmaster+|    
     |
   |             |     | chpt=r/xmaster     |    
     |
public | function_permissions   | view   | xmaster=arwdDxt/xmaster+|    
     |
   |             |     | =r/xmaster       |    
     |
public | heaptest         | table  | xmaster=arwdDxt/xmaster+|    
     |
   |             |     | chpt=r/xmaster     |    
     |
public | l1            | table  | xmaster=arwdDxt/xmaster+|    
    
二、查询视图
PostgreSQL里,对于一些创建用户、创建数据库、登陆、replication等权限,可以查询pg_roles去查
看。
而在PostgreSQL数据库里,也有着类似于MySQL数据库的information_schema
Information_schema自动的存在于每个database中,里面包含了数据库中所有对象的定义信息。
Information_schema默认不存在于任何用户的search_path中,所以对所有用户都是隐藏的,\dn看不
到。
Information_schema下有着几个x x x.privileges的视图,其中包含了一些对象的权限。包含用户在某
列的权限,能够访问的数据类型,存储过程函数的执行权限,表的权限,自定义类型上授予的USAGE
限,某用户的usage权限。
下边拿比较常用的表权限举例
表的权限
PostgreSQL数据库中, information_schema.role_table_grants
information_schema.table_privileges 是用来描述表的权限信息的两个系统表。
information_schema.role_table_grants 表列出了授权给角色的表级别权限信息,包括授权角
色、被授权表、授权类型(SELECTINSERTUPDATEDELETETRUNCATE
REFERENCES)、授权是否可授予别人、授权者、授权时间等。
information_schema.table_privileges 表列出了表的权限信息,包括授权者、被授权表、授
权角色、授权类型、授权是否可授予别人、授权时间等。
可以看出,这两个系统表都包含了关于表的权限信息,但是它们的数据来源略有不同。
在想获取一个用户对于一张表的权限的时候,我们可以通过元数据视图
information_schema.table_privileges
其实查看 information_schema.role_table_grants这个视图的结果也是大致相同的
of 12
10墨值下载
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文档的来源(墨天轮),文档链接,文档作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

关注
最新上传
暂无内容,敬请期待...
下载排行榜
Top250 周榜 月榜