- bullseye 13.7-0+deb11u1
|CREATEUSER(1)||PostgreSQL 13.4 Documentation||CREATEUSER(1)|
createuser - define a new PostgreSQL user account
createuser [connection-option...] [option...] [username]
createuser creates a new PostgreSQL user (or more precisely, a role). Only superusers and users with CREATEROLE privilege can create new users, so createuser must be invoked by someone who can connect as a superuser or a user with CREATEROLE privilege.
If you wish to create a new superuser, you must connect as a superuser, not merely with CREATEROLE privilege. Being a superuser implies the ability to bypass all access permission checks within the database, so superuser access should not be granted lightly.
createuser is a wrapper around the SQL command CREATE ROLE (CREATE_ROLE(7)). There is no effective difference between creating users via this utility and via other methods for accessing the server.
createuser accepts the following command-line arguments:
createuser also accepts the following command-line arguments for connection parameters:
This option is never essential, since createuser will automatically prompt for a password if the server demands password authentication. However, createuser will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing -W to avoid the extra connection attempt.
This utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 33.14).
In case of difficulty, see CREATE ROLE (CREATE_ROLE(7)) and psql(1) for discussions of potential problems and error messages. The database server must be running at the targeted host. Also, any default connection settings and environment variables used by the libpq front-end library will apply.
To create a user joe on the default database server:
$ createuser joe
To create a user joe on the default database server with prompting for some additional attributes:
$ createuser --interactive joe Shall the new role be a superuser? (y/n) n Shall the new role be allowed to create databases? (y/n) n Shall the new role be allowed to create more new roles? (y/n) n
To create the same user joe using the server on host eden, port 5000, with attributes explicitly specified, taking a look at the underlying command:
$ createuser -h eden -p 5000 -S -D -R -e joe CREATE ROLE joe NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;
To create the user joe as a superuser, and assign a password immediately:
$ createuser -P -s -e joe Enter password for new role: xyzzy Enter it again: xyzzy CREATE ROLE joe PASSWORD 'md5b5f5ba1a423792b526f799ae4eb3d59e' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;
In the above example, the new password isn't actually echoed when typed, but we show what was typed for clarity. As you see, the password is encrypted before it is sent to the client.
dropuser(1), CREATE ROLE (CREATE_ROLE(7))