createuser

A core utility for creating a database role

createuser is a core utility for creating a database role, and is essentially a wrapper around the CREATE ROLE command.

createuser was added in PostgreSQL 7.0.

Usage

In contrast to most core utilities, createuser does not accept conninfo strings via the -d/--dbname option; - the -d option is actually -d/--createdb ("role can create new databases"),  and there is no --dbname long option, so connection parameters must be individually provided with -h/--host, -p/--port etc.

Note that unlike CREATE ROLE (but like CREATE USER), any role created with createuser will be provided with login permission by default.

createuser does not emit any output on successful creation of a user.

Source code

The createuser source code is located at src/bin/scripts/createuser.c.

Change history

Work-in-progress

Examples

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

postgres=# \q
postgres$ createuser -h localhost --role=admin newuser
postgres$ psql
psql (13beta3)
Type "help" for help.

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


Categories

Core utility, User management

See also

dropuser, CREATE ROLE, CREATE USER