3 PostgreSQL documentation
6 <refentry id=
"APP-CREATEUSER">
8 <refentrytitle id=
"APP-CREATEUSER-TITLE"><application>createuser
</application></refentrytitle>
9 <manvolnum>1</manvolnum>
10 <refmiscinfo>Application
</refmiscinfo>
14 <refname>createuser
</refname>
15 <refpurpose>define a new
<productname>PostgreSQL
</productname> user account
</refpurpose>
18 <indexterm zone=
"app-createuser">
19 <primary>createuser
</primary>
24 <command>createuser
</command>
25 <arg rep=
"repeat"><replaceable>option
</replaceable></arg>
26 <arg><replaceable>username
</replaceable></arg>
32 <title>Description
</title>
34 <application>createuser
</application> creates a
35 new
<productname>PostgreSQL
</productname> user (or more precisely, a role).
36 Only superusers and users with
<literal>CREATEROLE<
/> privilege can create
37 new users, so
<application>createuser
</application> must be
38 invoked by someone who can connect as a superuser or a user with
39 <literal>CREATEROLE<
/> privilege.
43 If you wish to create a new superuser, you must connect as a
44 superuser, not merely with
<literal>CREATEROLE<
/> privilege.
45 Being a superuser implies the ability to bypass all access permission
46 checks within the database, so superuserdom should not be granted lightly.
50 <application>createuser
</application> is a wrapper around the
51 <acronym>SQL
</acronym> command
<xref linkend=
"SQL-CREATEROLE"
52 endterm=
"SQL-CREATEROLE-title">.
53 There is no effective difference between creating users via
54 this utility and via other methods for accessing the server.
61 <title>Options
</title>
64 <application>createuser<
/> accepts the following command-line arguments:
68 <term><replaceable class=
"parameter">username
</replaceable></term>
71 Specifies the name of the
<productname>PostgreSQL
</productname> user
73 This name must be different from all existing roles in this
74 <productname>PostgreSQL
</productname> installation.
80 <term><option>-s<
/></term>
81 <term><option>--superuser<
/></term>
84 The new user will be a superuser.
90 <term><option>-S<
/></term>
91 <term><option>--no-superuser<
/></term>
94 The new user will not be a superuser.
101 <term><option>-d<
/></term>
102 <term><option>--createdb<
/></term>
105 The new user will be allowed to create databases.
111 <term><option>-D<
/></term>
112 <term><option>--no-createdb<
/></term>
115 The new user will not be allowed to create databases.
122 <term><option>-r<
/></term>
123 <term><option>--createrole<
/></term>
126 The new user will be allowed to create new roles (that is,
127 this user will have
<literal>CREATEROLE<
/> privilege).
133 <term><option>-R<
/></term>
134 <term><option>--no-createrole<
/></term>
137 The new user will not be allowed to create new roles.
144 <term><option>-l<
/></term>
145 <term><option>--login<
/></term>
148 The new user will be allowed to log in (that is, the user name
149 can be used as the initial session user identifier).
156 <term><option>-L<
/></term>
157 <term><option>--no-login<
/></term>
160 The new user will not be allowed to log in.
161 (A role without login privilege is still useful as a means of
162 managing database permissions.)
168 <term><option>-i<
/></term>
169 <term><option>--inherit<
/></term>
172 The new role will automatically inherit privileges of roles
180 <term><option>-I<
/></term>
181 <term><option>--no-inherit<
/></term>
184 The new role will not automatically inherit privileges of roles
191 <term><option>-c
<replaceable class=
"parameter">number
</replaceable><
/></term>
192 <term><option>--connection-limit
<replaceable class=
"parameter">number
</replaceable><
/></term>
195 Set a maximum number of connections for the new user.
196 The default is to set no limit.
202 <term><option>-P<
/></term>
203 <term><option>--pwprompt<
/></term>
206 If given,
<application>createuser
</application> will issue a prompt for
207 the password of the new user. This is not necessary if you do not plan
208 on using password authentication.
214 <term><option>-E<
/></term>
215 <term><option>--encrypted<
/></term>
218 Encrypts the user's password stored in the database. If not
219 specified, the default password behavior is used.
225 <term><option>-N<
/></term>
226 <term><option>--unencrypted<
/></term>
229 Does not encrypt the user's password stored in the database. If
230 not specified, the default password behavior is used.
236 <term><option>-e<
/></term>
237 <term><option>--echo<
/></term>
240 Echo the commands that
<application>createuser
</application> generates
241 and sends to the server.
249 You will be prompted for a name and other missing information if it
250 is not specified on the command line.
254 <application>createuser
</application> also accepts the following
255 command-line arguments for connection parameters:
259 <term><option>-h
<replaceable class=
"parameter">host
</replaceable><
/></term>
260 <term><option>--host
<replaceable class=
"parameter">host
</replaceable><
/></term>
263 Specifies the host name of the machine on which the
265 is running. If the value begins with a slash, it is used
266 as the directory for the Unix domain socket.
272 <term><option>-p
<replaceable class=
"parameter">port
</replaceable><
/></term>
273 <term><option>--port
<replaceable class=
"parameter">port
</replaceable><
/></term>
276 Specifies the TCP port or local Unix domain socket file
277 extension on which the server
278 is listening for connections.
284 <term><option>-U
<replaceable class=
"parameter">username
</replaceable><
/></term>
285 <term><option>--username
<replaceable class=
"parameter">username
</replaceable><
/></term>
288 User name to connect as (not the user name to create).
294 <term><option>-w<
/></term>
295 <term><option>--no-password<
/></term>
298 Never issue a password prompt. If the server requires
299 password authentication and a password is not available by
300 other means such as a
<filename>.pgpass
</filename> file, the
301 connection attempt will fail. This option can be useful in
302 batch jobs and scripts where no user is present to enter a
309 <term><option>-W<
/></term>
310 <term><option>--password<
/></term>
313 Force
<application>createuser
</application> to prompt for a
314 password (for connecting to the server, not for the
315 password of the new user).
319 This option is never essential, since
320 <application>createuser
</application> will automatically prompt
321 for a password if the server demands password authentication.
322 However,
<application>createuser
</application> will waste a
323 connection attempt finding out that the server wants a password.
324 In some cases it is worth typing
<option>-W<
/> to avoid the extra
335 <title>Environment
</title>
339 <term><envar>PGHOST
</envar></term>
340 <term><envar>PGPORT
</envar></term>
341 <term><envar>PGUSER
</envar></term>
345 Default connection parameters
352 This utility, like most other
<productname>PostgreSQL<
/> utilities,
353 also uses the environment variables supported by
<application>libpq<
/>
354 (see
<xref linkend=
"libpq-envars">).
361 <title>Diagnostics
</title>
364 In case of difficulty, see
<xref linkend=
"SQL-CREATEROLE"
365 endterm=
"sql-createrole-title"> and
<xref linkend=
"APP-PSQL"> for
366 discussions of potential problems and error messages.
367 The database server must be running at the
368 targeted host. Also, any default connection settings and environment
369 variables used by the
<application>libpq
</application> front-end
377 <title>Examples
</title>
380 To create a user
<literal>joe
</literal> on the default database
383 <prompt>$
</prompt><userinput>createuser joe
</userinput>
384 <computeroutput>Shall the new role be a superuser? (y/n)
</computeroutput><userinput>n
</userinput>
385 <computeroutput>Shall the new role be allowed to create databases? (y/n)
</computeroutput><userinput>n
</userinput>
386 <computeroutput>Shall the new role be allowed to create more new roles? (y/n)
</computeroutput><userinput>n
</userinput>
391 To create the same user
<literal>joe
</literal> using the
392 server on host
<literal>eden<
/>, port
5000, avoiding the prompts and
393 taking a look at the underlying command:
395 <prompt>$
</prompt><userinput>createuser -h eden -p
5000 -S -D -R -e joe
</userinput>
396 <computeroutput>CREATE ROLE joe NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;
</computeroutput>
401 To create the user
<literal>joe
</literal> as a superuser,
402 and assign a password immediately:
404 <prompt>$
</prompt><userinput>createuser -P -s -e joe
</userinput>
405 <computeroutput>Enter password for new role:
</computeroutput><userinput>xyzzy
</userinput>
406 <computeroutput>Enter it again:
</computeroutput><userinput>xyzzy
</userinput>
407 <computeroutput>CREATE ROLE joe PASSWORD 'md5b5f5ba1a423792b526f799ae4eb3d59e' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;
</computeroutput>
409 In the above example, the new password isn't actually echoed when typed,
410 but we show what was typed for clarity. As you see, the password is
411 encrypted before it is sent to the client. If the option
<option>--unencrypted
</option>
412 is used, the password
<emphasis>will<
/> appear in the echoed command
413 (and possibly also in the server log and elsewhere),
414 so you don't want to use
<option>-e<
/> in that case, if
415 anyone else can see your screen.
421 <title>See Also
</title>
423 <simplelist type=
"inline">
424 <member><xref linkend=
"app-dropuser"></member>
425 <member><xref linkend=
"sql-createrole" endterm=
"sql-createrole-title"></member>