Contents
CREATE ROLE
An SQL command for creating a database role
CREATE ROLE
is a DDL command for creating a database role.
CREATE ROLE
was added in PostgreSQL 8.1, replacing the existing CREATE USER
and CREATE GROUP
commands (which are retained as aliases of CREATE ROLE
).
Change history
- PostgreSQL 10
- option
UNENCRYPTED PASSWORD
removed (commit eb61136d)
- option
- PostgreSQL 9.6
- option
CREATEUSER
/NOCREATEUSER
removed (commit d371bebd)
- option
- PostgreSQL 9.5
- option
BYPASSRLS
/NOBYPASSRLS
added (commit 491c029d)
- option
- PostgreSQL 9.1
- option
REPLICATION
/NOREPLICATION
added (commit 9b8aff8c)
- option
- PostgreSQL 8.1
- added (commit 7762619e)
Examples
Minimal usage example for CREATE ROLE
:
postgres=# CREATE ROLE foo; CREATE ROLE
By default this role is unable to log in:
postgres=# \du foo List of roles Role name | Attributes | Member of -----------+--------------+----------- foo | Cannot login | {}
To create a login role, execute e.g.:
postgres=# CREATE ROLE bar LOGIN; CREATE ROLE postgres=# \du bar List of roles Role name | Attributes | Member of -----------+------------+----------- bar | | {}
This is equivalent to executing CREATE USER bar
.
References
- PostgreSQL documentation: CREATE ROLE