2 $PostgreSQL: pgsql/doc/src/sgml/ref/createuser.sgml,v 1.50 2007/06/21 12:20:10 petere Exp $
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>--password</></term>
298 Force password prompt (to connect to the server, not for the
299 password of the new user).
309 <title>Environment</title>
313 <term><envar>PGHOST</envar></term>
314 <term><envar>PGPORT</envar></term>
315 <term><envar>PGUSER</envar></term>
319 Default connection parameters
326 This utility, like most other <productname>PostgreSQL</> utilities,
327 also uses the environment variables supported by <application>libpq</>
328 (see <xref linkend="libpq-envars">).
335 <title>Diagnostics</title>
338 In case of difficulty, see <xref linkend="SQL-CREATEROLE"
339 endterm="sql-createrole-title"> and <xref linkend="APP-PSQL"> for
340 discussions of potential problems and error messages.
341 The database server must be running at the
342 targeted host. Also, any default connection settings and environment
343 variables used by the <application>libpq</application> front-end
351 <title>Examples</title>
354 To create a user <literal>joe</literal> on the default database
357 <prompt>$ </prompt><userinput>createuser joe</userinput>
358 <computeroutput>Shall the new role be a superuser? (y/n) </computeroutput><userinput>n</userinput>
359 <computeroutput>Shall the new role be allowed to create databases? (y/n) </computeroutput><userinput>n</userinput>
360 <computeroutput>Shall the new role be allowed to create more new roles? (y/n) </computeroutput><userinput>n</userinput>
365 To create the same user <literal>joe</literal> using the
366 server on host <literal>eden</>, port 5000, avoiding the prompts and
367 taking a look at the underlying command:
369 <prompt>$ </prompt><userinput>createuser -h eden -p 5000 -S -D -R -e joe</userinput>
370 <computeroutput>CREATE ROLE joe NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;</computeroutput>
375 To create the user <literal>joe</literal> as a superuser,
376 and assign a password immediately:
378 <prompt>$ </prompt><userinput>createuser -P -s -e joe</userinput>
379 <computeroutput>Enter password for new role: </computeroutput><userinput>xyzzy</userinput>
380 <computeroutput>Enter it again: </computeroutput><userinput>xyzzy</userinput>
381 <computeroutput>CREATE ROLE joe PASSWORD 'md5b5f5ba1a423792b526f799ae4eb3d59e' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;</computeroutput>
383 In the above example, the new password isn't actually echoed when typed,
384 but we show what was typed for clarity. As you see, the password is
385 encrypted before it is sent to the client. If the option <option>--unencrypted</option>
386 is used, the password <emphasis>will</> appear in the echoed command
387 (and possibly also in the server log and elsewhere),
388 so you don't want to use <option>-e</> in that case, if
389 anyone else can see your screen.
395 <title>See Also</title>
397 <simplelist type="inline">
398 <member><xref linkend="app-dropuser"></member>
399 <member><xref linkend="sql-createrole" endterm="sql-createrole-title"></member>