CREATE ROLE statement creates SQL roles, which are groups containing any number of roles and users as members. You can assign privileges to roles, and all members of the role (regardless of whether if they are direct or indirect members) will inherit the role’s privileges.
You can use the keywords ROLE and USER interchangeably. CREATE USER is equivalent to CREATE ROLE, with one exception: CREATE ROLE sets the NOLOGIN role option, which prevents the new role from being used to log in to the database. You can use CREATE ROLE and specify the LOGIN role option to achieve the same result as CREATE USER.
The
CREATE ROLE statement performs a schema change. For more information about how online schema changes work in CockroachDB, see Online Schema Changes.Considerations
- After creating a role, you must grant it privileges to databases and tables.
- All privileges of a role are inherited by all of its members.
- Users and roles can be members of roles.
- Role options of a role are not inherited by any of its members.
- There is no limit to the number of members in a role.
- Membership loops are not allowed (direct:
A is a member of B is a member of Aor indirect:A is a member of B is a member of C ... is a member of A).
Required privileges
Unless a role is a member of theadmin role, additional privileges are required to manage other roles.
- To create other roles, a role must have the
CREATEROLErole option. - To add the
LOGINcapability for other roles so that they can log in as users, a role must also have theCREATELOGINrole option. - To be able to grant or revoke membership to a role for additional roles, a member of the role must be set as a role admin for that role.
Synopsis
Parameters
Role names
- Are case-insensitive.
- Must start with either a letter or underscore.
- Must contain only letters, numbers, periods, or underscores.
- Must be between 1 and 63 characters.
- Cannot be
none. - Cannot start with
pg_orcrdb_internal. Object names with these prefixes are reserved for system catalogs. - User and role names share the same namespace and must be unique.
Role options
Examples
To run the following examples, start a secure single-node cluster and use the built-in SQL shell:The following statements are run by the
root user that is a member of the admin role and has ALL privileges.Create a role
Role names are case-insensitive; must start with a letter, number, or underscore; must contain only letters, numbers, periods, or underscores; and must be between 1 and 63 characters.Create a role that can log in to the database
Prevent a role from using password authentication
The following statement prevents the role from using password authentication and mandates certificate-based client authentication:Create a role that can create other roles and manage authentication methods for the new roles
The following example allows the role to create other users and manage authentication methods for them:Create a role that can create and rename databases
The following example allows the role to create or rename databases:Create a role that can pause, resume, and cancel non-admin jobs
The following example allows the role to pause, resume, and cancel jobs:Create a role that can see and cancel non-admin queries and sessions
The following example allows the role to cancel queries and sessions for other non-admin roles:
Create a role that can control changefeeds
The following example allows the role to runCREATE CHANGEFEED:
Create a role that can modify cluster settings
The following example allows the role to modify cluster settings:Create a role that can bypass row-level security (RLS)
To create a role that can bypass row-level security, execute the following statement to grant theBYPASSRLS privilege:
BYPASSRLS privilege, refer to ALTER ROLE.

