4 createuser — define a new PostgreSQL user account
8 createuser [connection-option...] [option...] [username]
12 createuser creates a new PostgreSQL user (or more precisely, a role).
13 Only superusers and users with CREATEROLE privilege can create new
14 users, so createuser must be invoked by someone who can connect as a
15 superuser or a user with CREATEROLE privilege.
17 If you wish to create a role with the SUPERUSER, REPLICATION, or
18 BYPASSRLS privilege, you must connect as a superuser, not merely with
19 CREATEROLE privilege. Being a superuser implies the ability to bypass
20 all access permission checks within the database, so superuser access
21 should not be granted lightly. CREATEROLE also conveys very extensive
24 createuser is a wrapper around the SQL command CREATE ROLE. There is no
25 effective difference between creating users via this utility and via
26 other methods for accessing the server.
30 createuser accepts the following command-line arguments:
33 Specifies the name of the PostgreSQL user to be created. This
34 name must be different from all existing roles in this
35 PostgreSQL installation.
39 Specifies an existing role that will be automatically added as a
40 member of the new role with admin option, giving it the right to
41 grant membership in the new role to others. Multiple existing
42 roles can be specified by writing multiple -a switches.
45 --connection-limit=number
46 Set a maximum number of connections for the new user. The
47 default is to set no limit.
51 The new user will be allowed to create databases.
55 The new user will not be allowed to create databases. This is
60 Echo the commands that createuser generates and sends to the
65 This option is obsolete but still accepted for backward
70 --role=role (deprecated)
71 Specifies the new role should be automatically added as a member
72 of the specified existing role. Multiple existing roles can be
73 specified by writing multiple -g switches.
77 The new role will automatically inherit privileges of roles it
78 is a member of. This is the default.
82 The new role will not automatically inherit privileges of roles
86 Prompt for the user name if none is specified on the command
87 line, and also prompt for whichever of the options -d/-D, -r/-R,
88 -s/-S is not specified on the command line. (This was the
89 default behavior up to PostgreSQL 9.1.)
93 The new user will be allowed to log in (that is, the user name
94 can be used as the initial session user identifier). This is the
99 The new user will not be allowed to log in. (A role without
100 login privilege is still useful as a means of managing database
105 Specifies an existing role that will be automatically added as a
106 member of the new role. Multiple existing roles can be specified
107 by writing multiple -m switches.
111 If given, createuser will issue a prompt for the password of the
112 new user. This is not necessary if you do not plan on using
113 password authentication.
117 The new user will be allowed to create, alter, drop, comment on,
118 change the security label for other roles; that is, this user
119 will have CREATEROLE privilege. See role creation for more
120 details about what capabilities are conferred by this privilege.
124 The new user will not be allowed to create new roles. This is
129 The new user will be a superuser.
133 The new user will not be a superuser. This is the default.
136 --valid-until=timestamp
137 Set a date and time after which the role's password is no longer
138 valid. The default is to set no password expiry date.
142 Print the createuser version and exit.
145 The new user will bypass every row-level security (RLS) policy.
148 The new user will not bypass row-level security (RLS) policies.
152 The new user will have the REPLICATION privilege, which is
153 described more fully in the documentation for CREATE ROLE.
156 The new user will not have the REPLICATION privilege, which is
157 described more fully in the documentation for CREATE ROLE. This
162 Show help about createuser command line arguments, and exit.
164 createuser also accepts the following command-line arguments for
165 connection parameters:
169 Specifies the host name of the machine on which the server is
170 running. If the value begins with a slash, it is used as the
171 directory for the Unix domain socket.
175 Specifies the TCP port or local Unix domain socket file
176 extension on which the server is listening for connections.
180 User name to connect as (not the user name to create).
184 Never issue a password prompt. If the server requires password
185 authentication and a password is not available by other means
186 such as a .pgpass file, the connection attempt will fail. This
187 option can be useful in batch jobs and scripts where no user is
188 present to enter a password.
192 Force createuser to prompt for a password (for connecting to the
193 server, not for the password of the new user).
195 This option is never essential, since createuser will
196 automatically prompt for a password if the server demands
197 password authentication. However, createuser will waste a
198 connection attempt finding out that the server wants a password.
199 In some cases it is worth typing -W to avoid the extra
207 Default connection parameters
210 Specifies whether to use color in diagnostic messages. Possible
211 values are always, auto and never.
213 This utility, like most other PostgreSQL utilities, also uses the
214 environment variables supported by libpq (see Section 32.15).
218 In case of difficulty, see CREATE ROLE and psql for discussions of
219 potential problems and error messages. The database server must be
220 running at the targeted host. Also, any default connection settings and
221 environment variables used by the libpq front-end library will apply.
225 To create a user joe on the default database server:
228 To create a user joe on the default database server with prompting for
229 some additional attributes:
230 $ createuser --interactive joe
231 Shall the new role be a superuser? (y/n) n
232 Shall the new role be allowed to create databases? (y/n) n
233 Shall the new role be allowed to create more new roles? (y/n) n
235 To create the same user joe using the server on host eden, port 5000,
236 with attributes explicitly specified, taking a look at the underlying
238 $ createuser -h eden -p 5000 -S -D -R -e joe
239 CREATE ROLE joe NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;
241 To create the user joe as a superuser, and assign a password
243 $ createuser -P -s -e joe
244 Enter password for new role: xyzzy
245 Enter it again: xyzzy
246 CREATE ROLE joe PASSWORD 'md5b5f5ba1a423792b526f799ae4eb3d59e' SUPERUSER CREATED
247 B CREATEROLE INHERIT LOGIN;
249 In the above example, the new password isn't actually echoed when
250 typed, but we show what was typed for clarity. As you see, the password
251 is encrypted before it is sent to the client.
255 dropuser, CREATE ROLE, createrole_self_grant