<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenText Analytics Database 26.2.x – Database roles</title>
    <link>/en/admin/db-users-and-privileges/db-roles/</link>
    <description>Recent content in Database roles on OpenText Analytics Database 26.2.x</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/admin/db-users-and-privileges/db-roles/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Admin: Predefined database roles</title>
      <link>/en/admin/db-users-and-privileges/db-roles/predefined-db-roles/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/db-users-and-privileges/db-roles/predefined-db-roles/</guid>
      <description>
        
        
        &lt;p&gt;OpenText™ Analytics Database has the following predefined roles:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-roles/predefined-db-roles/dbadmin/&#34;&gt;DBADMIN&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-roles/predefined-db-roles/pseudosuperuser/&#34;&gt;PSEUDOSUPERUSER&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-roles/predefined-db-roles/dbduser/&#34;&gt;DBDUSER&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-roles/predefined-db-roles/sysmonitor/&#34;&gt;SYSMONITOR&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-roles/predefined-db-roles/udxdeveloper/&#34;&gt;UDXDEVELOPER&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-roles/predefined-db-roles/mlsupervisor/&#34;&gt;MLSUPERVISOR&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-roles/predefined-db-roles/public/&#34;&gt;PUBLIC&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;automatic-role-grants&#34;&gt;Automatic role grants&lt;/h2&gt;
&lt;p&gt;On installation, the database automatically grants and enables predefined roles as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The DBADMIN, PSEUDOSUPERUSER, and DBDUSER roles are irrevocably granted to the &lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-users/types-of-db-users/db-admin-user/&#34;&gt;dbadmin user&lt;/a&gt;. These roles are always enabled for &lt;code&gt;dbadmin&lt;/code&gt;, and can never be dropped.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;PUBLIC is granted to &lt;code&gt;dbadmin&lt;/code&gt;, and to all other users as they are created. This role is always enabled and cannot be dropped or revoked.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;granting-predefined-roles&#34;&gt;Granting predefined roles&lt;/h2&gt;
&lt;p&gt;After installation, the &lt;code&gt;dbadmin&lt;/code&gt; user and users with the PSEUDOSUPERUSER role can grant one or more predefined roles to any user or non-predefined role. For example, the following set of statements creates the &lt;code&gt;userdba&lt;/code&gt; role and grants it the predefined role DBADMIN:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE ROLE userdba;
CREATE ROLE
=&amp;gt; GRANT DBADMIN TO userdba WITH ADMIN OPTION;
GRANT ROLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Users and roles that are granted a predefined role can extend that role to other users, if the original &lt;a href=&#34;../../../../en/sql-reference/statements/grant-statements/grant-role/#&#34;&gt;GRANT (Role)&lt;/a&gt; statement includes WITH ADMIN OPTION. One exception applies: if you grant a user the PSEUDOSUPERUSER role and omit WITH ADMIN OPTION, the grantee can grant any role, including all predefined roles, to other users.&lt;/p&gt;
&lt;p&gt;For example, the &lt;code&gt;userdba&lt;/code&gt; role was previously granted the DBADMIN role. Because the GRANT statement includes WITH ADMIN OPTION, users who are assigned the &lt;code&gt;userdba&lt;/code&gt; role can grant the DBADMIN role to other users:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; GRANT userdba TO fred;
GRANT ROLE
=&amp;gt; \c - fred
You are now connected as user &amp;#34;fred&amp;#34;.
=&amp;gt; SET ROLE userdba;
SET
=&amp;gt; GRANT dbadmin TO alice;
GRANT ROLE
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;modifying-predefined-rolesbr-&#34;&gt;Modifying predefined Roles&lt;br /&gt;&lt;/h2&gt;
&lt;p&gt;Excluding SYSMONITOR, you can grant predefined roles privileges on individual database objects, such as tables or schemas. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE SCHEMA s1;
CREATE SCHEMA
=&amp;gt; GRANT ALL ON SCHEMA s1 to PUBLIC;
GRANT PRIVILEGE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can grant PUBLIC any role, including predefined roles. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; CREATE ROLE r1;
CREATE ROLE
=&amp;gt; GRANT r1 TO PUBLIC;
GRANT ROLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You cannot modify any other predefined role by granting another role to it. Attempts to do so return a rollback error:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE ROLE r2;
CREATE ROLE
=&amp;gt; GRANT r2 TO PSEUDOSUPERUSER;
ROLLBACK 2347:  Cannot alter predefined role &amp;#34;pseudosuperuser&amp;#34;
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Admin: Role hierarchy</title>
      <link>/en/admin/db-users-and-privileges/db-roles/role-hierarchy/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/db-users-and-privileges/db-roles/role-hierarchy/</guid>
      <description>
        
        
        &lt;p&gt;By granting roles to other roles, you can build a hierarchy of roles, where roles lower in the hierarchy have a narrow range of privileges, while roles higher in the hierarchy are granted combinations of roles and their privileges. When you organize roles hierarchically, any privileges that you add to lower-level roles are automatically propagated to the roles above them.&lt;/p&gt;
