CREATE USER

This page documents the preview version (v2.21). Preview includes features under active development and is for development and testing only. For production, use the stable version (v2024.1). To learn more, see Versioning.

Synopsis

Use the CREATE USER statement to create a user. The CREATE USER statement is an alias for CREATE ROLE, but creates a role that has LOGIN privileges by default.

Syntax

create_user ::= CREATE USER role_name 
                [ [ WITH ] role_option [ , ... ] ]

role_option ::= SUPERUSER
                | NOSUPERUSER
                | CREATEDB
                | NOCREATEDB
                | CREATEROLE
                | NOCREATEROLE
                | INHERIT
                | NOINHERIT
                | LOGIN
                | NOLOGIN
                | CONNECTION LIMIT connlimit
                | [ ENCRYPTED ] PASSWORD  ' password ' 
                | PASSWORD NULL
                | VALID UNTIL  ' timestamp ' 
                | IN ROLE role_name [ , ... ]
                | IN GROUP role_name [ , ... ]
                | ROLE role_name [ , ... ]
                | ADMIN role_name [ , ... ]
                | USER role_name [ , ... ]
                | SYSID uid

create_user

CREATEUSERrole_nameWITH,role_option

role_option

SUPERUSERNOSUPERUSERCREATEDBNOCREATEDBCREATEROLENOCREATEROLEINHERITNOINHERITLOGINNOLOGINCONNECTIONLIMITconnlimitENCRYPTEDPASSWORD password PASSWORDNULLVALIDUNTIL timestamp INROLE,role_nameINGROUP,role_nameROLE,role_nameADMIN,role_nameUSER,role_nameSYSIDuid

Semantics

See CREATE ROLE for more details.

Examples

  • Create a sample user with password.
yugabyte=# CREATE USER John WITH PASSWORD 'password';
  • Grant John all permissions on the yugabyte database.
yugabyte=# GRANT ALL ON DATABASE yugabyte TO John;
  • Remove John's permissions from the yugabyte database.
yugabyte=# REVOKE ALL ON DATABASE yugabyte FROM John;

See also