createuser
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
- PostgreSQL 13
- deprecated options
--adduser
and--no-adduser
removed (commit 4fa5edcd)
- deprecated options
- PostgreSQL 8.4
-w
/--no-password
option added (commit 9de59fd1)
- PostgreSQL 8.3
--quiet
option removed (commit 9539e64b)
- PostgreSQL 7.0
- added (commit 240e4c98)
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 | {}
References
- PostgreSQL documentation: createuser