Skip to main content
This topic describes how to manage users, roles, and privileges in the database. The database employs both role-based access control (RBAC) and identity-based access control (IBAC) to manage privileges within a cluster, allowing cluster administrators to easily restrict privileges within the cluster on different granular levels. Within a cluster, privileges can be granted to users or roles. A role is a collection of privileges that can be assigned to users or other roles in the cluster as needed. A user can be granted one or more roles, which determine their permissions on different objects.

View privilege and role information

Users with the system-defined role user_admin can view all the user and role information within the cluster.

View privilege information

You can view the privileges granted to a user or a role using SHOW GRANTS.
  • View the privileges of the current user.
    NOTE Any user can view their own privileges without needing any privileges.
  • View the privileges of a specific user. The following example shows the privileges of the user jack:
  • View the privileges of a specific role. The following example shows the privileges of the role example_role:

View roles

You can view all the roles within the cluster using SHOW ROLES.

Manage roles

Users with the system-defined role user_admin can create, grant, revoke, or drop roles in the database.

Create a role

You can create a role using CREATE ROLE. By default, a user can have a maximum of 64 roles, including the roles inherited through the roles granted to the user. This limit is checked when a role is granted to a user. You can adjust this setting by using the FE dynamic parameter privilege_max_total_roles_per_user. A role can have a maximum of 16 inheritance levels. You can adjust this setting by using the FE dynamic parameter privilege_max_role_depth. The following example creates the role example_role:

Grant a role

You can grant roles to a user or another role using GRANT.
  • Grant a role to a user. The following example grants the role example_role to the user jack:
  • Grant a role to another role. The following example grants the role example_role to the role test_role:
  • Grant a role to a user group. You can identify user groups from external authentication systems via Group Provider. The following example grants the role example_role to the user group analysts:

Alter the default role of a user

The default role of a user is automatically activated when the user connects to the database. For instructions on how to enable all (default and granted) roles for a user after connection, see Enable all roles. You can set the default role of a user using SET DEFAULT ROLE or ALTER USER. Both of the following examples set the default role of jack to db1_admin. Note that db1_admin must have been assigned to jack.
  • Set the default role using SET DEFAULT ROLE:
  • Set the default role using ALTER USER:

Revoke a role

You can revoke roles from a user or another role using REVOKE.
NOTE You cannot revoke the system-defined default role PUBLIC from a user.
  • Revoke a role from a user. The following example revokes the role example_role from the user jack:
  • Revoke a role from another role. The following example revokes the role example_role from the role test_role:

Drop a role

You can drop a role using DROP ROLE. The following example drops the role example_role:
CAUTION System-defined roles cannot be dropped.

Enable all roles

The default roles of a user are roles that are automatically activated each time the user connects to the cluster. If you want to enable all the roles (default and granted roles) for all users when they connect to the cluster, you can perform the following operation. This operation requires the system privilege OPERATE.
You can also use SET ROLE to activate the roles assigned to you. For example, user jack@'172.10.1.10' has roles db_admin and user_admin but they are not default roles of the user and are not automatically activated when the user connects to the database. If jack@'172.10.1.10' needs to activate db_admin and user_admin, he can run SET ROLE db_admin, user_admin;. Note that SET ROLE overwrites original roles. If you want to enable all your roles, run SET ROLE ALL.

Manage privileges

Users with the system-defined role user_admin can grant or revoke privileges in the database.

Grant privileges

You can grant privileges to a user or a role using GRANT.
  • Grant a privilege to a user. The following example grants the SELECT privilege on the table sr_member to the user jack, and allows jack to grant this privilege to other users or roles (by specifying WITH GRANT OPTION in the SQL):
  • Grant a privilege to a role. The following example grants the SELECT privilege on the table sr_member to the role example_role:

Revoke privileges

You can revoke privileges from a user or a role using REVOKE.
  • Revoke a privilege from a user. The following example revokes the SELECT privilege on the table sr_member from the user jack, and disallows jack to grant this privilege to other users or roles:
  • Revoke a privilege from a role. The following example revokes the SELECT privilege on the table sr_member from the role example_role:

Best practices

Multi-service access control

Usually, a company-owned cluster is managed by a sole service provider and maintains multiple lines of business (LOBs), each of which uses one or more databases. As shown below, a cluster’s users include members from the service provider and two LOBs (A and B). Each LOB is operated by two roles - analysts and executives. Analysts generate and analyze business statements, and executives query the statements. User Privileges LOB A independently manages the database DB_A, and LOB B the database DB_B. LOB A and LOB B use different tables in DB_C. DB_PUBLIC can be accessed by all members of both LOBs. User Privileges Because different members perform different operations on different databases and tables, we recommend you create roles in accordance with their services and positions, apply only the necessary privileges to each role, and assign these roles to corresponding members. As shown below: User Privileges
  1. Assign the system-defined roles db_admin, user_admin, and cluster_admin to cluster maintainers, set db_admin and user_admin as their default roles for daily maintenance, and manually activate the role cluster_admin when they need to operate the nodes of the cluster. Example:
  2. Create users for each member within the LOBs, and set complex passwords for each user.
  3. Create roles for each position within the LOBs, and apply the corresponding privileges to each role. For the director of each LOB, grant their role the maximum collection of the privileges their LOBs need, and the corresponding GRANT privileges (by specifying WITH GRANT OPTION in the statement). Therefore, they can assign these privileges to the members of their LOB. Set the role as their default role if their daily work requires it. Example:
    For analysts and executives, assign them the role with the corresponding privileges. Example:
  4. For the database DB_PUBLIC, which can be accessed by all cluster users, grant the SELECT privilege on DB_PUBLIC to the system-defined role public. Example:
You can assign roles to others to achieve role inheritance in complicated scenarios. For example, if analysts require privileges to write into and query tables in DB_PUBLIC, and executives can only query these tables, you can create roles public_analysis and public_sales, apply relevant privileges to the roles, and assign them to the original roles of analysts and executives respectively. Example:

Customize roles based on scenarios



We recommend you customize roles to manage privileges and users. The following examples classify a few combinations of privileges for some common scenarios.

Grant global read-only privileges on tables

And you can further grant the privilege to use UDFs in queries:

Grant global write privileges on tables

Grant read-only privileges on a specific external catalog

Tip For views in external catalogs, you can query only Hive table views (since v3.1).

Grant write-only privileges on a specific external catalog

You can only write data into Iceberg tables (since v3.1) and Hive tables (since v3.2).

Grant admin privileges on a specific database

Grant privileges to perform backup and restore operations on global, database, table, and partition levels

  • Grant privileges to perform global backup and restore operations: The privileges to perform global backup and restore operations allow the role to back up and restore any database, table, or partition. It requires the REPOSITORY privilege on the SYSTEM level, the privileges to create databases in the default catalog, to create tables in any database, and to load and export data on any table.
  • Grant the privileges to perform database-level backup and restore operations: The privileges to perform database-level backup and restore operations require the REPOSITORY privilege on the SYSTEM level, the privilege to create databases in the default catalog, the privilege to create tables in any database, the privilege to load data into any table, and the privilege export data from any table in the database to be backed up.
  • Grant the privileges to perform table-level backup and restore operations: The privileges to perform table-level backup and restore operations require the REPOSITORY privilege on the SYSTEM level, the privilege to create tables in corresponding databases, the privilege to load data into any table in the database, and the privilege to export data from the table to be backed up.
  • Grant the privileges to perform partition-level backup and restore operations: The privileges to perform partition-level backup and restore operations require the REPOSITORY privilege on the SYSTEM level, and the privilege to load and export data on the corresponding table.