postgresql , pg_class.relacl , pg_attribute.attacl
如何查看数据库中的表的相应权限,已经赋予给哪些用户了。
另外,postgresql还可以针对列进行赋权,还可以适应行安全策略,所以如何查看某张表的某些列的相应权限被赋予给哪些用户了。
还有其他的对象,如视图、函数、语言等,他们的权限被赋予给哪些数据库用户了呢?
这些通过psql \dp很容易实现,但是它又是怎么获取的呢?
使用psql -e选项,可以将psql的内部操作也打印出来,这样就能得到\dp都干了什么了?
通过这个query我们可以了解到权限是如何获取的
1. 对象权限,获取自pg_class.relacl,注意它只包含了在pg_class的对象(这里只有表、视图、序列、索引、物化视图、复合类型、toast表、外部表)
<a href="https://www.postgresql.org/docs/9.6/static/catalog-pg-class.html">https://www.postgresql.org/docs/9.6/static/catalog-pg-class.html</a>
name
type
references
description
relpersistence
char
-
p = permanent table, u = unlogged table, t = temporary table
relkind
r = ordinary table, i = index, s = sequence, v = view, m = materialized view, c = composite type, t = toast table, f = foreign table
relacl
aclitem[]
access privileges; see grant and revoke for details
那么函数、类型、语言、数据库、表空间等的权限在哪里呢?
它们在对应的系统视图中
比如
1.1 pg_class.relacl的解读
<a href="https://www.postgresql.org/docs/9.6/static/sql-grant.html">https://www.postgresql.org/docs/9.6/static/sql-grant.html</a>
2. 列权限,来自pg_attribute.attacl,如下
<a href="https://www.postgresql.org/docs/9.6/static/catalog-pg-attribute.html">https://www.postgresql.org/docs/9.6/static/catalog-pg-attribute.html</a>
pg_attribute
attacl
column-level access privileges, if any have been granted specifically on this column
3. 行安全策略,来自pg_policy
<a href="https://github.com/digoal/blog/blob/master/201605/20160510_01.md">《postgresql 逻辑结构 和 权限体系 介绍》</a>
<a href="https://github.com/digoal/blog/blob/master/201611/20161114_02.md">《用好postgresql role membership来管理继承组权限》</a>
<a href="https://github.com/digoal/blog/blob/master/201612/20161207_01.md">《postgresql 从源码找出哪些操作需要超级用户权限》</a>