createuser -- define a new PostgreSQL user account
createuser [options...] [username]
createuser creates a
new PostgreSQL user.
Only superusers (users with usesuper set in
the pg_shadow table) can create
new PostgreSQL users,
so createuser must be
invoked by someone who can connect as a PostgreSQL
Being a superuser also implies the ability to bypass access permission
checks within the database, so superuserdom should not be granted lightly.
createuser is a shell script wrapper around the
CREATE USER via
the PostgreSQL interactive terminal
psql. Thus, there is nothing
special about creating users via this or other methods. This means
that the psql application must be found by the
script and that
a database server must be running at the targeted host. Also, any default
settings and environment variables used by psql
and the libpq front-end library will apply.
createuser accepts the following command-line arguments:
Specifies the name of the PostgreSQL user to be created.
This name must be unique among all PostgreSQL users.
The new user is allowed to create other users.
(Note: Actually, this makes the new user a superuser.
The option is poorly named.)
The new user is not allowed to create other users (i.e.,
the new user is a regular user, not a superuser).
The new user is allowed to create databases.
The new user is not allowed to create databases.
Echo the queries that createuser generates
and sends to the server.
Encrypts the user's password stored in the database. If not
specified, the default is used.
-i uid --sysid uid
Allows you to pick a non-default user ID for the new user. This is not
necessary, but some people like it.
Does not encrypt the user's password stored in the database. If
not specified, the default is used.
If given, createuser will issue a prompt for
the password of the new user. This is not necessary if you do not plan
on using password authentication.
Do not display a response.
You will be prompted for a name and other missing information if it
is not specified on the command line.
createuser also accepts the following
command-line arguments for connection parameters:
-h host --host host
Specifies the host name of the machine on which the
is running. If host begins with a slash, it is used
as the directory for the Unix domain socket.
-p port --port port
Specifies the Internet TCP/IP port or local Unix domain socket file
extension on which the server
is listening for connections.
-U username --username username
User name to connect as (not the user name to create)
Force password prompt (to connect to the server, not for the
password of the new user).
PGHOST PGPORT PGUSER
Default connection parameters
All is well.
createuser: creation of user "username" failed
Something went wrong. The user was not created.
If there is an error condition, the backend error message will be displayed.
See CREATE USER
and psql for possibilities.
To create a user joe on the default database
$ createuser joeIs the new user allowed to create databases? (y/n) nShall the new user be allowed to create more new users? (y/n) nCREATE USER
To create the same user joe using the
server on host eden, port 5000, avoiding the prompts and
taking a look at the underlying query:
$ createuser -p 5000 -h eden -D -A -e joeCREATE USER "joe" NOCREATEDB NOCREATEUSERCREATE USER