&lt;h2 id=&#34;creating-hierarchical-roles&#34;&gt;Creating hierarchical roles&lt;/h2&gt;
&lt;p&gt;The following example creates two roles, assigns them privileges, then assigns both roles to another role.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create table &lt;code&gt;applog&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE applog (id int, sourceID VARCHAR(32), data TIMESTAMP, event VARCHAR(256));
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create the &lt;code&gt;logreader&lt;/code&gt; role and grant it read-only privileges on table &lt;code&gt;applog&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE ROLE logreader;
CREATE ROLE
=&amp;gt; GRANT SELECT ON applog TO logreader;
GRANT PRIVILEGE
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create the &lt;code&gt;logwriter&lt;/code&gt; role and grant it write privileges on table &lt;code&gt;applog&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE ROLE logwriter;
CREATE ROLE
=&amp;gt; GRANT INSERT, UPDATE ON applog to logwriter;
GRANT PRIVILEGE
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create the &lt;code&gt;logadmin&lt;/code&gt; role and grant it DELETE privilege on table &lt;code&gt;applog&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE ROLE logadmin;
CREATE ROLE
=&amp;gt; GRANT DELETE ON applog to logadmin;
GRANT PRIVILEGE
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Grant the &lt;code&gt;logreader&lt;/code&gt; and &lt;code&gt;logwriter&lt;/code&gt; roles to role &lt;code&gt;logadmin&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; GRANT logreader, logwriter TO logadmin;
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create user &lt;code&gt;bob&lt;/code&gt; and grant him the &lt;code&gt;logadmin&lt;/code&gt; role:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE USER bob;
CREATE USER
=&amp;gt; GRANT logadmin TO bob;
GRANT PRIVILEGE
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Modify user &lt;code&gt;bob&lt;/code&gt;&#39;s account so his &lt;code&gt;logadmin&lt;/code&gt; role is &lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-roles/enabling-roles-automatically/&#34;&gt;automatically enabled&lt;/a&gt; on login:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; ALTER USER bob DEFAULT ROLE logadmin;
ALTER USER
=&amp;gt; \c - bob
You are now connected as user &amp;#34;bob&amp;#34;.
=&amp;gt; SHOW ENABLED_ROLES;
     name      | setting
---------------+----------
 enabled roles | logadmin
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;enabling-hierarchical-roles&#34;&gt;Enabling hierarchical roles&lt;/h2&gt;
&lt;p&gt;Only roles that are explicitly granted to a user can be enabled for that user. In the previous example, roles &lt;code&gt;logreader&lt;/code&gt; or &lt;code&gt;logwriter&lt;/code&gt; cannot be enabled for &lt;code&gt;bob&lt;/code&gt;. They can only be enabled indirectly, by enabling &lt;code&gt;logadmin&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;hierarchical-role-grants-and-with-admin-option&#34;&gt;Hierarchical role grants and WITH ADMIN OPTION&lt;/h2&gt;
&lt;p&gt;If one or more roles are granted to another role using &lt;code&gt;WITH ADMIN OPTION&lt;/code&gt;, then users who are granted the &#39;higher&#39; role inherit administrative access to the subordinate roles.&lt;/p&gt;
&lt;p&gt;For example, you might modify the earlier grants of roles &lt;code&gt;logreader&lt;/code&gt; and &lt;code&gt;logwriter&lt;/code&gt; to &lt;code&gt;logadmin&lt;/code&gt; as follows:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; GRANT logreader, logwriter TO logadmin WITH ADMIN OPTION;
NOTICE 4617:  Role &amp;#34;logreader&amp;#34; was already granted to role &amp;#34;logadmin&amp;#34;
NOTICE 4617:  Role &amp;#34;logwriter&amp;#34; was already granted to role &amp;#34;logadmin&amp;#34;
GRANT ROLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;User &lt;code&gt;bob&lt;/code&gt; , through his &lt;code&gt;logadmin&lt;/code&gt; role, is now authorized to grant its two subordinate roles to other users—in this case, role &lt;code&gt;logreader&lt;/code&gt; to user &lt;code&gt;Alice&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; \c - bob;
You are now connected as user &amp;#34;bob&amp;#34;.
=&amp;gt; GRANT logreader TO Alice;
GRANT ROLE
=&amp;gt; \c - alice;
You are now connected as user &amp;#34;alice&amp;#34;.
=&amp;gt; show available_roles;
      name       |  setting
