table of contents
CREATEUSER(1) | PostgreSQL 16.4 Documentation | CREATEUSER(1) |
NAME¶
createuser - define a new PostgreSQL user account
SYNOPSIS¶
createuser [connection-option...] [option...] [username]
DESCRIPTION¶
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 role with the SUPERUSER, REPLICATION, or BYPASSRLS privilege, 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. CREATEROLE also conveys very extensive privileges.
createuser is a wrapper around the SQL command CREATE ROLE. There is no effective difference between creating users via this utility and via other methods for accessing the server.
OPTIONS¶
createuser accepts the following command-line arguments:
username
-a role
--with-admin=role
-c number
--connection-limit=number
-d
--createdb
-D
--no-createdb
-e
--echo
-E
--encrypted
-g role
--member-of=role
--role=role (deprecated)
-i
--inherit
-I
--no-inherit
--interactive
-l
--login
-L
--no-login
-m role
--with-member=role
-P
--pwprompt
-r
--createrole
-R
--no-createrole
-s
--superuser
-S
--no-superuser
-v timestamp
--valid-until=timestamp
-V
--version
--bypassrls
--no-bypassrls
--replication
--no-replication
-?
--help
createuser also accepts the following command-line arguments for connection parameters:
-h host
--host=host
-p port
--port=port
-U username
--username=username
-w
--no-password
-W
--password
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.
ENVIRONMENT¶
PGHOST
PGPORT
PGUSER
PG_COLOR
This utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 34.15).
DIAGNOSTICS¶
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.
EXAMPLES¶
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.
SEE ALSO¶
dropuser(1), CREATE ROLE (CREATE_ROLE(7)), createrole_self_grant
2024 | PostgreSQL 16.4 |