CREATEUSER(1)
β¨ CREATEUSER β the "make a new bestie role" tool β¨
okay so this is the createuser(1) page from the PostgreSQL 17.11 docs, and honestly? it's giving "little utility, big responsibility." let's get into it π«Ά
π NAME π
createuser β define a new PostgreSQL user account. that's the whole vibe. one job. slay.
πΈ SYNOPSIS πΈ
createuser [connection-option...] [option...] [username]
look at her. so clean. so simple. so many flags hiding in those brackets. π
π¦ DESCRIPTION π¦
so createuser creates a brand-new PostgreSQL user β or, to be more precise (and the docs are precise, periodt), a role. yes bestie, users are roles, roles are users, it's all the same thing underneath. iykyk.
here's the catch though: only superusers and users with CREATEROLE privilege can create new users. so like⦠you can't just roll up and make accounts. createuser has to be invoked by someone who can connect as a superuser or as a user with CREATEROLE privilege. no cap.
β οΈ okay important tea β β if you wanna create a role with theSUPERUSER,REPLICATION, orBYPASSRLSprivilege, you must connect as a superuser, not merely withCREATEROLEprivilege. being a superuser implies the ability to bypass all access permission checks within the database, so superuser access should not be granted lightly. andCREATEROLEalso conveys very extensive privileges. likeβ¦ be careful who you hand the keys to. π
createuser is really 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. same energy, different font. π
π OPTIONS π
createuser accepts the following command-line arguments:
the main character args π
usernameβ specifies the name of the PostgreSQL user to be created. this name must be different from all existing roles in this PostgreSQL installation. no duplicates allowed, we don't do that here. π-arole,--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. you can specify multiple existing roles by writing multiple-aswitches. stack 'em. π-cnumber,--connection-limit=numberβ set a maximum number of connections for the new user. the default is to set no limit. unlimited everything, main character energy. π₯-d,--createdbβ the new user will be allowed to create databases. go off bestie π-D,--no-createdbβ the new user will not be allowed to create databases. this is the default. (sad but responsible.)-e,--echoβ echo the commands thatcreateusergenerates and sends to the server. transparency icon β¨-E,--encryptedβ this option is obsolete but still accepted for backward compatibility. she's retired but she still shows up to the party π-grole,--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. note that--role=roleis the deprecated spelling β still works, but like, we've moved on. π¦-i,--inheritβ the new role will automatically inherit privileges of roles it is a member of. this is the default. generational wealth of permissions. π-I,--no-inheritβ the new role will not automatically inherit privileges of roles it is a member of. independent queen. no hand-me-downs.--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 β yes bestie, ancient history. πΊ)-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. she can come to the function π-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 yes, she has purpose even without an invite. π«Ά)-mrole,--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. look at-aand-mbeing cousins. cute.-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. no password, no prompt, no stress. π-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. big power, big responsibility fr fr.-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. absolute maximum power. use wisely, i'm begging π-S,--no-superuserβ the new user will not be a superuser. this is the default. safe and sound π-vtimestamp,--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. forever girlies, this one's for you π-V,--versionβ print thecreateuserversion and exit. short and sweet.--bypassrlsβ the new user will bypass every row-level security (RLS) policy. every single one. she sees all. π--no-bypassrlsβ the new user will not bypass row-level security (RLS) policies. this is the default. normal behaviour, love that for her πΈ--replicationβ the new user will have theREPLICATIONprivilege, which is described more fully in the documentation forCREATE ROLE(CREATE_ROLE(7)). copy that, replicate that π§--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. when in doubt, ask for help bestie π
connection-parameter args π
createuser also accepts the following command-line arguments for connection parameters:
-hhost,--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. slash = socket directory, that's the rule π¦-pport,--port=portβ specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections.-Uusername,--username=usernameβ user name to connect as (not the user name to create). ok this one trips everyone up so let's say it together: this is the connector, not the connectee. π-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. automation bestie π€-W,--passwordβ forcecreateuserto prompt for a password (for connecting to the server, not for the password of the new user). careful, they're two different passwords and the docs are very clear about it π
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. save yourself the round trip, queen π₯
π§ ENVIRONMENT π§
PGHOSTPGPORTPGUSER
default connection parameters. the trio. the holy trinity. π«Ά
PG_COLORβ specifies whether to use color in diagnostic messages. possible values arealways,autoandnever. yes, your error messages can be pretty π
this utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 32.15). so many env vars, so little time π
β 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 β yes, it has to actually be on, that's the vibe check. 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. safety first, always π
π SEE ALSO π
dropuser(1), CREATE ROLE (CREATE_ROLE(7)), createrole_self_grant
and that's the whole page, bestie. this was PostgreSQL 17.11, dated 2026, and honestly? iconic documentation behaviour. go forth and make roles responsibly. π β¨ππ¦πΈπ«Ά
π¦ where this page comes from
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-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