1. 程式人生 > >postgresql 9.6 的預設角色

postgresql 9.6 的預設角色

os: centos 7.4
db: postgresql 9.6

postgresql 使用角色的概念管理資料庫訪問許可權
一個角色可以被看成是一個數據庫使用者或者是一個數據庫使用者組,這取決於角色被怎樣設定。
角色可以擁有資料庫物件(例如,表和函式)並且能夠把那些物件上的許可權賦予給其他角色來控制誰能訪問哪些物件。此外,還可以把一個角色中的成員資格授予給另一個角色,這樣允許成員角色使用被賦予給另一個角色的許可權。

角色的概念把"使用者"和""的概念都包括在內。

預設角色

postgres=# select * from pg_roles order by rolname;
      rolname      | rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcanlogin | rolreplication | rolconnlimit | rolpassword | rolvaliduntil | rolbypassrls | rolconfig | oid  
-------------------+----------+------------+---------------+-------------+-------------+----------------+--------------+-------------+---------------+--------------+-----------+------
 pg_signal_backend | f        | t          | f             | f           | f           | f              |           -1 | ********    |               | f            |           | 4200
 postgres          | t        | t          | t             | t           | t           | t              |           -1 | ********    |               | t            |           |   10
(2 rows)

postgres 這個角色的 rolcanlogin 為 true,說明已經是可以登入的使用者,且是超級使用者。

pg_signal_backend 這個角色表示可以給其他後端傳送訊號(比如: 取消查詢、終止)。

9.6 的預設角色還比較少,在許可權分離這塊還不是特別清晰。
10、11在資料庫的許可權分離上已經逐漸清晰了。

授予預設角色

建立使用者
postgresq 的使用者就等於具有登入許可權的角色。

postgres=# create role peiyb with login password 'peiybpeiyb';
CREATE ROLE
postgres=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 peiyb     |                                                            | {}
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

授予 pg_signal_backend 角色

postgres=# grant pg_signal_backend to peiyb;
GRANT ROLE
postgres=# \du
                                        List of roles
 Role name |                         Attributes                         |      Member of      
-----------+------------------------------------------------------------+---------------------
 peiyb     |                                                            | {pg_signal_backend}
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

postgres=# 

通過 Member of 可以看到已經具有 pg_signal_backend 許可權。

參考:
http://postgres.cn/docs/9.6/user-manag.html