-----------------+-----------
 available roles | logreader
(1 row)
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

&lt;p&gt;Because the grant of the &lt;code&gt;logadmin&lt;/code&gt; role to &lt;code&gt;bob&lt;/code&gt; did not include &lt;code&gt;WITH ADMIN OPTION&lt;/code&gt;, he cannot grant that role to &lt;code&gt;alice&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; \c - bob;
You are now connected as user &amp;#34;bob&amp;#34;.
=&amp;gt; GRANT logadmin TO alice;
ROLLBACK 4925:  The role &amp;#34;logadmin&amp;#34; cannot be granted to &amp;#34;alice&amp;#34;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

      </description>
    </item>
    
    <item>
      <title>Admin: Creating and dropping roles</title>
      <link>/en/admin/db-users-and-privileges/db-roles/creating-and-dropping-roles/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/db-users-and-privileges/db-roles/creating-and-dropping-roles/</guid>
      <description>
        
        
        &lt;p&gt;As a superuser with the 
&lt;code&gt;&lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-roles/predefined-db-roles/dbadmin/#&#34;&gt;DBADMIN&lt;/a&gt;&lt;/code&gt; or 
&lt;code&gt;&lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-roles/predefined-db-roles/pseudosuperuser/#&#34;&gt;PSEUDOSUPERUSER&lt;/a&gt;&lt;/code&gt; role, you can create and drop roles with 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/create-statements/create-role/#&#34;&gt;CREATE ROLE&lt;/a&gt;&lt;/code&gt; and 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/drop-statements/drop-role/#&#34;&gt;DROP ROLE&lt;/a&gt;&lt;/code&gt;, respectively.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; &lt;span class=&#34;code-input&#34;&gt;CREATE ROLE&lt;/span&gt; administrator;
CREATE ROLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A new role has no privileges or roles granted to it. Only superusers can &lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-roles/granting-privileges-to-roles/&#34;&gt;grant privileges&lt;/a&gt; and &lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-roles/granting-db-roles/&#34;&gt;access&lt;/a&gt; to the role.&lt;/p&gt;
&lt;h2 id=&#34;dropping-database-roles-with-dependencies&#34;&gt;Dropping database roles with dependencies&lt;/h2&gt;
&lt;p&gt;If you try to drop a role that is granted to users or other roles the database returns a rollback message:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; &lt;span class=&#34;code-input&#34;&gt;DROP ROLE&lt;/span&gt; administrator;
NOTICE:  User Bob depends on Role administrator
ROLLBACK:  DROP ROLE failed due to dependencies
DETAIL:  Cannot drop Role administrator because other objects depend on it
HINT:  Use DROP ROLE ... CASCADE to remove granted roles from the dependent users/roles
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;To force the drop operation, qualify the &lt;code&gt;DROP ROL&lt;/code&gt;E statement with &lt;code&gt;CASCADE&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; DROP ROLE administrator &lt;span class=&#34;code-input&#34;&gt;CASCADE&lt;/span&gt;;
DROP ROLE
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Admin: Granting privileges to roles</title>
      <link>/en/admin/db-users-and-privileges/db-roles/granting-privileges-to-roles/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/db-users-and-privileges/db-roles/granting-privileges-to-roles/</guid>
      <description>
        
        
        &lt;p&gt;You can use &lt;a href=&#34;../../../../en/sql-reference/statements/grant-statements/&#34;&gt;GRANT statements&lt;/a&gt; to assign privileges to a role, just as you assign privileges to users. See &lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-privileges/#&#34;&gt;Database privileges&lt;/a&gt; for information about which privileges can be granted.&lt;/p&gt;
