CREATEUSER(1)
β¨ CREATEUSER(1) β¨
okay so bestie, we're diving into createuser, which is literally the PostgreSQL utility for defining a brand new user account. this page is from the PostgreSQL 16.15 docs and it's giving "admin era" β let's get into it π
πΈ NAME πΈ
createuser β define a new PostgreSQL user account
π¦ SYNOPSIS π¦
createuser [connection-option...] [option...] [username]
π DESCRIPTION π
so createuser creates a new PostgreSQL user (or, more precisely, a role β iykyk terminology matters). but here's the tea: only superusers and users with CREATEROLE privilege can create new users. so whoever runs createuser has to be able to connect as a superuser or as a user with CREATEROLE privilege. no cap.
if you wanna create a role with the SUPERUSER, REPLICATION, or BYPASSRLS privilege, you must connect as a superuser β being merely CREATEROLE is not enough. and like, being a superuser implies the ability to bypass all access permission checks within the database, so superuser access should not be granted lightly, fr fr. CREATEROLE also conveys very extensive privileges.
createuser is just a wrapper around the SQL command CREATE ROLE. there is no effective difference between creating users via this utility and via other methods for accessing the server. it's giving convenience β¨
π OPTIONS π
createuser accepts the following command-line arguments:
the main character options π
usernameβ specifies the name of the PostgreSQL user to be created. this name must be different from all existing roles in this PostgreSQL installation.-a role,--with-admin=roleβ specifies an existing role that will be automatically added as a member of the new role with admin option, giving it the right to grant membership in the new role to others. multiple existing roles can be specified by writing multiple-aswitches.-c number,--connection-limit=numberβ set a maximum number of connections for the new user. the default is to set no limit.-d,--createdbβ the new user will be allowed to create databases.-D,--no-createdbβ the new user will not be allowed to create databases. this is the default.-e,--echoβ echo the commands thatcreateusergenerates and sends to the server.-E,--encryptedβ this option is obsolete but still accepted for backward compatibility. (it's giving legacy vibes π)-g role,--member-of=role,--role=role(deprecated) β specifies the new role should be automatically added as a member of the specified existing role. multiple existing roles can be specified by writing multiple-gswitches.-i,--inheritβ the new role will automatically inherit privileges of roles it is a member of. this is the default.-I,--no-inheritβ the new role will not automatically inherit privileges of roles it is a member of.--interactiveβ prompt for the user name if none is specified on the command line, and also prompt for whichever of the options-d/-D,-r/-R,-s/-Sis not specified on the command line. (this was the default behavior up to PostgreSQL 9.1 β ancient history bestie πΊ)-l,--loginβ the new user will be allowed to log in (that is, the user name can be used as the initial session user identifier). this is the default.-L,--no-loginβ the new user will not be allowed to log in. (a role without login privilege is still useful as a means of managing database permissions β so it's not useless, just different π )-m role,--with-member=roleβ specifies an existing role that will be automatically added as a member of the new role. multiple existing roles can be specified by writing multiple-mswitches.-P,--pwpromptβ if given,createuserwill issue a prompt for the password of the new user. this is not necessary if you do not plan on using password authentication.-r,--createroleβ the new user will be allowed to create, alter, drop, comment on, change the security label for other roles; that is, this user will haveCREATEROLEprivilege. see role creation for more details about what capabilities are conferred by this privilege.-R,--no-createroleβ the new user will not be allowed to create new roles. this is the default.-s,--superuserβ the new user will be a superuser. (big power energy π)-S,--no-superuserβ the new user will not be a superuser. this is the default.-v timestamp,--valid-until=timestampβ set a date and time after which the role's password is no longer valid. the default is to set no password expiry date.-V,--versionβ print thecreateuserversion and exit.--bypassrlsβ the new user will bypass every row-level security (RLS) policy. (skirt the rules, iconic but dangerous π¨)--no-bypassrlsβ the new user will not bypass row-level security (RLS) policies. this is the default.--replicationβ the new user will have theREPLICATIONprivilege, which is described more fully in the documentation forCREATE ROLE(CREATE_ROLE(7)).--no-replicationβ the new user will not have theREPLICATIONprivilege, which is described more fully in the documentation forCREATE ROLE(CREATE_ROLE(7)). this is the default.-?,--helpβ show help aboutcreateusercommand line arguments, and exit.
connection era (for linking up to the server) π
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 server is running. if the value begins with a slash, it is used as the directory for the Unix domain socket.-p port,--port=portβ specifies the TCP 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 β don't get it twisted π).-w,--no-passwordβ never issue a password prompt. if the server requires password authentication and a password is not available by other means such as a.pgpassfile, the connection attempt will fail. this option can be useful in batch jobs and scripts where no user is present to enter a password.-W,--passwordβ forcecreateuserto prompt for a password (for connecting to the server, not for the password of the new user).
this option is never essential, since createuser will automatically prompt for a password if the server demands password authentication. however, createuser will waste a connection attempt finding out that the server wants a password. in some cases it is worth typing -W to avoid the extra connection attempt. (efficiency queen β¨)
π ENVIRONMENT π
PGHOSTPGPORTPGUSER
default connection parameters
PG_COLOR
specifies whether to use color in diagnostic messages. possible values are always, auto and never.
this utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 34.15).
π DIAGNOSTICS π
in case of difficulty, see CREATE ROLE (CREATE_ROLE(7)) and psql(1) for discussions of potential problems and error messages. the database server must be running at the targeted host. also, any default connection settings and environment variables used by the libpq front-end library will apply.
π EXAMPLES π
to create a user joe on the default database server:
$ createuser joe
to create a user joe on the default database server with prompting for some additional attributes:
$ createuser --interactive joe
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n
to create the same user joe using the server on host eden, port 5000, with attributes explicitly specified, taking a look at the underlying command:
$ createuser -h eden -p 5000 -S -D -R -e joe
CREATE ROLE joe NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;
to create the user joe as a superuser, and assign a password immediately:
$ createuser -P -s -e joe
Enter password for new role: xyzzy
Enter it again: xyzzy
CREATE ROLE joe PASSWORD 'SCRAM-SHA-256$4096:44560wPMLfjqiAzyPDZ/eQ==$4CA054rZlSFEq8Z3FEhToBTa2X6KnWFxFkPwIbKoDe0=:L/nbSZRCjp6RhOhKK56GoR1zibCCSePKshCJ9lnl3yw=' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS;
in the above example, the new password isn't actually echoed when typed, but we show what was typed for clarity. as you see, the password is encrypted before it is sent to the client. (security bestie, we love to see it π)
π§ SEE ALSO π§
dropuser(1), CREATE ROLE (CREATE_ROLE(7)), createrole_self_grant
and that's the whole vibe, bestie! this page is from PostgreSQL 16.15 and it's dated 2026. now go create those roles with confidence β¨ππ¦
π¦ where this page comes from
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms