| 1 |
<!-- |
| 2 |
doc/src/sgml/ref/pg_ctl-ref.sgml |
| 3 |
PostgreSQL documentation |
| 4 |
--> |
| 5 |
|
| 6 |
<refentry id="app-pg-ctl"> |
| 7 |
<indexterm zone="app-pg-ctl"> |
| 8 |
<primary>pg_ctl</primary> |
| 9 |
</indexterm> |
| 10 |
|
| 11 |
<refmeta> |
| 12 |
<refentrytitle><application>pg_ctl</application></refentrytitle> |
| 13 |
<manvolnum>1</manvolnum> |
| 14 |
<refmiscinfo>Application</refmiscinfo> |
| 15 |
</refmeta> |
| 16 |
|
| 17 |
<refnamediv> |
| 18 |
<refname>pg_ctl</refname> |
| 19 |
<refpurpose>initialize, start, stop, or control a <productname>PostgreSQL</productname> server</refpurpose> |
| 20 |
</refnamediv> |
| 21 |
|
| 22 |
<refsynopsisdiv> |
| 23 |
<cmdsynopsis> |
| 24 |
<command>pg_ctl</command> |
| 25 |
<arg choice="plain"><option>init[db]</option></arg> |
| 26 |
<arg choice="opt"><option>-D</option> <replaceable>datadir</replaceable></arg> |
| 27 |
<arg choice="opt"><option>-s</option></arg> |
| 28 |
<arg choice="opt"><option>-o</option> <replaceable>initdb-options</replaceable></arg> |
| 29 |
</cmdsynopsis> |
| 30 |
|
| 31 |
<cmdsynopsis> |
| 32 |
<command>pg_ctl</command> |
| 33 |
<arg choice="plain"><option>start</option></arg> |
| 34 |
<arg choice="opt"><option>-D</option> <replaceable>datadir</replaceable></arg> |
| 35 |
<arg choice="opt"><option>-l</option> <replaceable>filename</replaceable></arg> |
| 36 |
<arg choice="opt"><option>-W</option></arg> |
| 37 |
<arg choice="opt"><option>-t</option> <replaceable>seconds</replaceable></arg> |
| 38 |
<arg choice="opt"><option>-s</option></arg> |
| 39 |
<arg choice="opt"><option>-o</option> <replaceable>options</replaceable></arg> |
| 40 |
<arg choice="opt"><option>-p</option> <replaceable>path</replaceable></arg> |
| 41 |
<arg choice="opt"><option>-c</option></arg> |
| 42 |
</cmdsynopsis> |
| 43 |
|
| 44 |
<cmdsynopsis> |
| 45 |
<command>pg_ctl</command> |
| 46 |
<arg choice="plain"><option>stop</option></arg> |
| 47 |
<arg choice="opt"><option>-D</option> <replaceable>datadir</replaceable></arg> |
| 48 |
<arg choice="opt"><option>-m</option> |
| 49 |
<group choice="plain"> |
| 50 |
<arg choice="plain"><option>s[mart]</option></arg> |
| 51 |
<arg choice="plain"><option>f[ast]</option></arg> |
| 52 |
<arg choice="plain"><option>i[mmediate]</option></arg> |
| 53 |
</group> |
| 54 |
</arg> |
| 55 |
<arg choice="opt"><option>-W</option></arg> |
| 56 |
<arg choice="opt"><option>-t</option> <replaceable>seconds</replaceable></arg> |
| 57 |
<arg choice="opt"><option>-s</option></arg> |
| 58 |
</cmdsynopsis> |
| 59 |
|
| 60 |
<cmdsynopsis> |
| 61 |
<command>pg_ctl</command> |
| 62 |
<arg choice="plain"><option>restart</option></arg> |
| 63 |
<arg choice="opt"><option>-D</option> <replaceable>datadir</replaceable></arg> |
| 64 |
<arg choice="opt"><option>-m</option> |
| 65 |
<group choice="plain"> |
| 66 |
<arg choice="plain"><option>s[mart]</option></arg> |
| 67 |
<arg choice="plain"><option>f[ast]</option></arg> |
| 68 |
<arg choice="plain"><option>i[mmediate]</option></arg> |
| 69 |
</group> |
| 70 |
</arg> |
| 71 |
<arg choice="opt"><option>-W</option></arg> |
| 72 |
<arg choice="opt"><option>-t</option> <replaceable>seconds</replaceable></arg> |
| 73 |
<arg choice="opt"><option>-s</option></arg> |
| 74 |
<arg choice="opt"><option>-o</option> <replaceable>options</replaceable></arg> |
| 75 |
<arg choice="opt"><option>-c</option></arg> |
| 76 |
</cmdsynopsis> |
| 77 |
|
| 78 |
<cmdsynopsis> |
| 79 |
<command>pg_ctl</command> |
| 80 |
<arg choice="plain"><option>reload</option></arg> |
| 81 |
<arg choice="opt"><option>-D</option> <replaceable>datadir</replaceable></arg> |
| 82 |
<arg choice="opt"><option>-s</option></arg> |
| 83 |
</cmdsynopsis> |
| 84 |
|
| 85 |
<cmdsynopsis> |
| 86 |
<command>pg_ctl</command> |
| 87 |
<arg choice="plain"><option>status</option></arg> |
| 88 |
<arg choice="opt"><option>-D</option> <replaceable>datadir</replaceable></arg> |
| 89 |
</cmdsynopsis> |
| 90 |
|
| 91 |
<cmdsynopsis> |
| 92 |
<command>pg_ctl</command> |
| 93 |
<arg choice="plain"><option>promote</option></arg> |
| 94 |
<arg choice="opt"><option>-D</option> <replaceable>datadir</replaceable></arg> |
| 95 |
<arg choice="opt"><option>-W</option></arg> |
| 96 |
<arg choice="opt"><option>-t</option> <replaceable>seconds</replaceable></arg> |
| 97 |
<arg choice="opt"><option>-s</option></arg> |
| 98 |
</cmdsynopsis> |
| 99 |
|
| 100 |
<cmdsynopsis> |
| 101 |
<command>pg_ctl</command> |
| 102 |
<arg choice="plain"><option>logrotate</option></arg> |
| 103 |
<arg choice="opt"><option>-D</option> <replaceable>datadir</replaceable></arg> |
| 104 |
<arg choice="opt"><option>-s</option></arg> |
| 105 |
</cmdsynopsis> |
| 106 |
|
| 107 |
<cmdsynopsis> |
| 108 |
<command>pg_ctl</command> |
| 109 |
<arg choice="plain"><option>kill</option></arg> |
| 110 |
<arg choice="plain"><replaceable>signal_name</replaceable></arg> |
| 111 |
<arg choice="plain"><replaceable>process_id</replaceable></arg> |
| 112 |
</cmdsynopsis> |
| 113 |
|
| 114 |
<para>On Microsoft Windows, also:</para> |
| 115 |
|
| 116 |
<cmdsynopsis> |
| 117 |
<command>pg_ctl</command> |
| 118 |
<arg choice="plain"><option>register</option></arg> |
| 119 |
<arg choice="opt"><option>-D</option> <replaceable>datadir</replaceable></arg> |
| 120 |
<arg choice="opt"><option>-N</option> <replaceable>servicename</replaceable></arg> |
| 121 |
<arg choice="opt"><option>-U</option> <replaceable>username</replaceable></arg> |
| 122 |
<arg choice="opt"><option>-P</option> <replaceable>password</replaceable></arg> |
| 123 |
<arg choice="opt"><option>-S</option> |
| 124 |
<group choice="plain"> |
| 125 |
<arg choice="plain"><option>a[uto]</option></arg> |
| 126 |
<arg choice="plain"><option>d[emand]</option></arg> |
| 127 |
</group> |
| 128 |
</arg> |
| 129 |
<arg choice="opt"><option>-e</option> <replaceable>source</replaceable></arg> |
| 130 |
<arg choice="opt"><option>-W</option></arg> |
| 131 |
<arg choice="opt"><option>-t</option> <replaceable>seconds</replaceable></arg> |
| 132 |
<arg choice="opt"><option>-s</option></arg> |
| 133 |
<arg choice="opt"><option>-o</option> <replaceable>options</replaceable></arg> |
| 134 |
</cmdsynopsis> |
| 135 |
|
| 136 |
<cmdsynopsis> |
| 137 |
<command>pg_ctl</command> |
| 138 |
<arg choice="plain"><option>unregister</option></arg> |
| 139 |
<arg choice="opt"><option>-N</option> <replaceable>servicename</replaceable></arg> |
| 140 |
</cmdsynopsis> |
| 141 |
</refsynopsisdiv> |
| 142 |
|
| 143 |
|
| 144 |
<refsect1 id="app-pg-ctl-description"> |
| 145 |
<title>Description</title> |
| 146 |
<para> |
| 147 |
<application>pg_ctl</application> is a utility for initializing a |
| 148 |
<productname>PostgreSQL</productname> database cluster, starting, |
| 149 |
stopping, or restarting the <productname>PostgreSQL</productname> |
| 150 |
database server (<xref linkend="app-postgres"/>), or displaying the |
| 151 |
status of a running server. Although the server can be started |
| 152 |
manually, <application>pg_ctl</application> encapsulates tasks such |
| 153 |
as redirecting log output and properly detaching from the terminal |
| 154 |
and process group. It also provides convenient options for |
| 155 |
controlled shutdown. |
| 156 |
</para> |
| 157 |
|
| 158 |
<para> |
| 159 |
The <option>init</option> or <option>initdb</option> mode creates a new |
| 160 |
<productname>PostgreSQL</productname> database cluster, that is, |
| 161 |
a collection of databases that will be managed by a single |
| 162 |
server instance. This mode invokes the <command>initdb</command> |
| 163 |
command. See <xref linkend="app-initdb"/> for details. |
| 164 |
</para> |
| 165 |
|
| 166 |
<para> |
| 167 |
<option>start</option> mode launches a new server. The |
| 168 |
server is started in the background, and its standard input is attached |
| 169 |
to <filename>/dev/null</filename> (or <literal>nul</literal> on Windows). |
| 170 |
On Unix-like systems, by default, the server's standard output and |
| 171 |
standard error are sent to <application>pg_ctl</application>'s |
| 172 |
standard output (not standard error). The standard output of |
| 173 |
<application>pg_ctl</application> should then be redirected to a |
| 174 |
file or piped to another process such as a log rotating program |
| 175 |
like <application>rotatelogs</application>; otherwise <command>postgres</command> |
| 176 |
will write its output to the controlling terminal (from the |
| 177 |
background) and will not leave the shell's process group. On |
| 178 |
Windows, by default the server's standard output and standard error |
| 179 |
are sent to the terminal. These default behaviors can be changed |
| 180 |
by using <option>-l</option> to append the server's output to a log file. |
| 181 |
Use of either <option>-l</option> or output redirection is recommended. |
| 182 |
</para> |
| 183 |
|
| 184 |
<para> |
| 185 |
<option>stop</option> mode shuts down the server that is running in |
| 186 |
the specified data directory. Three different |
| 187 |
shutdown methods can be selected with the <option>-m</option> |
| 188 |
option. <quote>Smart</quote> mode disallows new connections, then waits |
| 189 |
for all existing clients to disconnect. |
| 190 |
If the server is in hot standby, recovery and streaming replication |
| 191 |
will be terminated once all clients have disconnected. |
| 192 |
<quote>Fast</quote> mode (the default) does not wait for clients to disconnect. |
| 193 |
All active transactions are |
| 194 |
rolled back and clients are forcibly disconnected, then the |
| 195 |
server is shut down. <quote>Immediate</quote> mode will abort |
| 196 |
all server processes immediately, without a clean shutdown. This choice |
| 197 |
will lead to a crash-recovery cycle during the next server start. |
| 198 |
</para> |
| 199 |
|
| 200 |
<para> |
| 201 |
<option>restart</option> mode effectively executes a stop followed |
| 202 |
by a start. This allows changing the <command>postgres</command> |
| 203 |
command-line options, or changing configuration-file options that |
| 204 |
cannot be changed without restarting the server. |
| 205 |
If relative paths were used on the command line during server |
| 206 |
start, <option>restart</option> might fail unless |
| 207 |
<application>pg_ctl</application> is executed in the same current |
| 208 |
directory as it was during server start. |
| 209 |
</para> |
| 210 |
|
| 211 |
<para> |
| 212 |
<option>reload</option> mode simply sends the |
| 213 |
<command>postgres</command> server process a <systemitem>SIGHUP</systemitem> |
| 214 |
signal, causing it to reread its configuration files |
| 215 |
(<filename>postgresql.conf</filename>, |
| 216 |
<filename>pg_hba.conf</filename>, etc.). This allows changing |
| 217 |
configuration-file options that do not require a full server restart |
| 218 |
to take effect. |
| 219 |
</para> |
| 220 |
|
| 221 |
<para> |
| 222 |
<option>status</option> mode checks whether a server is running in |
| 223 |
the specified data directory. If it is, the server's <acronym>PID</acronym> |
| 224 |
and the command line options that were used to invoke it are displayed. |
| 225 |
If the server is not running, <application>pg_ctl</application> returns |
| 226 |
an exit status of 3. If an accessible data directory is not |
| 227 |
specified, <application>pg_ctl</application> returns an exit status of 4. |
| 228 |
</para> |
| 229 |
|
| 230 |
<para> |
| 231 |
<option>promote</option> mode commands the standby server that is |
| 232 |
running in the specified data directory to end standby mode |
| 233 |
and begin read-write operations. |
| 234 |
</para> |
| 235 |
|
| 236 |
<para> |
| 237 |
<option>logrotate</option> mode rotates the server log file. |
| 238 |
For details on how to use this mode with external log rotation tools, see |
| 239 |
<xref linkend="logfile-maintenance"/>. |
| 240 |
</para> |
| 241 |
|
| 242 |
<para> |
| 243 |
<option>kill</option> mode sends a signal to a specified process. |
| 244 |
This is primarily valuable on <productname>Microsoft Windows</productname> |
| 245 |
which does not have a built-in <application>kill</application> command. Use |
| 246 |
<literal>--help</literal> to see a list of supported signal names. |
| 247 |
</para> |
| 248 |
|
| 249 |
<para> |
| 250 |
<option>register</option> mode registers the <productname>PostgreSQL</productname> |
| 251 |
server as a system service on <productname>Microsoft Windows</productname>. |
| 252 |
The <option>-S</option> option allows selection of service start type, |
| 253 |
either <quote>auto</quote> (start service automatically on system startup) |
| 254 |
or <quote>demand</quote> (start service on demand). |
| 255 |
</para> |
| 256 |
|
| 257 |
<para> |
| 258 |
<option>unregister</option> mode unregisters a system service |
| 259 |
on <productname>Microsoft Windows</productname>. This undoes the effects of the |
| 260 |
<option>register</option> command. |
| 261 |
</para> |
| 262 |
</refsect1> |
| 263 |
|
| 264 |
<refsect1 id="app-pg-ctl-options"> |
| 265 |
<title>Options</title> |
| 266 |
|
| 267 |
<variablelist> |
| 268 |
|
| 269 |
<varlistentry> |
| 270 |
<term><option>-c</option></term> |
| 271 |
<term><option>--core-files</option></term> |
| 272 |
<listitem> |
| 273 |
<para> |
| 274 |
Attempt to allow server crashes to produce core files, on platforms |
| 275 |
where this is possible, by lifting any soft resource limit placed on |
| 276 |
core files. |
| 277 |
This is useful in debugging or diagnosing problems by allowing a |
| 278 |
stack trace to be obtained from a failed server process. |
| 279 |
</para> |
| 280 |
</listitem> |
| 281 |
</varlistentry> |
| 282 |
|
| 283 |
<varlistentry> |
| 284 |
<term><option>-D <replaceable class="parameter">datadir</replaceable></option></term> |
| 285 |
<term><option>--pgdata=<replaceable class="parameter">datadir</replaceable></option></term> |
| 286 |
<listitem> |
| 287 |
<para> |
| 288 |
Specifies the file system location of the database configuration files. If |
| 289 |
this option is omitted, the environment variable |
| 290 |
<envar>PGDATA</envar> is used. |
| 291 |
</para> |
| 292 |
</listitem> |
| 293 |
</varlistentry> |
| 294 |
|
| 295 |
<varlistentry> |
| 296 |
<term><option>-l <replaceable class="parameter">filename</replaceable></option></term> |
| 297 |
<term><option>--log=<replaceable class="parameter">filename</replaceable></option></term> |
| 298 |
<listitem> |
| 299 |
<para> |
| 300 |
Append the server log output to |
| 301 |
<replaceable>filename</replaceable>. If the file does not |
| 302 |
exist, it is created. By default, only the cluster owner can |
| 303 |
access the log file. If group access is enabled in the cluster, |
| 304 |
users in the same group as the cluster owner can also read it. |
| 305 |
</para> |
| 306 |
</listitem> |
| 307 |
</varlistentry> |
| 308 |
|
| 309 |
<varlistentry> |
| 310 |
<term><option>-m <replaceable class="parameter">mode</replaceable></option></term> |
| 311 |
<term><option>--mode=<replaceable class="parameter">mode</replaceable></option></term> |
| 312 |
<listitem> |
| 313 |
<para> |
| 314 |
Specifies the shutdown mode. <replaceable>mode</replaceable> |
| 315 |
can be <literal>smart</literal>, <literal>fast</literal>, or |
| 316 |
<literal>immediate</literal>, or the first letter of one of |
| 317 |
these three. If this option is omitted, <literal>fast</literal> is |
| 318 |
the default. |
| 319 |
</para> |
| 320 |
</listitem> |
| 321 |
</varlistentry> |
| 322 |
|
| 323 |
<varlistentry> |
| 324 |
<term><option>-o <replaceable class="parameter">options</replaceable></option></term> |
| 325 |
<term><option>--options=<replaceable class="parameter">options</replaceable></option></term> |
| 326 |
<listitem> |
| 327 |
<para> |
| 328 |
Specifies options to be passed directly to the |
| 329 |
<command>postgres</command> command. |
| 330 |
<option>-o</option> can be specified multiple times, with all the given |
| 331 |
options being passed through. |
| 332 |
</para> |
| 333 |
<para> |
| 334 |
The <replaceable>options</replaceable> should usually be surrounded by single or |
| 335 |
double quotes to ensure that they are passed through as a group. |
| 336 |
</para> |
| 337 |
</listitem> |
| 338 |
</varlistentry> |
| 339 |
|
| 340 |
<varlistentry> |
| 341 |
<term><option>-o <replaceable class="parameter">initdb-options</replaceable></option></term> |
| 342 |
<term><option>--options=<replaceable class="parameter">initdb-options</replaceable></option></term> |
| 343 |
<listitem> |
| 344 |
<para> |
| 345 |
Specifies options to be passed directly to the |
| 346 |
<command>initdb</command> command. |
| 347 |
<option>-o</option> can be specified multiple times, with all the given |
| 348 |
options being passed through. |
| 349 |
</para> |
| 350 |
<para> |
| 351 |
The <replaceable>initdb-options</replaceable> should usually be surrounded by single or |
| 352 |
double quotes to ensure that they are passed through as a group. |
| 353 |
</para> |
| 354 |
</listitem> |
| 355 |
</varlistentry> |
| 356 |
|
| 357 |
<varlistentry> |
| 358 |
<term><option>-p <replaceable class="parameter">path</replaceable></option></term> |
| 359 |
<listitem> |
| 360 |
<para> |
| 361 |
Specifies the location of the <filename>postgres</filename> |
| 362 |
executable. By default the <filename>postgres</filename> executable is taken from the same |
| 363 |
directory as <command>pg_ctl</command>, or failing that, the hard-wired |
| 364 |
installation directory. It is not necessary to use this |
| 365 |
option unless you are doing something unusual and get errors |
| 366 |
that the <filename>postgres</filename> executable was not found. |
| 367 |
</para> |
| 368 |
|
| 369 |
<para> |
| 370 |
In <literal>init</literal> mode, this option analogously |
| 371 |
specifies the location of the <filename>initdb</filename> |
| 372 |
executable. |
| 373 |
</para> |
| 374 |
</listitem> |
| 375 |
</varlistentry> |
| 376 |
|
| 377 |
<varlistentry> |
| 378 |
<term><option>-s</option></term> |
| 379 |
<term><option>--silent</option></term> |
| 380 |
<listitem> |
| 381 |
<para> |
| 382 |
Print only errors, no informational messages. |
| 383 |
</para> |
| 384 |
</listitem> |
| 385 |
</varlistentry> |
| 386 |
|
| 387 |
<varlistentry> |
| 388 |
<term><option>-t <replaceable class="parameter">seconds</replaceable></option></term> |
| 389 |
<term><option>--timeout=<replaceable class="parameter">seconds</replaceable></option></term> |
| 390 |
<listitem> |
| 391 |
<para> |
| 392 |
Specifies the maximum number of seconds to wait when waiting for an |
| 393 |
operation to complete (see option <option>-w</option>). Defaults to |
| 394 |
the value of the <envar>PGCTLTIMEOUT</envar> environment variable or, if |
| 395 |
not set, to 60 seconds. |
| 396 |
</para> |
| 397 |
</listitem> |
| 398 |
</varlistentry> |
| 399 |
|
| 400 |
<varlistentry> |
| 401 |
<term><option>-V</option></term> |
| 402 |
<term><option>--version</option></term> |
| 403 |
<listitem> |
| 404 |
<para> |
| 405 |
Print the <application>pg_ctl</application> version and exit. |
| 406 |
</para> |
| 407 |
</listitem> |
| 408 |
</varlistentry> |
| 409 |
|
| 410 |
<varlistentry> |
| 411 |
<term><option>-w</option></term> |
| 412 |
<term><option>--wait</option></term> |
| 413 |
<listitem> |
| 414 |
<para> |
| 415 |
Wait for the operation to complete. This is supported for the |
| 416 |
modes <literal>start</literal>, <literal>stop</literal>, |
| 417 |
<literal>restart</literal>, <literal>promote</literal>, |
| 418 |
and <literal>register</literal>, and is the default for those modes. |
| 419 |
</para> |
| 420 |
|
| 421 |
<para> |
| 422 |
When waiting, <command>pg_ctl</command> repeatedly checks the |
| 423 |
server's <acronym>PID</acronym> file, sleeping for a short amount |
| 424 |
of time between checks. Startup is considered complete when |
| 425 |
the <acronym>PID</acronym> file indicates that the server is ready to |
| 426 |
accept connections. Shutdown is considered complete when the server |
| 427 |
removes the <acronym>PID</acronym> file. |
| 428 |
<command>pg_ctl</command> returns an exit code based on the |
| 429 |
success of the startup or shutdown. |
| 430 |
</para> |
| 431 |
|
| 432 |
<para> |
| 433 |
If the operation does not complete within the timeout (see |
| 434 |
option <option>-t</option>), then <command>pg_ctl</command> exits with |
| 435 |
a nonzero exit status. But note that the operation might continue in |
| 436 |
the background and eventually succeed. |
| 437 |
</para> |
| 438 |
</listitem> |
| 439 |
</varlistentry> |
| 440 |
|
| 441 |
<varlistentry> |
| 442 |
<term><option>-W</option></term> |
| 443 |
<term><option>--no-wait</option></term> |
| 444 |
<listitem> |
| 445 |
<para> |
| 446 |
Do not wait for the operation to complete. This is the opposite of |
| 447 |
the option <option>-w</option>. |
| 448 |
</para> |
| 449 |
|
| 450 |
<para> |
| 451 |
If waiting is disabled, the requested action is triggered, but there |
| 452 |
is no feedback about its success. In that case, the server log file |
| 453 |
or an external monitoring system would have to be used to check the |
| 454 |
progress and success of the operation. |
| 455 |
</para> |
| 456 |
|
| 457 |
<para> |
| 458 |
In prior releases of PostgreSQL, this was the default except for |
| 459 |
the <literal>stop</literal> mode. |
| 460 |
</para> |
| 461 |
</listitem> |
| 462 |
</varlistentry> |
| 463 |
|
| 464 |
<varlistentry> |
| 465 |
<term><option>-?</option></term> |
| 466 |
<term><option>--help</option></term> |
| 467 |
<listitem> |
| 468 |
<para> |
| 469 |
Show help about <application>pg_ctl</application> command line |
| 470 |
arguments, and exit. |
| 471 |
</para> |
| 472 |
</listitem> |
| 473 |
</varlistentry> |
| 474 |
</variablelist> |
| 475 |
|
| 476 |
<para> |
| 477 |
If an option is specified that is valid, but not relevant to the selected |
| 478 |
operating mode, <application>pg_ctl</application> ignores it. |
| 479 |
</para> |
| 480 |
|
| 481 |
<refsect2 id="app-pg-ctl-windows-options"> |
| 482 |
<title>Options for Windows</title> |
| 483 |
|
| 484 |
<variablelist> |
| 485 |
<varlistentry> |
| 486 |
<term><option>-e <replaceable class="parameter">source</replaceable></option></term> |
| 487 |
<listitem> |
| 488 |
<para> |
| 489 |
Name of the event source for <application>pg_ctl</application> to use |
| 490 |
for logging to the event log when running as a Windows service. The |
| 491 |
default is <literal>PostgreSQL</literal>. Note that this only controls |
| 492 |
messages sent from <application>pg_ctl</application> itself; once |
| 493 |
started, the server will use the event source specified |
| 494 |
by its <xref linkend="guc-event-source"/> parameter. Should the server |
| 495 |
fail very early in startup, before that parameter has been set, |
| 496 |
it might also log using the default event |
| 497 |
source name <literal>PostgreSQL</literal>. |
| 498 |
</para> |
| 499 |
</listitem> |
| 500 |
</varlistentry> |
| 501 |
|
| 502 |
<varlistentry> |
| 503 |
<term><option>-N <replaceable class="parameter">servicename</replaceable></option></term> |
| 504 |
<listitem> |
| 505 |
<para> |
| 506 |
Name of the system service to register. This name will be used |
| 507 |
as both the service name and the display name. |
| 508 |
The default is <literal>PostgreSQL</literal>. |
| 509 |
</para> |
| 510 |
</listitem> |
| 511 |
</varlistentry> |
| 512 |
|
| 513 |
<varlistentry> |
| 514 |
<term><option>-P <replaceable class="parameter">password</replaceable></option></term> |
| 515 |
<listitem> |
| 516 |
<para> |
| 517 |
Password for the user to run the service as. |
| 518 |
</para> |
| 519 |
</listitem> |
| 520 |
</varlistentry> |
| 521 |
|
| 522 |
<varlistentry> |
| 523 |
<term><option>-S <replaceable class="parameter">start-type</replaceable></option></term> |
| 524 |
<listitem> |
| 525 |
<para> |
| 526 |
Start type of the system service. <replaceable>start-type</replaceable> can |
| 527 |
be <literal>auto</literal>, or <literal>demand</literal>, or |
| 528 |
the first letter of one of these two. If this option is omitted, |
| 529 |
<literal>auto</literal> is the default. |
| 530 |
</para> |
| 531 |
</listitem> |
| 532 |
</varlistentry> |
| 533 |
|
| 534 |
<varlistentry> |
| 535 |
<term><option>-U <replaceable class="parameter">username</replaceable></option></term> |
| 536 |
<listitem> |
| 537 |
<para> |
| 538 |
User name for the user to run the service as. For domain users, use the |
| 539 |
format <literal>DOMAIN\username</literal>. |
| 540 |
</para> |
| 541 |
</listitem> |
| 542 |
</varlistentry> |
| 543 |
</variablelist> |
| 544 |
</refsect2> |
| 545 |
|
| 546 |
</refsect1> |
| 547 |
|
| 548 |
|
| 549 |
<refsect1> |
| 550 |
<title>Environment</title> |
| 551 |
|
| 552 |
<variablelist> |
| 553 |
<varlistentry> |
| 554 |
<term><envar>PGCTLTIMEOUT</envar></term> |
| 555 |
|
| 556 |
<listitem> |
| 557 |
<para> |
| 558 |
Default limit on the number of seconds to wait when waiting for startup |
| 559 |
or shutdown to complete. If not set, the default is 60 seconds. |
| 560 |
</para> |
| 561 |
</listitem> |
| 562 |
</varlistentry> |
| 563 |
|
| 564 |
<varlistentry> |
| 565 |
<term><envar>PGDATA</envar></term> |
| 566 |
|
| 567 |
<listitem> |
| 568 |
<para> |
| 569 |
Default data directory location. |
| 570 |
</para> |
| 571 |
</listitem> |
| 572 |
</varlistentry> |
| 573 |
|
| 574 |
</variablelist> |
| 575 |
|
| 576 |
<para> |
| 577 |
Most <command>pg_ctl</command> modes require knowing the data directory |
| 578 |
location; therefore, the <option>-D</option> option is required |
| 579 |
unless <envar>PGDATA</envar> is set. |
| 580 |
</para> |
| 581 |
|
| 582 |
<para> |
| 583 |
For additional variables that affect the server, |
| 584 |
see <xref linkend="app-postgres"/>. |
| 585 |
</para> |
| 586 |
</refsect1> |
| 587 |
|
| 588 |
|
| 589 |
<refsect1> |
| 590 |
<title>Files</title> |
| 591 |
|
| 592 |
<variablelist> |
| 593 |
<varlistentry> |
| 594 |
<term><filename>postmaster.pid</filename></term> |
| 595 |
|
| 596 |
<listitem> |
| 597 |
<para> |
| 598 |
<application>pg_ctl</application> examines this file in the data |
| 599 |
directory to determine whether the server is currently running. |
| 600 |
</para> |
| 601 |
</listitem> |
| 602 |
</varlistentry> |
| 603 |
|
| 604 |
<varlistentry> |
| 605 |
<term><filename>postmaster.opts</filename></term> |
| 606 |
|
| 607 |
<listitem> |
| 608 |
<para>If this file exists in the data directory, |
| 609 |
<application>pg_ctl</application> (in <option>restart</option> mode) |
| 610 |
will pass the contents of the file as options to |
| 611 |
<application>postgres</application>, unless overridden |
| 612 |
by the <option>-o</option> option. The contents of this file |
| 613 |
are also displayed in <option>status</option> mode. |
| 614 |
</para> |
| 615 |
</listitem> |
| 616 |
</varlistentry> |
| 617 |
|
| 618 |
</variablelist> |
| 619 |
</refsect1> |
| 620 |
|
| 621 |
|
| 622 |
<refsect1 id="r1-app-pgctl-2"> |
| 623 |
<title>Examples</title> |
| 624 |
|
| 625 |
<refsect2 id="r2-app-pgctl-3"> |
| 626 |
<title>Starting the Server</title> |
| 627 |
|
| 628 |
<para> |
| 629 |
To start the server, waiting until the server is |
| 630 |
accepting connections: |
| 631 |
<screen> |
| 632 |
<prompt>$</prompt> <userinput>pg_ctl start</userinput> |
| 633 |
</screen> |
| 634 |
</para> |
| 635 |
|
| 636 |
<para> |
| 637 |
To start the server using port 5433, and |
| 638 |
running without <function>fsync</function>, use: |
| 639 |
<screen> |
| 640 |
<prompt>$</prompt> <userinput>pg_ctl -o "-F -p 5433" start</userinput> |
| 641 |
</screen></para> |
| 642 |
</refsect2> |
| 643 |
|
| 644 |
<refsect2 id="r2-app-pgctl-4"> |
| 645 |
<title>Stopping the Server</title> |
| 646 |
<para> |
| 647 |
To stop the server, use: |
| 648 |
<screen> |
| 649 |
<prompt>$</prompt> <userinput>pg_ctl stop</userinput> |
| 650 |
</screen> |
| 651 |
The <option>-m</option> option allows control over |
| 652 |
<emphasis>how</emphasis> the server shuts down: |
| 653 |
<screen> |
| 654 |
<prompt>$</prompt> <userinput>pg_ctl stop -m smart</userinput> |
| 655 |
</screen></para> |
| 656 |
</refsect2> |
| 657 |
|
| 658 |
<refsect2 id="r2-app-pgctl-5"> |
| 659 |
<title>Restarting the Server</title> |
| 660 |
|
| 661 |
<para> |
| 662 |
Restarting the server is almost equivalent to stopping the |
| 663 |
server and starting it again, except that by default, |
| 664 |
<command>pg_ctl</command> saves and reuses the command line options that |
| 665 |
were passed to the previously-running instance. To restart |
| 666 |
the server using the same options as before, use: |
| 667 |
<screen> |
| 668 |
<prompt>$</prompt> <userinput>pg_ctl restart</userinput> |
| 669 |
</screen> |
| 670 |
</para> |
| 671 |
|
| 672 |
<para> |
| 673 |
But if <option>-o</option> is specified, that replaces any previous options. |
| 674 |
To restart using port 5433, disabling <function>fsync</function> upon restart: |
| 675 |
<screen> |
| 676 |
<prompt>$</prompt> <userinput>pg_ctl -o "-F -p 5433" restart</userinput> |
| 677 |
</screen></para> |
| 678 |
</refsect2> |
| 679 |
|
| 680 |
<refsect2 id="r2-app-pgctl-6"> |
| 681 |
<title>Showing the Server Status</title> |
| 682 |
|
| 683 |
<para> |
| 684 |
Here is sample status output from |
| 685 |
<application>pg_ctl</application>: |
| 686 |
<screen> |
| 687 |
<prompt>$</prompt> <userinput>pg_ctl status</userinput> |
| 688 |
<computeroutput> |
| 689 |
pg_ctl: server is running (PID: 13718) |
| 690 |
/usr/local/pgsql/bin/postgres "-D" "/usr/local/pgsql/data" "-p" "5433" "-B" "128" |
| 691 |
</computeroutput></screen> |
| 692 |
The second line is the command that would be invoked in restart mode. |
| 693 |
</para> |
| 694 |
</refsect2> |
| 695 |
</refsect1> |
| 696 |
|
| 697 |
|
| 698 |
<refsect1> |
| 699 |
<title>See Also</title> |
| 700 |
|
| 701 |
<simplelist type="inline"> |
| 702 |
<member><xref linkend="app-initdb"/></member> |
| 703 |
<member><xref linkend="app-postgres"/></member> |
| 704 |
</simplelist> |
| 705 |
</refsect1> |
| 706 |
|
| 707 |
</refentry> |