&lt;p&gt;Granting a privilege to a role immediately affects active user sessions. When you grant a privilege to a role, it becomes immediately available to all users with that role enabled.&lt;/p&gt;
&lt;p&gt;The following example creates two roles and assigns them different privileges on the same table.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create table &lt;code&gt;applog&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE applog (id int, sourceID VARCHAR(32), data TIMESTAMP, event VARCHAR(256));
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create roles &lt;code&gt;logreader&lt;/code&gt; and &lt;code&gt;logwriter&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE ROLE logreader;
CREATE ROLE
=&amp;gt; CREATE ROLE logwriter;
CREATE ROLE
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Grant read-only privileges on &lt;code&gt;applog&lt;/code&gt; to &lt;code&gt;logreader&lt;/code&gt;, and write privileges to &lt;code&gt;logwriter&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; &lt;span class=&#34;code-input&#34;&gt;GRANT SELECT&lt;/span&gt; ON applog TO logreader;
GRANT PRIVILEGE
=&amp;gt; &lt;span class=&#34;code-input&#34;&gt;GRANT INSERT&lt;/span&gt; ON applog TO logwriter;
GRANT PRIVILEGE
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;revoking-privileges-from-roles&#34;&gt;Revoking privileges from roles&lt;/h2&gt;
&lt;p&gt;Use &lt;a href=&#34;../../../../en/sql-reference/statements/revoke-statements/&#34;&gt;REVOKE statements&lt;/a&gt; to revoke a privilege from a role. Revoking a privilege from a role immediately affects active user sessions. When you revoke a privilege from a role, it is no longer available to users who have the privilege through that role.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; &lt;span class=&#34;code-input&#34;&gt;REVOKE INSERT&lt;/span&gt; ON applog FROM logwriter;
REVOKE PRIVILEGE
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Admin: Granting database roles</title>
      <link>/en/admin/db-users-and-privileges/db-roles/granting-db-roles/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/db-users-and-privileges/db-roles/granting-db-roles/</guid>
      <description>
        
        
        &lt;p&gt;You can assign one or more roles to a user or another role with &lt;a href=&#34;../../../../en/sql-reference/statements/grant-statements/grant-role/#&#34;&gt;GRANT (Role)&lt;/a&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;GRANT &lt;span class=&#34;code-variable&#34;&gt;role&lt;/span&gt;[,...] TO &lt;span class=&#34;code-variable&#34;&gt;grantee&lt;/span&gt;[,...] [ WITH ADMIN OPTION ]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example, you might create three roles—&lt;code&gt;appdata&lt;/code&gt;, &lt;code&gt;applogs&lt;/code&gt;, and &lt;code&gt;appadmin&lt;/code&gt;—and grant &lt;code&gt;appadmin&lt;/code&gt; to user &lt;code&gt;bob&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE ROLE appdata;
CREATE ROLE
=&amp;gt; CREATE ROLE applogs;
CREATE ROLE
=&amp;gt; CREATE ROLE appadmin;
CREATE ROLE
=&amp;gt; GRANT appadmin TO bob;
GRANT ROLE
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;granting-roles-to-another-role&#34;&gt;Granting roles to another role&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;GRANT&lt;/code&gt; can assign one or more roles to another role. For example, the following &lt;code&gt;GRANT&lt;/code&gt; statement grants roles &lt;code&gt;appdata&lt;/code&gt; and &lt;code&gt;applogs&lt;/code&gt; to role &lt;code&gt;appadmin&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; GRANT appdata, applogs TO appadmin;
 -- grant to other roles
GRANT ROLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Because user bob was previously assigned the role &lt;code&gt;appadmin&lt;/code&gt;, he now has all privileges that are granted to roles &lt;code&gt;appdata&lt;/code&gt; and &lt;code&gt;applogs&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;When you grant one role to another role, the database checks for circular references. In the previous example, role &lt;code&gt;appdata&lt;/code&gt; is assigned to the &lt;code&gt;appadmin&lt;/code&gt; role. Thus, subsequent attempts to assign &lt;code&gt;appadmin&lt;/code&gt; to &lt;code&gt;appdata&lt;/code&gt; fail, returning with the following warning:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; GRANT appadmin TO appdata;
WARNING:  Circular assignation of roles is not allowed
HINT:  Cannot grant appadmin to appdata
GRANT ROLE
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;enabling-roles&#34;&gt;Enabling roles&lt;/h2&gt;
&lt;p&gt;After granting a role to a user, the role must be enabled. You can enable a role for the current session:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; SET ROLE appdata;
SET ROLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can also enable a role as part of the user&#39;s login, by modifying the user&#39;s profile with 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/alter-statements/alter-user/#&#34;&gt;ALTER USER...DEFAULT ROLE&lt;/a&gt;&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; ALTER USER bob DEFAULT ROLE appdata;
ALTER USER
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For details, see &lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-roles/enabling-roles/#&#34;&gt;Enabling roles&lt;/a&gt; and &lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-roles/enabling-roles-automatically/#&#34;&gt;Enabling roles automatically&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;granting-administrative-privileges&#34;&gt;Granting administrative privileges&lt;/h2&gt;
&lt;p&gt;You can delegate to non-superusers users administrative access to a role by qualifying the &lt;a href=&#34;../../../../en/sql-reference/statements/grant-statements/grant-role/#&#34;&gt;GRANT (Role)&lt;/a&gt; statement with the option &lt;code&gt;WITH ADMIN OPTION&lt;/code&gt;. Users with administrative access can manage access to the role for other users, including granting them administrative access. In the following example, a superuser grants the &lt;code&gt;appadmin&lt;/code&gt; role with administrative privileges to users &lt;code&gt;bob&lt;/code&gt; and &lt;code&gt;alice.&lt;/code&gt;&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; GRANT appadmin TO bob, alice WITH ADMIN OPTION;
GRANT ROLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now, both users can exercise their administrative privileges to grant the &lt;code&gt;appadmin&lt;/code&gt; role to other users, or revoke it. For example, user &lt;code&gt;bob&lt;/code&gt; can now revoke the &lt;code&gt;appadmin&lt;/code&gt; role from user &lt;code&gt;alice&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; \connect - bob
You are now connected as user &amp;#34;bob&amp;#34;.
=&amp;gt; REVOKE appadmin FROM alice;
REVOKE ROLE
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;admonition caution&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Caution&lt;/h4&gt;

