Skip to main content
The CREATE USER statement creates SQL users, which let you control privileges on your databases and tables. 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 USER statement performs a schema change. For more information about how online schema changes work in CockroachDB, see Online Schema Changes.

Considerations

Required privileges

To create other users, the user must be a member of the admin role or have the CREATEROLE parameter set.

Synopsis

See CREATE ROLE: Synopsis.

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_ or crdb_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

User authentication

Secure clusters require users to authenticate their access to databases and tables. CockroachDB offers three methods for this:
  • Client certificate and key authentication, 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 PASSWORD clause of CREATE USER. To add a password to an existing user, use the ALTER USER 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.
  • GSSAPI authentication.

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 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.
After creating users, you must:

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 create other users and manage authentication methods for them:

Create a user that can create and rename databases

The following example allows the user to create or rename databases:

Create a user that can pause, resume, and cancel non-admin jobs

The following example allows the user to pause, resume, and cancel jobs:

Create a user that can see and cancel non-admin queries and sessions

The following example allows the user to cancel queries and sessions for other non-admin roles:

Create a user that can control changefeeds

The following example allows the user to run CREATE CHANGEFEED:

Create a user that can modify cluster settings

The following example allows the user to modify cluster settings:

See also