LinuxCommandLibrary

createuser

TLDR

Create a user interactively

$ createuser [username]
copy
Create superuser
$ createuser -s [username]
copy
Create user with password prompt
$ createuser -P [username]
copy
Create user that can create databases
$ createuser -d [username]
copy
Create user with connection options
$ createuser -h [localhost] -p [5432] -U [admin] [username]
copy
Create user that can create roles
$ createuser -r [username]
copy

SYNOPSIS

createuser [options] [username]

DESCRIPTION

createuser is a PostgreSQL utility that creates new database users (roles). It's a wrapper around the SQL CREATE ROLE command, providing a convenient command-line interface.
The tool can create users with various privileges including superuser status, database creation rights, and role creation abilities. It connects to the database server and executes the appropriate SQL.

PARAMETERS

-s, --superuser

Create superuser.
-d, --createdb
Allow creating databases.
-r, --createrole
Allow creating roles.
-l, --login
Allow login (default).
-P, --pwprompt
Prompt for password.
-e, --echo
Show generated SQL.
-h host
Database server host.
-p port
Database server port.
-U user
Connect as user.
-W
Force password prompt.
-i, --inherit
Role inherits privileges.
--replication
Allow replication connections.

CAVEATS

Requires appropriate privileges to create roles. Superuser creation requires superuser connection. Password set via -P is entered interactively.

HISTORY

createuser has been part of PostgreSQL since early versions, providing a shell interface to role management. PostgreSQL evolved from the POSTGRES project at UC Berkeley in the 1980s. The distinction between users and roles was unified in PostgreSQL 8.1.

SEE ALSO

dropuser(1), psql(1), createdb(1), pg_dump(1)

Copied to clipboard