The code to unlink dropped relations in FinishPreparedTransaction() was
[PostgreSQL.git] / doc / src / sgml / ref / pg_ctl-ref.sgml
blobac7aa79aabc433e228f9374c6d22bf02ed02749e
1 <!--
2 $PostgreSQL$
3 PostgreSQL documentation
4 -->
6 <refentry id="app-pg-ctl">
7 <refmeta>
8 <refentrytitle id="app-pg-ctl-title"><application>pg_ctl</application></refentrytitle>
9 <manvolnum>1</manvolnum>
10 <refmiscinfo>Application</refmiscinfo>
11 </refmeta>
13 <refnamediv>
14 <refname>pg_ctl</refname>
15 <refpurpose>start, stop, or restart a <productname>PostgreSQL</productname> server</refpurpose>
16 </refnamediv>
18 <indexterm zone="app-pg-ctl">
19 <primary>pg_ctl</primary>
20 </indexterm>
22 <refsynopsisdiv>
23 <cmdsynopsis>
25 <command>pg_ctl</command>
26 <arg choice="plain">start</arg>
27 <arg>-w</arg>
28 <arg>-t <replaceable>seconds</replaceable></arg>
29 <arg>-s</arg>
30 <arg>-D <replaceable>datadir</replaceable></arg>
31 <arg>-l <replaceable>filename</replaceable></arg>
32 <arg>-o <replaceable>options</replaceable></arg>
33 <arg>-p <replaceable>path</replaceable></arg>
34 <arg>-c</arg>
35 <sbr>
37 <command>pg_ctl</command>
38 <arg choice="plain">stop</arg>
39 <arg>-W</arg>
40 <arg>-t <replaceable>seconds</replaceable></arg>
41 <arg>-s</arg>
42 <arg>-D <replaceable>datadir</replaceable></arg>
43 <arg>-m
44 <group choice="plain">
45 <arg>s[mart]</arg>
46 <arg>f[ast]</arg>
47 <arg>i[mmediate]</arg>
48 </group>
49 </arg>
50 <sbr>
52 <command>pg_ctl</command>
53 <arg choice="plain">restart</arg>
54 <arg>-w</arg>
55 <arg>-t <replaceable>seconds</replaceable></arg>
56 <arg>-s</arg>
57 <arg>-D <replaceable>datadir</replaceable></arg>
58 <arg>-c</arg>
59 <arg>-m
60 <group choice="plain">
61 <arg>s[mart]</arg>
62 <arg>f[ast]</arg>
63 <arg>i[mmediate]</arg>
64 </group>
65 </arg>
66 <arg>-o <replaceable>options</replaceable></arg>
67 <sbr>
69 <command>pg_ctl</command>
70 <arg choice="plain">reload</arg>
71 <arg>-s</arg>
72 <arg>-D <replaceable>datadir</replaceable></arg>
73 <sbr>
75 <command>pg_ctl</command>
76 <arg choice="plain">status</arg>
77 <arg>-D <replaceable>datadir</replaceable></arg>
78 <sbr>
80 <command>pg_ctl</command>
81 <arg choice="plain">kill</arg>
82 <arg><replaceable>signal_name</replaceable></arg>
83 <arg><replaceable>process_id</replaceable></arg>
84 <sbr>
86 <command>pg_ctl</command>
87 <arg choice="plain">register</arg>
88 <arg>-N <replaceable>servicename</replaceable></arg>
89 <arg>-U <replaceable>username</replaceable></arg>
90 <arg>-P <replaceable>password</replaceable></arg>
91 <arg>-D <replaceable>datadir</replaceable></arg>
92 <arg>-w</arg>
93 <arg>-t <replaceable>seconds</replaceable></arg>
94 <arg>-o <replaceable>options</replaceable></arg>
95 <sbr>
97 <command>pg_ctl</command>
98 <arg choice="plain">unregister</arg>
99 <arg>-N <replaceable>servicename</replaceable></arg>
101 </cmdsynopsis>
102 </refsynopsisdiv>
105 <refsect1 id="app-pg-ctl-description">
106 <title>Description</title>
107 <para>
108 <application>pg_ctl</application> is a utility for starting,
109 stopping, or restarting the <productname>PostgreSQL</productname>
110 backend server (<xref linkend="app-postgres">), or displaying the
111 status of a running server. Although the server can be started
112 manually, <application>pg_ctl</application> encapsulates tasks such
113 as redirecting log output and properly detaching from the terminal
114 and process group. It also provides convenient options for
115 controlled shutdown.
116 </para>
118 <para>
119 In <option>start</option> mode, a new server is launched. The
120 server is started in the background, and standard input is attached to
121 <filename>/dev/null</filename>. The standard output and standard
122 error are either appended to a log file (if the <option>-l</option>
123 option is used), or redirected to <application>pg_ctl</application>'s
124 standard output (not standard error). If no log file is chosen, the
125 standard output of <application>pg_ctl</application> should be redirected
126 to a file or piped to another process such as a log rotating program
127 like <application>rotatelogs</>; otherwise <command>postgres</command>
128 will write its output to the controlling terminal (from the background)
129 and will not leave the shell's process group.
130 </para>
132 <para>
133 In <option>stop</option> mode, the server that is running in
134 the specified data directory is shut down. Three different
135 shutdown methods can be selected with the <option>-m</option>
136 option: <quote>Smart</quote> mode waits for online backup mode
137 to finish and all the clients to disconnect. This is the default.
138 <quote>Fast</quote> mode does not wait for clients to disconnect and
139 will terminate an online backup in progress. All active transactions are
140 rolled back and clients are forcibly disconnected, then the
141 server is shut down. <quote>Immediate</quote> mode will abort
142 all server processes without a clean shutdown. This will lead to
143 a recovery run on restart.
144 </para>
146 <para>
147 <option>restart</option> mode effectively executes a stop followed
148 by a start. This allows changing the <command>postgres</command>
149 command-line options.
150 </para>
152 <para>
153 <option>reload</option> mode simply sends the
154 <command>postgres</command> process a <systemitem>SIGHUP</>
155 signal, causing it to reread its configuration files
156 (<filename>postgresql.conf</filename>,
157 <filename>pg_hba.conf</filename>, etc.). This allows changing of
158 configuration-file options that do not require a complete restart
159 to take effect.
160 </para>
162 <para>
163 <option>status</option> mode checks whether a server is running in
164 the specified data directory. If it is, the <acronym>PID</acronym>
165 and the command line options that were used to invoke it are
166 displayed.
167 </para>
169 <para>
170 <option>kill</option> mode allows you to send a signal to a specified
171 process. This is particularly valuable for <productname>Microsoft Windows</>
172 which does not have a <application>kill</> command. Use
173 <literal>--help</> to see a list of supported signal names.
174 </para>
176 <para>
177 <option>register</option> mode allows you to register a system service
178 on <productname>Microsoft Windows</>.
179 </para>
181 <para>
182 <option>unregister</option> mode allows you to unregister a system service
183 on <productname>Microsoft Windows</>, previously registered with the
184 <option>register</option> command.
185 </para>
186 </refsect1>
188 <refsect1 id="app-pg-ctl-options">
189 <title>Options</title>
191 <variablelist>
193 <varlistentry>
194 <term><option>-c</option></term>
195 <listitem>
196 <para>
197 Attempt to allow server crashes to produce core files, on platforms
198 where this available, by lifting any soft resource limit placed on
199 them.
200 This is useful in debugging or diagnosing problems by allowing a
201 stack trace to be obtained from a failed server process.
202 </para>
203 </listitem>
204 </varlistentry>
206 <varlistentry>
207 <term><option>-D <replaceable class="parameter">datadir</replaceable></option></term>
208 <listitem>
209 <para>
210 Specifies the file system location of the database files. If
211 this is omitted, the environment variable
212 <envar>PGDATA</envar> is used.
213 </para>
214 </listitem>
215 </varlistentry>
217 <varlistentry>
218 <term><option>-l <replaceable class="parameter">filename</replaceable></option></term>
219 <listitem>
220 <para>
221 Append the server log output to
222 <replaceable>filename</replaceable>. If the file does not
223 exist, it is created. The <systemitem>umask</> is set to 077, so access to
224 the log file from other users is disallowed by default.
225 </para>
226 </listitem>
227 </varlistentry>
229 <varlistentry>
230 <term><option>-m <replaceable class="parameter">mode</replaceable></option></term>
231 <listitem>
232 <para>
233 Specifies the shutdown mode. <replaceable>mode</replaceable>
234 can be <literal>smart</literal>, <literal>fast</literal>, or
235 <literal>immediate</literal>, or the first letter of one of
236 these three.
237 </para>
238 </listitem>
239 </varlistentry>
241 <varlistentry>
242 <term><option>-o <replaceable class="parameter">options</replaceable></option></term>
243 <listitem>
244 <para>
245 Specifies options to be passed directly to the
246 <command>postgres</command> command.
247 </para>
248 <para>
249 The options are usually surrounded by single or double
250 quotes to ensure that they are passed through as a group.
251 </para>
252 </listitem>
253 </varlistentry>
255 <varlistentry>
256 <term><option>-p <replaceable class="parameter">path</replaceable></option></term>
257 <listitem>
258 <para>
259 Specifies the location of the <filename>postgres</filename>
260 executable. By default the <filename>postgres</filename> executable is taken from the same
261 directory as <command>pg_ctl</command>, or failing that, the hard-wired
262 installation directory. It is not necessary to use this
263 option unless you are doing something unusual and get errors
264 that the <filename>postgres</filename> executable was not found.
265 </para>
266 </listitem>
267 </varlistentry>
269 <varlistentry>
270 <term><option>-s</option></term>
271 <listitem>
272 <para>
273 Only print errors, no informational messages.
274 </para>
275 </listitem>
276 </varlistentry>
278 <varlistentry>
279 <term><option>-t</option></term>
280 <listitem>
281 <para>
282 The number of seconds to wait when waiting for start or shutdown
283 to complete.
284 </para>
285 </listitem>
286 </varlistentry>
288 <varlistentry>
289 <term><option>-w</option></term>
290 <listitem>
291 <para>
292 Wait for the start or shutdown to complete. The default wait time
293 is 60 seconds. This is the default option for shutdowns. A successful
294 shutdown is indicated by removal of the <acronym>PID</acronym>
295 file. For starting up, a successful <command>psql -l</command>
296 indicates success. <command>pg_ctl</command> will attempt to
297 use the proper port for <application>psql</>. If the environment variable
298 <envar>PGPORT</envar> exists, that is used. Otherwise, it will see if a port
299 has been set in the <filename>postgresql.conf</filename> file.
300 If neither of those is used, it will use the default port that
301 <productname>PostgreSQL</productname> was compiled with
302 (5432 by default). When waiting, <command>pg_ctl</command> will
303 return an accurate exit code based on the success of the startup
304 or shutdown.
305 </para>
306 </listitem>
307 </varlistentry>
309 <varlistentry>
310 <term><option>-W</option></term>
311 <listitem>
312 <para>
313 Do not wait for start or shutdown to complete. This is the
314 default for starts and restarts.
315 </para>
316 </listitem>
317 </varlistentry>
318 </variablelist>
320 <refsect2 id="app-pg-ctl-windows-options">
321 <title>Options for Windows</title>
323 <variablelist>
324 <varlistentry>
325 <term><option>-N <replaceable class="parameter">servicename</replaceable></option></term>
326 <listitem>
327 <para>
328 Name of the system service to register. The name will be used
329 as both the service name and the display name.
330 </para>
331 </listitem>
332 </varlistentry>
334 <varlistentry>
335 <term><option>-P <replaceable class="parameter">password</replaceable></option></term>
336 <listitem>
337 <para>
338 Password for the user to start the service.
339 </para>
340 </listitem>
341 </varlistentry>
343 <varlistentry>
344 <term><option>-U <replaceable class="parameter">username</replaceable></option></term>
345 <listitem>
346 <para>
347 User name for the user to start the service. For domain users, use the
348 format <literal>DOMAIN\username</literal>.
349 </para>
350 </listitem>
351 </varlistentry>
352 </variablelist>
353 </refsect2>
355 </refsect1>
358 <refsect1>
359 <title>Environment</title>
361 <variablelist>
362 <varlistentry>
363 <term><envar>PGDATA</envar></term>
365 <listitem>
366 <para>
367 Default data directory location.
368 </para>
369 </listitem>
370 </varlistentry>
372 <varlistentry>
373 <term><envar>PGPORT</envar></term>
375 <listitem>
376 <para>
377 Default port for <xref linkend="app-psql"> (used by the -w option).
378 </para>
379 </listitem>
380 </varlistentry>
381 </variablelist>
383 <para>
384 For additional server variables, see <xref linkend="app-postgres">.
385 This utility, like most other <productname>PostgreSQL</> utilities,
386 also uses the environment variables supported by <application>libpq</>
387 (see <xref linkend="libpq-envars">).
388 </para>
389 </refsect1>
392 <refsect1>
393 <title>Files</title>
395 <variablelist>
396 <varlistentry>
397 <term><filename>postmaster.pid</filename></term>
399 <listitem>
400 <para>
401 The existence of this file in the data directory is used to help
402 <application>pg_ctl</application> determine if the server is
403 currently running or not.
404 </para>
405 </listitem>
406 </varlistentry>
408 <varlistentry>
409 <term><filename>postmaster.opts</filename></term>
411 <listitem>
412 <para>If this file exists in the data directory,
413 <application>pg_ctl</application> (in <option>restart</option> mode)
414 will pass the contents of the file as options to
415 <application>postgres</application>, unless overridden
416 by the <option>-o</option> option. The contents of this file
417 are also displayed in <option>status</option> mode.
418 </para>
419 </listitem>
420 </varlistentry>
422 <varlistentry>
423 <term><filename>postgresql.conf</filename></term>
425 <listitem>
426 <para>
427 This file, located in the data directory, is parsed to find the
428 proper port to use with <application>psql</application> when the
429 <option>-w</option> is given in <option>start</option> mode.
430 </para>
431 </listitem>
432 </varlistentry>
434 </variablelist>
435 </refsect1>
438 <refsect1>
439 <title>Notes</title>
441 <para>
442 Waiting for complete start is not a well-defined operation and might
443 fail if access control is set up so that a local client cannot
444 connect without manual interaction (e.g., password authentication). For
445 additional connection variables, see <xref linkend="libpq-envars">,
446 and for passwords, also see <xref linkend="libpq-pgpass">.
447 </para>
448 </refsect1>
451 <refsect1 id="R1-APP-PGCTL-2">
452 <title>Examples</title>
454 <refsect2 id="R2-APP-PGCTL-3">
455 <title>Starting the Server</title>
457 <para>
458 To start up a server:
459 <screen>
460 <prompt>$</prompt> <userinput>pg_ctl start</userinput>
461 </screen>
462 </para>
464 <para>
465 An example of starting the server, blocking until the server has
466 come up is:
467 <screen>
468 <prompt>$</prompt> <userinput>pg_ctl -w start</userinput>
469 </screen>
470 </para>
472 <para>
473 For a server using port 5433, and
474 running without <function>fsync</function>, use:
475 <screen>
476 <prompt>$</prompt> <userinput>pg_ctl -o "-F -p 5433" start</userinput>
477 </screen>
478 </para>
479 </refsect2>
481 <refsect2 id="R2-APP-PGCTL-4">
482 <title>Stopping the Server</title>
483 <para>
484 <screen>
485 <prompt>$</prompt> <userinput>pg_ctl stop</userinput>
486 </screen>
487 stops the server. Using the <option>-m</option> switch allows one
488 to control <emphasis>how</emphasis> the backend shuts down.
489 </para>
490 </refsect2>
492 <refsect2 id="R2-APP-PGCTL-5">
493 <title>Restarting the Server</title>
495 <para>
496 Restarting the server is almost equivalent to stopping the
497 server and starting it again
498 except that <command>pg_ctl</command> saves and reuses the command line options that
499 were passed to the previously running instance. To restart
500 the server in the simplest form, use:
501 <screen>
502 <prompt>$</prompt> <userinput>pg_ctl restart</userinput>
503 </screen>
504 </para>
506 <para>
507 To restart server,
508 waiting for it to shut down and to come up:
509 <screen>
510 <prompt>$</prompt> <userinput>pg_ctl -w restart</userinput>
511 </screen>
512 </para>
514 <para>
515 To restart using port 5433 and disabling <function>fsync</> after restarting:
516 <screen>
517 <prompt>$</prompt> <userinput>pg_ctl -o "-F -p 5433" restart</userinput>
518 </screen>
519 </para>
520 </refsect2>
522 <refsect2 id="R2-APP-PGCTL-6">
523 <title>Showing the Server Status</title>
525 <para>
526 Here is a sample status output from
527 <application>pg_ctl</application>:
528 <screen>
529 <prompt>$</prompt> <userinput>pg_ctl status</userinput>
530 <computeroutput>
531 pg_ctl: server is running (pid: 13718)
532 Command line was:
533 /usr/local/pgsql/bin/postgres '-D' '/usr/local/pgsql/data' '-p' '5433' '-B' '128'
534 </computeroutput>
535 </screen>
536 This is the command line that would be invoked in restart mode.
537 </para>
538 </refsect2>
539 </refsect1>
542 <refsect1>
543 <title>See Also</title>
545 <para>
546 <xref linkend="app-postgres">
547 </para>
548 </refsect1>
550 </refentry>