As with all user privilege models, database superusers should be cautious when granting any user a role with administrative privileges. For example, if the database superuser grants two users a role with administrative privileges, either user can revoke that role from the other user.

&lt;/div&gt;
&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;p&gt;The following example creates a role called &lt;code&gt;commenter&lt;/code&gt; and grants that role to user &lt;code&gt;bob&lt;/code&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create the &lt;code&gt;comments&lt;/code&gt; table:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE comments (id INT, comment VARCHAR);
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create the &lt;code&gt;commenter&lt;/code&gt; role:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE ROLE commenter;
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Grant to &lt;code&gt;commenter&lt;/code&gt; INSERT and SELECT privileges on the &lt;code&gt;comments&lt;/code&gt; table:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; GRANT INSERT, SELECT ON comments TO commenter;
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Grant the &lt;code&gt;commenter&lt;/code&gt; role to user &lt;code&gt;bob&lt;/code&gt;.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; GRANT commenter TO bob;
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In order to access the role and its associated privileges, &lt;code&gt;bob&lt;/code&gt; enables the newly-granted role for himself:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; \c - bob
=&amp;gt; SET ROLE commenter;
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Because &lt;code&gt;bob&lt;/code&gt; has INSERT and SELECT privileges on the &lt;code&gt;comments&lt;/code&gt; table, he can perform the following actions:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; INSERT INTO comments VALUES (1, &amp;#39;Hello World&amp;#39;);
 OUTPUT
--------
      1
(1 row)
=&amp;gt; SELECT * FROM comments;
 id |   comment
----+-------------
  1 | Hello World
(1 row)
=&amp;gt; COMMIT;
COMMIT
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Because &lt;code&gt;bob&lt;/code&gt;&#39;s role lacks DELETE privileges, the following statement returns an error:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; DELETE FROM comments WHERE id=1;
ERROR 4367:  Permission denied for relation comments
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;a href=&#34;../../../../en/mc/users-roles-and-privileges/db-privileges/#&#34;&gt;Database privileges&lt;/a&gt;

      </description>
    </item>
    
    <item>
      <title>Admin: Revoking database roles</title>
      <link>/en/admin/db-users-and-privileges/db-roles/revoking-db-roles/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/db-users-and-privileges/db-roles/revoking-db-roles/</guid>
      <description>
        
        
        &lt;p&gt;
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/revoke-statements/revoke-role/#&#34;&gt;REVOKE (Role)&lt;/a&gt;&lt;/code&gt; can revoke roles from one or more grantees—that is, from users or roles:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;REVOKE [ ADMIN OPTION FOR ] &lt;span class=&#34;code-variable&#34;&gt;role&lt;/span&gt;[,...] FROM &lt;span class=&#34;code-variable&#34;&gt;grantee&lt;/span&gt;[,...] [ CASCADE ]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example, the following statement revokes the &lt;code&gt;commenter&lt;/code&gt; role from user &lt;code&gt;bob&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; \c
You are now connected as user &amp;#34;dbadmin&amp;#34;.
=&amp;gt; REVOKE commenter FROM bob;
REVOKE ROLE
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;revoking-administrative-access-from-a-role&#34;&gt;Revoking administrative access from a role&lt;/h2&gt;
&lt;p&gt;You can qualify 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/revoke-statements/revoke-role/#&#34;&gt;REVOKE (Role)&lt;/a&gt;&lt;/code&gt; with the clause &lt;code&gt;ADMIN OPTION FOR&lt;/code&gt;. This clause revokes from the grantees the authority (granted by an earlier &lt;code&gt;GRANT (Role)...WITH ADMIN OPTION&lt;/code&gt; statement) to grant the specified roles to other users or roles. Current roles for the grantees are unaffected.&lt;/p&gt;
&lt;p&gt;The following example revokes user Alice&#39;s authority to grant and revoke the &lt;code&gt;commenter&lt;/code&gt; role:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; \c
You are now connected as user &amp;#34;dbadmin&amp;#34;.
=&amp;gt; REVOKE ADMIN OPTION FOR commenter FROM alice;
REVOKE ROLE
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Admin: Enabling roles</title>
      <link>/en/admin/db-users-and-privileges/db-roles/enabling-roles/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/db-users-and-privileges/db-roles/enabling-roles/</guid>
      <description>
        
        
        &lt;p&gt;When you enable a role in a session, you obtain all privileges assigned to that role. You can enable multiple roles simultaneously, thereby gaining all privileges of those roles, plus any privileges that are already granted to you directly.&lt;/p&gt;
&lt;p&gt;By default, only &lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-roles/predefined-db-roles/&#34;&gt;predefined roles&lt;/a&gt; are &lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-roles/enabling-roles-automatically/&#34;&gt;enabled automatically&lt;/a&gt; for users. Otherwise, on starting a session, you must explicitly enable &lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-roles/granting-db-roles/&#34;&gt;assigned roles&lt;/a&gt; with the function 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/set-statements/set-role/#&#34;&gt;SET ROLE&lt;/a&gt;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;For example, the dbadmin creates the &lt;code&gt;logreader&lt;/code&gt; role and assigns it to user &lt;code&gt;alice&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; \c
You are now connected as user &amp;#34;dbadmin&amp;#34;.
=&amp;gt; CREATE ROLE logreader;
CREATE ROLE
=&amp;gt; GRANT SELECT ON TABLE applog to logreader;
GRANT PRIVILEGE
=&amp;gt; GRANT logreader TO alice;
GRANT ROLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;User &lt;code&gt;alice&lt;/code&gt; must enable the new role before she can view the &lt;code&gt;applog&lt;/code&gt; table:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; \c - alice
You are now connected as user &amp;#34;alice&amp;#34;.
=&amp;gt; SELECT * FROM applog;
ERROR:  permission denied for relation applog
=&amp;gt; SET ROLE logreader;
SET
=&amp;gt; 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)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;enabling-all-user-roles&#34;&gt;Enabling all user roles&lt;/h2&gt;
&lt;p&gt;You can enable all roles available to your user account with &lt;code&gt;SET ROLE ALL&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SET ROLE ALL;
SET
=&amp;gt; SHOW ENABLED_ROLES;
     name      |           setting
