CREATE USER creates SQL users, which let you control on your databases and tables.
You can use the keywords ROLE and USER interchangeably. CREATE USER is equivalent to , 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 USER statement performs a schema change. For more information about how online schema changes work in CockroachDB, see .
Considerations
- After creating users, you must .
- All users belong to the
publicrole, to which you can and privileges. - On secure clusters, you must and users must authenticate their access to the cluster.
- The
CREATE USERstatement waits for full-cluster visibility of the new user metadata. It is not blocked by long-running transactions that may have accessed older metadata, and it does not create a .
Required privileges
To create other users, the user must be a member of theadmin role or have the CREATEROLE parameter set.
Synopsis
See .Parameters
User names
- Are case-insensitive.
- Must start with 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 . - User and role names share the same namespace and must be unique.
Role options
User authentication
Secure clusters require users to authenticate their access to databases and tables. CockroachDB offers three methods for this:- , which is available to all users. To ensure the highest level of security, we recommend only using client certificate and key authentication.
-
Password authentication, which is available to users and roles who you’ve created passwords for. To create a user with a password, use the
WITH PASSWORDclause ofCREATE USER. To add a password to an existing user, use the statement. Users can use passwords to authenticate without supplying client certificates and keys; however, we recommend using certificate-based authentication whenever possible. Password creation is supported only in secure clusters. - .
Examples
To run the following examples, 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 user
Usernames are case-insensitive; must start with a letter or underscore; must contain only letters, numbers, periods, or underscores; and must be between 1 and 63 characters.- .
- For secure clusters, you must also .
Create a user with a password
Prevent a user from using password authentication
The following statement prevents the user from using password authentication and mandates certificate-based client authentication:Create a user that can create other users and manage authentication methods for the new users
The following example allows the user to and for them:Create a user that can create and rename databases
The following example allows the user to or databases:Create a user that can pause, resume, and cancel non-admin jobs
The following example allows the user to , , and jobs:Create a user that can see and cancel non-admin queries and sessions
The following example allows the user to cancel and for other non-admin roles:

