]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/createuser.sgml
Create a "sort support" interface API for faster sorting.
[postgresql] / doc / src / sgml / ref / createuser.sgml
1 <!--
2 doc/src/sgml/ref/createuser.sgml
3 PostgreSQL documentation
4 -->
5
6 <refentry id="APP-CREATEUSER">
7  <refmeta>
8   <refentrytitle><application>createuser</application></refentrytitle>
9   <manvolnum>1</manvolnum>
10   <refmiscinfo>Application</refmiscinfo>
11  </refmeta>
12
13  <refnamediv>
14   <refname>createuser</refname>
15   <refpurpose>define a new <productname>PostgreSQL</productname> user account</refpurpose>
16  </refnamediv>
17
18  <indexterm zone="app-createuser">
19   <primary>createuser</primary>
20  </indexterm>
21
22  <refsynopsisdiv>
23   <cmdsynopsis>
24    <command>createuser</command>
25    <arg rep="repeat"><replaceable>connection-option</replaceable></arg>
26    <arg rep="repeat"><replaceable>option</replaceable></arg>
27    <arg><replaceable>username</replaceable></arg>
28   </cmdsynopsis>
29  </refsynopsisdiv>
30
31
32  <refsect1>
33   <title>Description</title>
34   <para>
35    <application>createuser</application> creates a
36    new <productname>PostgreSQL</productname> user (or more precisely, a role).
37    Only superusers and users with <literal>CREATEROLE</> privilege can create
38    new users, so <application>createuser</application> must be
39    invoked by someone who can connect as a superuser or a user with
40    <literal>CREATEROLE</> privilege.
41   </para>
42
43   <para>
44    If you wish to create a new superuser, you must connect as a
45    superuser, not merely with <literal>CREATEROLE</> privilege.
46    Being a superuser implies the ability to bypass all access permission
47    checks within the database, so superuserdom should not be granted lightly.
48   </para>
49
50   <para>
51    <application>createuser</application> is a wrapper around the
52    <acronym>SQL</acronym> command <xref linkend="SQL-CREATEROLE">.
53    There is no effective difference between creating users via
54    this utility and via other methods for accessing the server.
55   </para>
56
57  </refsect1>
58
59
60  <refsect1>
61   <title>Options</title>
62
63   <para>
64    <application>createuser</> accepts the following command-line arguments:
65
66     <variablelist>
67      <varlistentry>
68       <term><replaceable class="parameter">username</replaceable></term>
69       <listitem>
70        <para>
71         Specifies the name of the <productname>PostgreSQL</productname> user
72         to be created.
73         This name must be different from all existing roles in this
74         <productname>PostgreSQL</productname> installation.
75        </para>
76       </listitem>
77      </varlistentry>
78
79      <varlistentry>
80       <term><option>-c <replaceable class="parameter">number</replaceable></></term>
81       <term><option>--connection-limit=<replaceable class="parameter">number</replaceable></></term>
82       <listitem>
83        <para>
84         Set a maximum number of connections for the new user.
85         The default is to set no limit.
86        </para>
87       </listitem>
88      </varlistentry>
89
90      <varlistentry>
91       <term><option>-d</></term>
92       <term><option>--createdb</></term>
93       <listitem>
94        <para>
95         The new user will be allowed to create databases.
96        </para>
97       </listitem>
98      </varlistentry>
99
100      <varlistentry>
101       <term><option>-D</></term>
102       <term><option>--no-createdb</></term>
103       <listitem>
104        <para>
105         The new user will not be allowed to create databases.
106        </para>
107       </listitem>
108      </varlistentry>
109
110      <varlistentry>
111       <term><option>-e</></term>
112       <term><option>--echo</></term>
113       <listitem>
114        <para>
115         Echo the commands that <application>createuser</application> generates
116         and sends to the server.
117        </para>
118       </listitem>
119      </varlistentry>
120
121      <varlistentry>
122       <term><option>-E</></term>
123       <term><option>--encrypted</></term>
124       <listitem>
125        <para>
126         Encrypts the user's password stored in the database. If not
127         specified, the default password behavior is used.
128        </para>
129       </listitem>
130      </varlistentry>
131
132      <varlistentry>
133       <term><option>-i</></term>
134       <term><option>--inherit</></term>
135       <listitem>
136        <para>
137         The new role will automatically inherit privileges of roles
138         it is a member of.
139         This is the default.
140        </para>
141       </listitem>
142      </varlistentry>
143
144      <varlistentry>
145       <term><option>-I</></term>
146       <term><option>--no-inherit</></term>
147       <listitem>
148        <para>
149         The new role will not automatically inherit privileges of roles
150         it is a member of.
151        </para>
152       </listitem>
153      </varlistentry>
154
155      <varlistentry>
156       <term><option>-l</></term>
157       <term><option>--login</></term>
158       <listitem>
159        <para>
160         The new user will be allowed to log in (that is, the user name
161         can be used as the initial session user identifier).
162         This is the default.
163        </para>
164       </listitem>
165      </varlistentry>
166
167      <varlistentry>
168       <term><option>-L</></term>
169       <term><option>--no-login</></term>
170       <listitem>
171        <para>
172         The new user will not be allowed to log in.
173         (A role without login privilege is still useful as a means of
174         managing database permissions.)
175        </para>
176       </listitem>
177      </varlistentry>
178
179      <varlistentry>
180       <term><option>-N</></term>
181       <term><option>--unencrypted</></term>
182       <listitem>
183        <para>
184         Does not encrypt the user's password stored in the database. If
185         not specified, the default password behavior is used.
186        </para>
187       </listitem>
188      </varlistentry>
189
190      <varlistentry>
191       <term><option>-P</></term>
192       <term><option>--pwprompt</></term>
193       <listitem>
194        <para>
195        If given, <application>createuser</application> will issue a prompt for
196        the password of the new user. This is not necessary if you do not plan
197        on using password authentication.
198        </para>
199       </listitem>
200      </varlistentry>
201
202      <varlistentry>
203       <term><option>-r</></term>
204       <term><option>--createrole</></term>
205       <listitem>
206        <para>
207         The new user will be allowed to create new roles (that is,
208         this user will have <literal>CREATEROLE</> privilege).
209        </para>
210       </listitem>
211      </varlistentry>
212
213      <varlistentry>
214       <term><option>-R</></term>
215       <term><option>--no-createrole</></term>
216       <listitem>
217        <para>
218         The new user will not be allowed to create new roles.
219        </para>
220       </listitem>
221      </varlistentry>
222
223      <varlistentry>
224       <term><option>-s</></term>
225       <term><option>--superuser</></term>
226       <listitem>
227        <para>
228         The new user will be a superuser.
229        </para>
230       </listitem>
231      </varlistentry>
232
233      <varlistentry>
234       <term><option>-S</></term>
235       <term><option>--no-superuser</></term>
236       <listitem>
237        <para>
238         The new user will not be a superuser.
239        </para>
240       </listitem>
241      </varlistentry>
242
243      <varlistentry>
244       <term><option>--replication</></term>
245       <listitem>
246        <para>
247         The new user will have the REPLICATION privilege, which is
248         described more fully in the documentation for 
249         <xref linkend="sql-createrole">.
250        </para>
251       </listitem>
252      </varlistentry>
253
254      <varlistentry>
255       <term><option>--no-replication</></term>
256       <listitem>
257        <para>
258         The new user will not have the REPLICATION privilege, which is
259         described more fully in the documentation for 
260         <xref linkend="sql-createrole">.
261        </para>
262       </listitem>
263      </varlistentry>
264
265      <varlistentry>
266        <term><option>-V</></term>
267        <term><option>--version</></term>
268        <listitem>
269        <para>
270        Print the <application>createuser</application> version and exit.
271        </para>
272        </listitem>
273      </varlistentry>
274
275      <varlistentry>
276        <term><option>-?</></term>
277        <term><option>--help</></term>
278        <listitem>
279        <para>
280        Show help about <application>createuser</application> command line
281        arguments, and exit.
282        </para>
283        </listitem>
284      </varlistentry>
285
286     </variablelist>
287   </para>
288
289   <para>
290    You will be prompted for a name and other missing information if it
291    is not specified on the command line.
292   </para>
293
294   <para>
295    <application>createuser</application> also accepts the following
296    command-line arguments for connection parameters:
297
298    <variablelist>
299      <varlistentry>
300       <term><option>-h <replaceable class="parameter">host</replaceable></></term>
301       <term><option>--host=<replaceable class="parameter">host</replaceable></></term>
302       <listitem>
303        <para>
304         Specifies the host name of the machine on which the
305         server
306         is running.  If the value begins with a slash, it is used
307         as the directory for the Unix domain socket.
308        </para>
309       </listitem>
310      </varlistentry>
311
312      <varlistentry>
313       <term><option>-p <replaceable class="parameter">port</replaceable></></term>
314       <term><option>--port=<replaceable class="parameter">port</replaceable></></term>
315       <listitem>
316        <para>
317         Specifies the TCP port or local Unix domain socket file
318         extension on which the server
319         is listening for connections.
320        </para>
321       </listitem>
322      </varlistentry>
323
324      <varlistentry>
325       <term><option>-U <replaceable class="parameter">username</replaceable></></term>
326       <term><option>--username=<replaceable class="parameter">username</replaceable></></term>
327       <listitem>
328        <para>
329         User name to connect as (not the user name to create).
330        </para>
331       </listitem>
332      </varlistentry>
333
334      <varlistentry>
335       <term><option>-w</></term>
336       <term><option>--no-password</></term>
337       <listitem>
338        <para>
339         Never issue a password prompt.  If the server requires
340         password authentication and a password is not available by
341         other means such as a <filename>.pgpass</filename> file, the
342         connection attempt will fail.  This option can be useful in
343         batch jobs and scripts where no user is present to enter a
344         password.
345        </para>
346       </listitem>
347      </varlistentry>
348
349      <varlistentry>
350       <term><option>-W</></term>
351       <term><option>--password</></term>
352       <listitem>
353        <para>
354         Force <application>createuser</application> to prompt for a
355         password (for connecting to the server, not for the
356         password of the new user).
357        </para>
358
359        <para>
360         This option is never essential, since
361         <application>createuser</application> will automatically prompt
362         for a password if the server demands password authentication.
363         However, <application>createuser</application> will waste a
364         connection attempt finding out that the server wants a password.
365         In some cases it is worth typing <option>-W</> to avoid the extra
366         connection attempt.
367        </para>
368       </listitem>
369      </varlistentry>
370    </variablelist>
371   </para>
372  </refsect1>
373
374
375  <refsect1>
376   <title>Environment</title>
377
378   <variablelist>
379    <varlistentry>
380     <term><envar>PGHOST</envar></term>
381     <term><envar>PGPORT</envar></term>
382     <term><envar>PGUSER</envar></term>
383
384     <listitem>
385      <para>
386       Default connection parameters
387      </para>
388     </listitem>
389    </varlistentry>
390   </variablelist>
391
392   <para>
393    This utility, like most other <productname>PostgreSQL</> utilities,
394    also uses the environment variables supported by <application>libpq</>
395    (see <xref linkend="libpq-envars">).
396   </para>
397
398  </refsect1>
399
400
401  <refsect1>
402   <title>Diagnostics</title>
403
404   <para>
405    In case of difficulty, see <xref linkend="SQL-CREATEROLE">
406    and <xref linkend="APP-PSQL"> for
407    discussions of potential problems and error messages.
408    The database server must be running at the
409    targeted host.  Also, any default connection settings and environment
410    variables used by the <application>libpq</application> front-end
411    library will apply.
412   </para>
413
414  </refsect1>
415
416
417  <refsect1>
418   <title>Examples</title>
419
420    <para>
421     To create a user <literal>joe</literal> on the default database
422     server:
423 <screen>
424 <prompt>$ </prompt><userinput>createuser joe</userinput>
425 <computeroutput>Shall the new role be a superuser? (y/n) </computeroutput><userinput>n</userinput>
426 <computeroutput>Shall the new role be allowed to create databases? (y/n) </computeroutput><userinput>n</userinput>
427 <computeroutput>Shall the new role be allowed to create more new roles? (y/n) </computeroutput><userinput>n</userinput>
428 </screen>
429    </para>
430
431    <para>
432     To create the same user <literal>joe</literal> using the
433     server on host <literal>eden</>, port 5000, avoiding the prompts and
434     taking a look at the underlying command:
435 <screen>
436 <prompt>$ </prompt><userinput>createuser -h eden -p 5000 -S -D -R -e joe</userinput>
437 <computeroutput>CREATE ROLE joe NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;</computeroutput>
438 </screen>
439    </para>
440
441    <para>
442     To create the user <literal>joe</literal> as a superuser,
443     and assign a password immediately:
444 <screen>
445 <prompt>$ </prompt><userinput>createuser -P -s -e joe</userinput>
446 <computeroutput>Enter password for new role: </computeroutput><userinput>xyzzy</userinput>
447 <computeroutput>Enter it again: </computeroutput><userinput>xyzzy</userinput>
448 <computeroutput>CREATE ROLE joe PASSWORD 'md5b5f5ba1a423792b526f799ae4eb3d59e' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;</computeroutput>
449 </screen>
450     In the above example, the new password isn't actually echoed when typed,
451     but we show what was typed for clarity.  As you see, the password is
452     encrypted before it is sent to the client.  If the option <option>--unencrypted</option>
453     is used, the password <emphasis>will</> appear in the echoed command
454     (and possibly also in the server log and elsewhere),
455     so you don't want to use <option>-e</> in that case, if
456     anyone else can see your screen.
457    </para>
458  </refsect1>
459
460
461  <refsect1>
462   <title>See Also</title>
463
464   <simplelist type="inline">
465    <member><xref linkend="app-dropuser"></member>
466    <member><xref linkend="sql-createrole"></member>
467   </simplelist>
468  </refsect1>
469
470 </refentry>