---------------+------------------------------
 enabled roles | logreader, logwriter
(1 row)
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;admonition important&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Important&lt;/h4&gt;
You can also enable user roles on login. For more information, see &lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-roles/enabling-roles-automatically/#&#34;&gt;Enabling roles automatically&lt;/a&gt;.
&lt;/div&gt;
&lt;h2 id=&#34;disabling-roles&#34;&gt;Disabling roles&lt;/h2&gt;
&lt;p&gt;A user can disable all roles with 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/set-statements/set-role/#&#34;&gt;SET ROLE NONE&lt;/a&gt;&lt;/code&gt;. This statement disables all roles for the current session, excluding predefined roles:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SET ROLE NONE;
=&amp;gt; SHOW ENABLED_ROLES;
     name      | setting
---------------+---------
 enabled roles |
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Admin: Enabling roles automatically</title>
      <link>/en/admin/db-users-and-privileges/db-roles/enabling-roles-automatically/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/db-users-and-privileges/db-roles/enabling-roles-automatically/</guid>
      <description>
        
        
        &lt;p&gt;By default, new users are assigned the &lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-roles/predefined-db-roles/public/#&#34;&gt;PUBLIC&lt;/a&gt;, which is automatically enabled when a new session starts. Typically, other roles are created and users are assigned to them, but these are not automatically enabled. Instead, users must explicitly &lt;a href=&#34;../../../../en/admin/db-users-and-privileges/db-roles/enabling-roles/&#34;&gt;enable&lt;/a&gt; their assigned roles with each new session, with 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/set-statements/set-role/#&#34;&gt;SET ROLE&lt;/a&gt;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You can automatically enable roles for users in two ways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Enable roles for individual users on login&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enable all roles for all users on login&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;enable-roles-for-individual-users&#34;&gt;Enable roles for individual users&lt;/h2&gt;
&lt;p&gt;After assigning roles to users, you can set one or more default roles for each user by modifying their profiles, with 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/alter-statements/alter-user/#&#34;&gt;ALTER USER...DEFAULT ROLE&lt;/a&gt;&lt;/code&gt;. User default roles are automatically enabled at the start of the user session. You should consider setting default roles for users if they typically rely on the privileges of those roles to carry out routine tasks.

