postgres-ref.sgml 14.2 KB
Newer Older
1
<!--
2
$Header: /cvsroot/pgsql/doc/src/sgml/ref/postgres-ref.sgml,v 1.33 2003/05/02 20:54:33 tgl Exp $
3
PostgreSQL documentation
4 5
-->

T
Thomas G. Lockhart 已提交
6 7
<refentry id="APP-POSTGRES">
 <refmeta>
8 9
  <refentrytitle id="APP-POSTGRES-TITLE"><application>postgres</application></refentrytitle>
  <manvolnum>1</manvolnum>
T
Thomas G. Lockhart 已提交
10 11
  <refmiscinfo>Application</refmiscinfo>
 </refmeta>
12

T
Thomas G. Lockhart 已提交
13
 <refnamediv>
14
  <refname>postgres</refname>
15
  <refpurpose>run a <productname>PostgreSQL</productname> server in single-user mode</refpurpose>
T
Thomas G. Lockhart 已提交
16
 </refnamediv>
17

T
Thomas G. Lockhart 已提交
18
 <refsynopsisdiv>
19 20 21 22 23 24 25 26 27 28 29 30 31
  <cmdsynopsis>
   <!-- standalone call -->
   <command>postgres</command>
   <arg>-A <group choice="plain"><arg>0</arg><arg>1</arg></group></arg>
   <arg>-B <replaceable>nbuffers</replaceable></arg>
   <arg>-c <replaceable>name</replaceable>=<replaceable>value</replaceable></arg>
   <arg>-d <replaceable>debug-level</replaceable></arg>
   <arg>-D <replaceable>datadir</replaceable></arg>
   <arg>-e</arg>
   <arg>-E</arg>
   <arg>-f<group choice="plain"><arg>s</arg><arg>i</arg><arg>t</arg><arg>n</arg><arg>m</arg><arg>h</arg></group></arg>
   <arg>-F</arg>
   <arg>-N</arg>
32
   <arg>-o <replaceable>filename</replaceable></arg>
33 34 35 36 37 38 39 40
   <arg>-O</arg>
   <arg>-P</arg>
   <group>
    <arg>-s</arg>
    <arg>-t<group choice="plain"><arg>pa</arg><arg>pl</arg><arg>ex</arg></group></arg>
   </group>
   <arg>-S <replaceable>sort-mem</replaceable></arg>
   <arg>-W <replaceable>seconds</replaceable></arg>
41
   <arg>--<replaceable>name</replaceable>=<replaceable>value</replaceable></arg>
42 43 44 45 46 47 48 49 50 51 52 53
   <arg choice="plain"><replaceable>database</replaceable></arg>
   <sbr>
   <!-- postmaster fork -->
   <command>postgres</command>
   <arg>-A <group choice="plain"><arg>0</arg><arg>1</arg></group></arg>
   <arg>-B <replaceable>nbuffers</replaceable></arg>
   <arg>-c <replaceable>name</replaceable>=<replaceable>value</replaceable></arg>
   <arg>-d <replaceable>debug-level</replaceable></arg>
   <arg>-D <replaceable>datadir</replaceable></arg>
   <arg>-e</arg>
   <arg>-f<group choice="plain"><arg>s</arg><arg>i</arg><arg>t</arg><arg>n</arg><arg>m</arg><arg>h</arg></group></arg>
   <arg>-F</arg>
54
   <arg>-o <replaceable>filename</replaceable></arg>
55 56 57 58 59 60 61 62
   <arg>-O</arg>
   <arg>-p <replaceable>database</replaceable></arg>
   <arg>-P</arg>
   <group>
    <arg>-s</arg>
    <arg>-t<group choice="plain"><arg>pa</arg><arg>pl</arg><arg>ex</arg></group></arg>
   </group>
   <arg>-S <replaceable>sort-mem</replaceable></arg>
63
   <arg>-v <replaceable>protocol</replaceable></arg>
64
   <arg>-W <replaceable>seconds</replaceable></arg>
65
   <arg>--<replaceable>name</replaceable>=<replaceable>value</replaceable></arg>
66 67
  </cmdsynopsis>
 </refsynopsisdiv>
T
Thomas G. Lockhart 已提交
68

69 70
 <refsect1>
  <title>Description</title>
T
Thomas G. Lockhart 已提交
71

72
  <para>
73
   The <command>postgres</command> executable is the actual
74
   <productname>PostgreSQL</productname> server process that processes
P
Peter Eisentraut 已提交
75
   queries.  It is normally not called directly; instead a <xref
76
   linkend="app-postmaster"> multiuser server is started.
P
Peter Eisentraut 已提交
77 78 79 80
  </para>

  <para>
   The second form above is how
81
   <command>postgres</command> is invoked by the <xref
82
   linkend="app-postmaster"> (only
83 84 85
   conceptually, since both <filename>postmaster</filename> and
   <filename>postgres</filename> are in fact the same program); it
   should not be invoked directly this way.  The first form invokes
86 87 88
   the server directly in interactive single-user mode.  The primary use
   for this mode is during bootstrapping by <xref linkend="app-initdb">.
   Sometimes it is used for debugging or disaster recovery.
89
  </para>
T
Thomas G. Lockhart 已提交
90

91 92 93 94
  <para>
   When invoked in interactive mode from the shell, the user can enter
   queries and the results will be printed to the screen, but in a
   form that is more useful for developers than end users.  But note
95
   that running a single-user server is not truly suitable for
P
Peter Eisentraut 已提交
96
   debugging the server since no realistic interprocess communication
97 98
   and locking will happen.
  </para>
T
Thomas G. Lockhart 已提交
99

100
  <para>
101
   When running a stand-alone server, the session user will be set to
P
Peter Eisentraut 已提交
102
   the user with ID 1.  This user does not actually have to exist, so
103
   a stand-alone server can be used to manually recover from certain
104
   kinds of accidental damage to the system catalogs.  Implicit
P
Peter Eisentraut 已提交
105
   superuser powers are granted to the user with ID 1 in stand-alone
106
   mode.
107
  </para>
P
Peter Eisentraut 已提交
108
 </refsect1>
T
Thomas G. Lockhart 已提交
109

P
Peter Eisentraut 已提交
110 111
 <refsect1>
  <title>Options</title>
T
Thomas G. Lockhart 已提交
112

113
   <para>
114
    When <command>postgres</command> is started by a <xref
115
    linkend="app-postmaster"> then it
116
    inherits all options set by the latter.  Additionally,
117 118
    <command>postgres</command>-specific options can be passed
    from the <command>postmaster</command> with the
119 120
    <option>-o</option> switch.
   </para>
121

122 123
   <para>
    You can avoid having to type these options by setting up a
124
    configuration file.  See <xref linkend="runtime-config"> for details.  Some
125 126 127 128
    (safe) options can also be set from the connecting client in an
    application-dependent way.  For example, if the environment
    variable <envar>PGOPTIONS</envar> is set, then
    <application>libpq</>-based clients will pass that string to the
129
    server, which will interpret it as
130
    <command>postgres</command> command-line options.
131
   </para>
T
Thomas G. Lockhart 已提交
132

P
Peter Eisentraut 已提交
133
   <refsect2>
134
    <title>General Purpose</title>
T
Thomas G. Lockhart 已提交
135

136 137 138
    <para>
     The options <option>-A</option>, <option>-B</option>,
     <option>-c</option>, <option>-d</option>, <option>-D</option>,
139
     <option>-F</option>, and <option>--<replaceable>name</></option> have the same meanings
140
     as the <xref linkend="app-postmaster"> except that
141 142
     <literal>-d 0</> prevents the server log level of
     the <command>postmaster</> from being propagated to <command>postgres</>.
143
    </para>
T
Thomas G. Lockhart 已提交
144

145
    <variablelist>
T
Thomas G. Lockhart 已提交
146
     <varlistentry>
147
      <term><option>-e</option></term>
T
Thomas G. Lockhart 已提交
148 149
      <listitem>
       <para>
150 151 152 153
        Sets the default date style to <quote>European</quote>, which
	means that the <quote>day before month</quote> (rather than
	month before day) rule is used to interpret ambiguous date
	input, and that the day is printed before the month in certain
154
	date output formats.  See <xref linkend="datatype-datetime"> for more information.
T
Thomas G. Lockhart 已提交
155 156 157 158 159
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
160
      <term><option>-o</option> <replaceable class="parameter">filename</replaceable></term>
T
Thomas G. Lockhart 已提交
161 162
      <listitem>
       <para>
163
	Send all server log output to 
164
	<replaceable class="parameter">filename</replaceable>.
165 166
	If <command>postgres</command> is running under the
	<command>postmaster</command>, this option is ignored,
167
	and the <systemitem>stderr</> inherited from the
168
	<command>postmaster</command> is used.
T
Thomas G. Lockhart 已提交
169 170 171 172
       </para>
      </listitem>
     </varlistentry>

173
     <varlistentry>
174
      <term><option>-P</option></term>
175 176
      <listitem>
       <para>
177
	Ignore system indexes while scanning/updating system tables. The
178 179 180 181 182 183
	<command>REINDEX</command> command for system tables/indexes
	requires this option to be used.
       </para>
      </listitem>
     </varlistentry>

