CREATE USER

An SQL command for creating a database role

CREATE USER is a DDL command for creating a database role.

CREATE USER was added in PostgreSQL 6.3. Since PostgreSQL 8.1 it has been an alias for CREATE ROLE.

CREATE USER and CREATE ROLE

While CREATE USER is basically (since PostgreSQL 8.1)  an alias for CREATE ROLE, there is one significant behavioural difference, in that CREATE USER results in a role being created with permission to log in (option LOGIN). However roles created with CREATE ROLE do not have permission to log in by default (option NOLOGIN).

This retains the pre-PostgreSQL 8.1 behaviour of CREATE USER, while making it possible to safely define non-login roles with CREATE ROLE.

Note that the createuser core utility behaves in the same way as CREATE USER, i.e. roles created using it have login permission by default.

Change history

Examples

Basic usage example for CREATE USER:

postgres=# CREATE USER foo;
CREATE ROLE

postgres=# \du List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------+----------- foo | | {} postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

Note the behavioral difference between CREATE USER and CREATE ROLE:

postgres=# CREATE ROLE bar;
CREATE ROLE

postgres=# \du List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------+----------- bar | Cannot login | {} foo | | {} postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

Categories

DDL, SQL command, Users and roles

See also

ALTER USER, DROP USER, CREATE ROLE, createuser