createuser

Name

createuser  --  Adds a new user account to a database.

Synopsis

createuser [ options ] [ username ]
  

Parameters

-h, --host host

Use this parameter to provide the hostname that postmaster is running on.

-p, --port port

Use this parameter to specify the TCP/IP port or socket file that postmaster is currently listening on.

-e, --echo

Pass this parameter to have all SQL queries that createuser generates displayed to the screen.

-q, --quiet

Pass this parameter to run in quiet mode; when in quiet mode, the program will not display any results or responses.

-d, --createdb

Pass this parameter to allow the new user account the ability to create databases.

-D, --no-createdb

Pass this paramter to forbid the new user account to create databases.

-a, --adduser

Pass this parameter to allow the new user account to create other new users.

-A, --no-adduser

Pass this parameter to explicitly forbid the new user account the ability to create new users.

-P, --pwprompt

Pass this parameter to instruct createuser to prompt for the new user account's password.

-i, --sysid uid

Use this parameter to specify a non-default user ID for the new user account. If you do not user this parameter, the system will set the user ID as one more than the last user ID.

username

Use this parameter to supply the username of the new user account being created. This must be a unique username within the database.

Results

CREATE USER

This message is displayed if creation of the user account is successful.

createuser: creation of user "username" failed

This error is displayed if creation of the user account fails. If an error condition is present, the backend's message will be displayed. This should provide more information about why creation failed. Refer to CREATE USER and psql for more information about possible errors.

Description

Use createuser to create a new user account from the command line. This functions exactly the same as connecting to the PostgreSQL database through psql and issuing the SQL CREATE USER command. Neither of these methods of adding users is better than the other, as they both use the same set of commands.

NoteNote
 

Your PostgreSQL user account must have permissions to create usersbefore this command will work.

Examples

The following example demonstrates how to create a user named jonathan on the default database.

$ createuser jonathan
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