启用角色

当您在会话中启用角色时,将获得分配给该角色的所有权限。您可以同时启用多个角色,从而获得这些角色的所有权限,以及已经直接授予您的任何权限。

默认情况下,对于用户,仅自动启用预定义角色。否则,在启动会话时,您必须使用 Vertica 函数 SET ROLE 显式启用分配的角色

例如,dbadmin 创建 logreader 角色并将其分配给用户 alice

=> \c
You are now connected as user "dbadmin".
=> CREATE ROLE logreader;
CREATE ROLE
=> GRANT SELECT ON TABLE applog to logreader;
GRANT PRIVILEGE
=> GRANT logreader TO alice;
GRANT ROLE

用户 alice 必须启用新角色才能查看 applog 表:


=> \c - alice
You are now connected as user "alice".
=> SELECT * FROM applog;
ERROR:  permission denied for relation applog
=> SET ROLE logreader;
SET
=> SELECT * FROM applog;
 id | sourceID |            data            |                    event
----+----------+----------------------------+----------------------------------------------
  1 | Loader   | 2011-03-31 11:00:38.494226 | Error: Failed to open source file
  2 | Reporter | 2011-03-31 11:00:38.494226 | Warning: Low disk space on volume /scratch-a
(2 rows)

启用所有用户角色

您可以使用 SET ROLE ALL 启用对您的用户帐户可用的所有角色:

=> SET ROLE ALL;
SET
=> SHOW ENABLED_ROLES;
     name      |           setting
---------------+------------------------------
 enabled roles | logreader, logwriter
(1 row)

禁用角色

用户可以使用 SET ROLE NONE 禁用所有角色。此语句禁用当前会话的除预定义角色以外的所有其他角色:

=> SET ROLE NONE;
=> SHOW ENABLED_ROLES;
     name      | setting
---------------+---------
 enabled roles |
(1 row)