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

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.

Categories

DDL, SQL command, User management

See also

ALTER ROLE, DROP ROLE, SET ROLE, CREATE USER, createuser