&lt;div class=&#34;admonition important&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Important&lt;/h4&gt;
&lt;code&gt;ALTER USER...DEFAULT ROLE&lt;/code&gt; overwrites previous default role settings.
&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;The following example shows how to set &lt;code&gt;regional_manager&lt;/code&gt; as the default role for user &lt;code&gt;LilyCP&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; \c
You are now connected as user &amp;#34;dbadmin&amp;#34;.
=&amp;gt; GRANT regional_manager TO LilyCP;
GRANT ROLE
=&amp;gt; ALTER USER LilyCP DEFAULT ROLE regional_manager;
ALTER USER
=&amp;gt; \c - LilyCP
You are now connected as user &amp;#34;LilyCP&amp;#34;.
=&amp;gt; SHOW ENABLED_ROLES;
     name      |     setting
---------------+------------------
 enabled roles | regional_manager
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;enable-all-roles-for-all-users&#34;&gt;Enable all roles for all users&lt;/h2&gt;
&lt;p&gt;Configuration parameter &lt;code&gt;EnableAllRolesOnLogin&lt;/code&gt; specifies whether to enable all roles for all database users on login. By default, this parameter is set to 0. If set to 1, the database enables the roles of all users when they log in.&lt;/p&gt;
&lt;h2 id=&#34;clearing-default-roles&#34;&gt;Clearing default roles&lt;/h2&gt;
&lt;p&gt;You can clear all default role assignments for a user with 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/alter-statements/alter-user/#&#34;&gt;ALTER USER...DEFAULT ROLE NONE&lt;/a&gt;&lt;/code&gt;. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER USER fred DEFAULT ROLE NONE;
ALTER USER
=&amp;gt; SELECT user_name, default_roles, all_roles FROM users WHERE user_name = &amp;#39;fred&amp;#39;;
 user_name | default_roles | all_roles
-----------+---------------+-----------
 fred      |               | logreader
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Admin: Viewing user roles</title>
      <link>/en/admin/db-users-and-privileges/db-roles/viewing-user-roles/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/db-users-and-privileges/db-roles/viewing-user-roles/</guid>
      <description>
        
        
        &lt;p&gt;You can obtain information about roles in three ways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;#Verifyin&#34;&gt;Verify specific role assignments&lt;/a&gt; with the function 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/management-functions/privileges-and-access-functions/has-role/#&#34;&gt;HAS_ROLE&lt;/a&gt;&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;#Viewing&#34;&gt;View all available (granted) and enabled roles&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;#Querying&#34;&gt;Obtain comprehensive information&lt;/a&gt; about roles, the users assigned to them, and the privileges granted to those users and roles by querying system tables &lt;a href=&#34;../../../../en/sql-reference/system-tables/v-catalog-schema/roles/&#34;&gt;ROLES&lt;/a&gt;, &lt;a href=&#34;../../../../en/sql-reference/system-tables/v-catalog-schema/users/&#34;&gt;USERS&lt;/a&gt;, AND &lt;a href=&#34;../../../../en/sql-reference/system-tables/v-catalog-schema/grants/&#34;&gt;GRANTS&lt;/a&gt;, respectively.&lt;/p&gt;

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

System tables do not show whether a role is available to a user indirectly through other roles. Call &lt;code&gt;HAS_ROLE&lt;/code&gt; to obtain that information.

