createuser [ options ] [ username ]
Specifies the hostname of the machine on which the postmaster is running.
Specifies the Internet TCP/IP port or local Unix domain socket file extension on which the postmaster is listening for connections.
Echo the queries that createdb generates and sends to the backend.
Do not display a response.
Allows the new user to create databases.
Forbids the new user to create databases.
Allows the new user to create other users.
Forbids the new user to create other users.
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.
Allows you to pick a non-default user id for the new user. This is not necessary, but some people like it.
Specifies the name of the Postgres user to be created. This name must be unique among all Postgres users.
The options -h, -p, and -e, are passed on literally to psql. The psql options -U and -W are available as well, but their use can be confusing in this context.
All is well.
Something went wrong. The user was not created.
createuser creates a new Postgres user. Only users with usesuper set in the pg_shadow class can create new Postgres users.
createuser is a shell script wrapper around the SQL command CREATE USER via the Postgres interactive terminal psql. Thus, there is nothing special about creating users via this or other methods. This means that the psql must be found by the script and that a database server is running at the targeted host. Also, any default settings and environment variables available to psql and the libpq front-end library do apply.
To create a user joe on the default database server:
$ createuser joe Is the new user allowed to create databases? (y/n) n Shall the new user be allowed to create more new users? (y/n) n CREATE USER
To create the same user joe using the postmaster on host eden, port 5000, avoiding the prompts and taking a look at the underlying query:
$ createuser -p 5000 -h eden -D -A -e joe CREATE USER "joe" NOCREATEDB NOCREATEUSER CREATE USER