T
Thomas G. Lockhart 已提交
184
     <varlistentry>
185
      <term><option>-s</option></term>
T
Thomas G. Lockhart 已提交
186 187
      <listitem>
       <para>
188
	Print time information and other statistics at the end of each command.
T
Thomas G. Lockhart 已提交
189 190 191 192 193 194 195
	This is useful for benchmarking or for use in tuning the number of
	buffers.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
196
      <term><option>-S</option> <replaceable class="parameter">sort-mem</replaceable></term>
T
Thomas G. Lockhart 已提交
197 198
      <listitem>
       <para>
199 200
	Specifies the amount of memory to be used by internal sorts and hashes
	before resorting to temporary disk files.  The value is specified in
201
	kilobytes, and defaults to 1024.  Note that for a complex query,
202 203 204 205
	several sorts and/or hashes might be running in parallel, and each one
	will be allowed to use as much as
	<replaceable class="parameter">sort-mem</replaceable> kilobytes
	before it starts to put data into temporary files.
T
Thomas G. Lockhart 已提交
206 207 208 209
       </para>
      </listitem>
     </varlistentry>

210
    </variablelist>
P
Peter Eisentraut 已提交
211
   </refsect2>
T
Thomas G. Lockhart 已提交
212

P
Peter Eisentraut 已提交
213
   <refsect2>
214
    <title>Options for stand-alone mode</title>
T
Thomas G. Lockhart 已提交
215 216 217

    <variablelist>
     <varlistentry>
218
      <term><replaceable class="parameter">database</replaceable></term>
T
Thomas G. Lockhart 已提交
219 220
      <listitem>
       <para>
221 222
	Specifies the name of the database to be accessed.  If it is
	omitted it defaults to the user name.	
T
Thomas G. Lockhart 已提交
223
       </para>
224 225
      </listitem>
     </varlistentry>
T
Thomas G. Lockhart 已提交
226 227

     <varlistentry>
228
      <term><option>-E</option></term>
T
Thomas G. Lockhart 已提交
229 230
      <listitem>
       <para>
231
	Echo all commands.
T
Thomas G. Lockhart 已提交
232 233 234 235 236
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
237
      <term><option>-N</option></term>
T
Thomas G. Lockhart 已提交
238 239
      <listitem>
       <para>
240
	Disables use of newline as a statement delimiter.
T
Thomas G. Lockhart 已提交
241 242 243
       </para>
      </listitem>
     </varlistentry>
244
    </variablelist>
P
Peter Eisentraut 已提交
245
   </refsect2>
246

P
Peter Eisentraut 已提交
247
   <refsect2>
248 249 250 251 252 253 254 255 256 257 258
    <title>Semi-internal Options</title>

    <para>
     There are several other options that may be specified, used
     mainly for debugging purposes.  These are listed here only for
     the use by <productname>PostgreSQL</productname> system
     developers.  <emphasis>Use of any of these options is highly
     discouraged.</emphasis>  Furthermore, any of these options may
     disappear or change in a future release without notice.
   </para>
    <variablelist>
T
Thomas G. Lockhart 已提交
259 260

     <varlistentry>
261
      <term><option>-f</option> <literal>{ s | i | m | n | h }</literal></term>
T
Thomas G. Lockhart 已提交
262 263 264 265 266 267 268
      <listitem>
       <para>
	Forbids the use of particular scan and join methods:
	<literal>s</literal> and <literal>i</literal>
	disable sequential and index scans respectively, while
	<literal>n</literal>, <literal>m</literal>, and <literal>h</literal>
	disable nested-loop, merge and hash joins respectively.
269
       </para>
T
Thomas G. Lockhart 已提交
270 271 272 273 274 275 276 277 278 279 280 281 282
	
	<note>
	 <para>
	  Neither sequential scans nor nested-loop joins can be disabled completely;
	  the <literal>-fs</literal> and <literal>-fn</literal>
	  options simply discourage the optimizer from using those
	  plan types if it has any other alternative.
	 </para>
	</note>
      </listitem>
     </varlistentry>

     <varlistentry>
283
      <term><option>-O</option></term>
T
Thomas G. Lockhart 已提交
284 285
      <listitem>
       <para>
286
	Allows the structure of system tables to be modified.  This is
287
	used by <command>initdb</command>.
T
Thomas G. Lockhart 已提交
288 289 290 291
       </para>
      </listitem>
     </varlistentry>

292
     <varlistentry>
293
      <term><option>-p</option> <replaceable class="parameter">database</replaceable></term>
294 295
      <listitem>
       <para>
296 297
	Indicates that this process has been started by a
	<command>postmaster</command> and specifies the database to use.
