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>