createuser
Create new PostgreSQL database users
TLDR
Create a user interactively
Create a user with no special rights
Create a superuser
Create a user allowed to create databases, manage roles, and prompt for a password
Create a user without the ability to create databases or manage roles
SYNOPSIS
createuser [OPTION]... [ROLENAME]
PARAMETERS
-c N, --connection-limit=N
Set maximum concurrent connections for the role (default -1 unlimited).
-d, --createdb
Allow role to create databases.
-D, --no-createdb
Prevent role from creating databases (default).
-E, --encrypted
Encrypt the password (default).
-e, --no-encrypted
Do not encrypt the password.
-I, --no-inherit
Role does not inherit privileges from roles it is member of.
-i, --inherit
Role inherits privileges (default).
-l, --login
Enable login for the role.
-L, --no-login
Disable login (default).
-N, --no-role-name
Do not output SQL to create role name.
-O
Do not output SQL command to create role.
-P, --pwprompt
Prompt for role password.
-r, --createrole
Allow role to create other roles.
-R, --no-createrole
Prevent role from creating roles (default).
-s, --superuser
Make role a superuser.
-S, --no-superuser
Prevent superuser status (default).
-w, --no-password
Never prompt for password.
-W, --password
Force password prompt.
-h HOST, --host=HOST
Database server host.
-p PORT, --port=PORT
Database server port.
-U USER, --username=USER
Connect as specified user.
--role=ROLENAME
Connect as specified role.
-?, --help
Show help.
-V, --version
Show version.
DESCRIPTION
The createuser command is a PostgreSQL utility for creating new roles (database users) from the command line. Roles control access and privileges within a PostgreSQL database cluster. By default, it creates a role without login privileges unless specified.
It prompts interactively for attributes like superuser status, database creation ability, role creation ability, and password, unless options override them. Equivalent to using psql with CREATE ROLE SQL command.
Requires connection to a PostgreSQL server, typically as a superuser (like postgres). Supports connection options for host, port, username. Useful for scripting user management in deployments. Non-interactive mode via options enables automation. Passwords can be prompted or pre-set.
Enhances security by allowing fine-grained role setup without direct SQL access.
CAVEATS
Must connect as superuser or user with CREATEROLE privilege. Fails if role exists. Default database is postgres; specify via PGDATABASE. Interactive prompts unless fully specified. Passwords stored in pg_authid; use ALTER ROLE to change later.
EXAMPLES
createuser newuser # Interactive prompts
createuser --createdb --login --pwprompt appuser # Non-interactive with options
createuser -s postgres new_super # Superuser
ENVIRONMENT
Uses PGHOST, PGPORT, PGUSER, PGPASSWORD, PGDATABASE, PGOPTIONS, PGCONNECT_TIMEOUT.
HISTORY
Introduced in PostgreSQL 6.1 (1998) as a frontend to CREATE USER SQL (later generalized to CREATE ROLE in 8.1, 2005). Evolved with role features; now supports all CREATE ROLE options. Maintained by PostgreSQL Global Development Group.