298 299 300 301
	etc.
       </para>
      </listitem>
     </varlistentry>
T
Thomas G. Lockhart 已提交
302 303

     <varlistentry>
304
      <term><option>-t</option> <literal>pa[rser] | pl[anner] | e[xecutor]</literal></term>
T
Thomas G. Lockhart 已提交
305 306
      <listitem>
       <para>
307 308 309 310 311 312
	Print timing statistics for each query relating to each of the
	major system modules.  This option cannot be used together
	with the <option>-s</option> option.
       </para>
      </listitem>
     </varlistentry>
T
Thomas G. Lockhart 已提交
313

314
     <varlistentry>
315
      <term><option>-v</option> <replaceable class="parameter">protocol</replaceable></term>
316 317 318 319
      <listitem>
       <para>
	Specifies the version number of the frontend/backend protocol
	to be used for this particular session.
T
Thomas G. Lockhart 已提交
320 321 322 323
       </para>
      </listitem>
     </varlistentry>

324
     <varlistentry>
325
      <term><option>-W</option> <replaceable class="parameter">seconds</replaceable></term>
326 327 328 329
      <listitem>
       <para>
	As soon as this option is encountered, the process sleeps for
	the specified amount of seconds.  This gives developers time
330
	to attach a debugger to the server process.
331 332 333
       </para>
      </listitem>
     </varlistentry>
T
Thomas G. Lockhart 已提交
334

335
    </variablelist>
P
Peter Eisentraut 已提交
336
   </refsect2>
337
 </refsect1>
T
Thomas G. Lockhart 已提交
338

339
 <refsect1>
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
  <title>Environment</title>

  <variablelist>
   <varlistentry>
    <term><envar>PGDATA</envar></term>

    <listitem>
     <para>
      Default data direction location
     </para>
    </listitem>
   </varlistentry>

  </variablelist>

  <para>
   For others, which have little influence during single-user mode,
   see <xref linkend="app-postmaster">.
  </para>
 </refsect1>

 <refsect1>
362 363 364 365
  <title>Notes</title>

  <para>
   To stop a running query use the <literal>SIGINT</literal> signal. To
366
   tell <command>postgres</command> to reread the configuration file,
367
   use a <literal>SIGHUP</literal> signal. The
368 369
   <command>postmaster</command> uses <literal>SIGTERM</literal>
   to tell a <command>postgres</command> process to quit normally and
370 371 372 373 374 375 376
   <literal>SIGQUIT</literal> to terminate without the normal cleanup.
   These <emphasis>should not</emphasis> be used by users.
  </para>

 </refsect1>

 <refsect1>
377 378 379
  <title>Usage</title>

   <para>
380
    Start a stand-alone server with a command like
381
<screen>
382
<userinput>postgres -D /usr/local/pgsql/data <replaceable>other-options</> my_database</userinput>
383
</screen>
384
    Provide the correct path to the database directory with <option>-D</>, or
385 386 387 388 389
    make sure that the environment variable <envar>PGDATA</> is set.
    Also specify the name of the particular database you want to work in.
   </para>

   <para>
390
    Normally, the stand-alone server treats newline as the command
391 392 393 394 395 396 397 398
    entry terminator; there is no intelligence about semicolons,
    as there is in <application>psql</>.  To continue a command
    across multiple lines, you must type backslash just before each
    newline except the last one.
   </para>

   <para>
    But if you use the <option>-N</> command line switch, then newline does
399
    not terminate command entry.  In this case, the server will read the standard input
400
    until the end-of-file (<acronym>EOF</>) marker, then
401
    process the input as a single command string.  Backslash-newline is not
402 403 404 405
    treated specially in this case.
   </para>

   <para>
406
    To quit the session, type <acronym>EOF</acronym>
P
Peter Eisentraut 已提交
407 408
    (<keycombo action="simul"><keycap>Control</><keycap>D</></>, usually).
    If you've
409
    used <option>-N</>, two consecutive <acronym>EOF</>s are needed to exit.
410 411 412
   </para>

   <para>
413
    Note that the stand-alone server does not provide sophisticated
P
Peter Eisentraut 已提交
414
    line-editing features (no command history, for example).
415 416 417 418
   </para>

 </refsect1>

419
 <refsect1>
420
  <title>See Also</title>
T
Thomas G. Lockhart 已提交
421 422

  <para>
423 424 425
   <xref linkend="app-initdb">,
   <xref linkend="app-ipcclean">,
   <xref linkend="app-postmaster">
T
Thomas G. Lockhart 已提交
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
  </para>
 </refsect1>

</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:nil
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:"/usr/lib/sgml/catalog"
sgml-local-ecat-files:nil
End:
-->