&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a name=&#34;Verifyin&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;verifying-role-assignments&#34;&gt;Verifying role assignments&lt;/h2&gt;
&lt;p&gt;The function 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/management-functions/privileges-and-access-functions/has-role/#&#34;&gt;HAS_ROLE&lt;/a&gt;&lt;/code&gt; checks whether a role is granted to the specified user or role. Non-superusers can use this function to check their own role membership. Superusers can use it to determine role assignments for other users and roles. You can also use Management Console to &lt;a href=&#34;../../../../en/mc/users-roles-and-privileges/&#34;&gt;check role assignments&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In the following example, a &lt;code&gt;dbadmin&lt;/code&gt; user checks whether user &lt;code&gt;MikeL&lt;/code&gt; is assigned the &lt;code&gt;admnistrator&lt;/code&gt; role:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; \c
You are now connected as user &amp;#34;dbadmin&amp;#34;.
=&amp;gt; SELECT HAS_ROLE(&amp;#39;MikeL&amp;#39;, &amp;#39;administrator&amp;#39;);
 HAS_ROLE
----------
 t
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;User &lt;code&gt;MikeL&lt;/code&gt; checks whether he has the &lt;code&gt;regional_manager&lt;/code&gt; role:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; \c - MikeL
You are now connected as user &amp;#34;MikeL&amp;#34;.
=&amp;gt; SELECT HAS_ROLE(&amp;#39;regional_manager&amp;#39;);
 HAS_ROLE
----------
 f
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The dbadmin grants the &lt;code&gt;regional_manager&lt;/code&gt; role to the &lt;code&gt;administrator&lt;/code&gt; role. On checking again, &lt;code&gt;MikeL&lt;/code&gt; verifies that he now has the &lt;code&gt;regional_manager&lt;/code&gt; role:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;dbadmin=&amp;gt; \c
You are now connected as user &amp;#34;dbadmin&amp;#34;.
dbadmin=&amp;gt; GRANT regional_manager to administrator;
GRANT ROLE
dbadmin=&amp;gt; \c - MikeL
You are now connected as user &amp;#34;MikeL&amp;#34;.
dbadmin=&amp;gt; SELECT HAS_ROLE(&amp;#39;regional_manager&amp;#39;);
 HAS_ROLE
----------
 t
(1 row)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a name=&#34;Viewing&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;viewing-available-and-enabled-roles&#34;&gt;Viewing available and enabled roles&lt;/h2&gt;
&lt;p&gt;
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/show/#AvailableRoles&#34;&gt;SHOW AVAILABLE ROLES&lt;/a&gt;&lt;/code&gt; lists all roles granted to you:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SHOW AVAILABLE ROLES;
      name       |           setting
-----------------+-----------------------------
 available roles | logreader, logwriter
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/show/#EnabledRoles&#34;&gt;SHOW ENABLED ROLES&lt;/a&gt;&lt;/code&gt; lists the roles enabled in your session:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SHOW ENABLED ROLES;
     name      | setting
---------------+----------
 enabled roles | logreader
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;a name=&#34;Querying&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;querying-system-tables&#34;&gt;Querying system tables&lt;/h2&gt;
&lt;p&gt;You can query tables &lt;a href=&#34;../../../../en/sql-reference/system-tables/v-catalog-schema/roles/&#34;&gt;ROLES&lt;/a&gt;, &lt;a href=&#34;../../../../en/sql-reference/system-tables/v-catalog-schema/users/&#34;&gt;USERS&lt;/a&gt;, AND &lt;a href=&#34;../../../../en/sql-reference/system-tables/v-catalog-schema/grants/&#34;&gt;GRANTS&lt;/a&gt;, either separately or joined, to obtain detailed information about user roles, users assigned to those roles, and the privileges granted explicitly to users and implicitly through roles.&lt;/p&gt;
&lt;p&gt;The following query on &lt;a href=&#34;../../../../en/sql-reference/system-tables/v-catalog-schema/roles/&#34;&gt;ROLES&lt;/a&gt; returns the names of all roles users can access, and the roles granted (assigned) to those roles. An asterisk (*) appended to a role indicates that the user can grant the role to other users:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * FROM roles;
      name       | assigned_roles
-----------------+----------------
 public          |
 dbduser         |
 dbadmin         | dbduser*
 pseudosuperuser | dbadmin*
 logreader       |
 logwriter       |
 logadmin        | logreader, logwriter
(7 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following query on system table &lt;a href=&#34;../../../../en/sql-reference/system-tables/v-catalog-schema/users/&#34;&gt;USERS&lt;/a&gt; returns all users with the DBADMIN role. An asterisk (*) appended to a role indicates that the user can grant the role to other users:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT user_name, is_super_user, default_roles, all_roles FROM v_catalog.users WHERE all_roles ILIKE &amp;#39;%dbadmin%&amp;#39;;
 user_name | is_super_user |            default_roles             |              all_roles
-----------+---------------+--------------------------------------+--------------------------------------
 dbadmin   | t             | dbduser*, dbadmin*, pseudosuperuser* | dbduser*, dbadmin*, pseudosuperuser*
 u1        | f             |                                      | dbadmin*
 u2        | f             |                                      | dbadmin
(3 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following query on system table &lt;a href=&#34;../../../../en/sql-reference/system-tables/v-catalog-schema/grants/&#34;&gt;GRANTS&lt;/a&gt; returns the privileges granted to user Jane or role R1. An asterisk (*) appended to a privilege indicates that the user can grant the privilege to other users:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT grantor,privileges_description,object_name,object_type,grantee FROM grants WHERE grantee=&amp;#39;Jane&amp;#39; OR grantee=&amp;#39;R1&amp;#39;;
grantor | privileges_description | object_name | object_type  |  grantee
--------+------------------------+-------------+--------------+-----------
dbadmin | USAGE                  | general     | RESOURCEPOOL | Jane
dbadmin |                        | R1          | ROLE         | Jane
dbadmin | USAGE*                 | s1          | SCHEMA       | Jane
dbadmin | USAGE, CREATE*         | s1          | SCHEMA       | R1
(4 rows)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
  </channel>
</rss>
