]> begriffs open source - ai-pg/blob - full-docs/man1/pg_ctl.1
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / man1 / pg_ctl.1
1 '\" t
2 .\"     Title: pg_ctl
3 .\"    Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\"      Date: 2025
6 .\"    Manual: PostgreSQL 18.0 Documentation
7 .\"    Source: PostgreSQL 18.0
8 .\"  Language: English
9 .\"
10 .TH "PG_CTL" "1" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 pg_ctl \- initialize, start, stop, or control a PostgreSQL server
32 .SH "SYNOPSIS"
33 .HP \w'\fBpg_ctl\fR\ 'u
34 \fBpg_ctl\fR \fBinit[db]\fR [\fB\-D\fR\ \fIdatadir\fR] [\fB\-s\fR] [\fB\-o\fR\ \fIinitdb\-options\fR]
35 .HP \w'\fBpg_ctl\fR\ 'u
36 \fBpg_ctl\fR \fBstart\fR [\fB\-D\fR\ \fIdatadir\fR] [\fB\-l\fR\ \fIfilename\fR] [\fB\-W\fR] [\fB\-t\fR\ \fIseconds\fR] [\fB\-s\fR] [\fB\-o\fR\ \fIoptions\fR] [\fB\-p\fR\ \fIpath\fR] [\fB\-c\fR]
37 .HP \w'\fBpg_ctl\fR\ 'u
38 \fBpg_ctl\fR \fBstop\fR [\fB\-D\fR\ \fIdatadir\fR] [\fB\-m\fR\ \fBs[mart]\fR\ |\ \fBf[ast]\fR\ |\ \fBi[mmediate]\fR] [\fB\-W\fR] [\fB\-t\fR\ \fIseconds\fR] [\fB\-s\fR]
39 .HP \w'\fBpg_ctl\fR\ 'u
40 \fBpg_ctl\fR \fBrestart\fR [\fB\-D\fR\ \fIdatadir\fR] [\fB\-m\fR\ \fBs[mart]\fR\ |\ \fBf[ast]\fR\ |\ \fBi[mmediate]\fR] [\fB\-W\fR] [\fB\-t\fR\ \fIseconds\fR] [\fB\-s\fR] [\fB\-o\fR\ \fIoptions\fR] [\fB\-c\fR]
41 .HP \w'\fBpg_ctl\fR\ 'u
42 \fBpg_ctl\fR \fBreload\fR [\fB\-D\fR\ \fIdatadir\fR] [\fB\-s\fR]
43 .HP \w'\fBpg_ctl\fR\ 'u
44 \fBpg_ctl\fR \fBstatus\fR [\fB\-D\fR\ \fIdatadir\fR]
45 .HP \w'\fBpg_ctl\fR\ 'u
46 \fBpg_ctl\fR \fBpromote\fR [\fB\-D\fR\ \fIdatadir\fR] [\fB\-W\fR] [\fB\-t\fR\ \fIseconds\fR] [\fB\-s\fR]
47 .HP \w'\fBpg_ctl\fR\ 'u
48 \fBpg_ctl\fR \fBlogrotate\fR [\fB\-D\fR\ \fIdatadir\fR] [\fB\-s\fR]
49 .HP \w'\fBpg_ctl\fR\ 'u
50 \fBpg_ctl\fR \fBkill\fR \fIsignal_name\fR \fIprocess_id\fR
51 .PP
52 On Microsoft Windows, also:
53 .HP \w'\fBpg_ctl\fR\ 'u
54 \fBpg_ctl\fR \fBregister\fR [\fB\-D\fR\ \fIdatadir\fR] [\fB\-N\fR\ \fIservicename\fR] [\fB\-U\fR\ \fIusername\fR] [\fB\-P\fR\ \fIpassword\fR] [\fB\-S\fR\ \fBa[uto]\fR\ |\ \fBd[emand]\fR] [\fB\-e\fR\ \fIsource\fR] [\fB\-W\fR] [\fB\-t\fR\ \fIseconds\fR] [\fB\-s\fR] [\fB\-o\fR\ \fIoptions\fR]
55 .HP \w'\fBpg_ctl\fR\ 'u
56 \fBpg_ctl\fR \fBunregister\fR [\fB\-N\fR\ \fIservicename\fR]
57 .SH "DESCRIPTION"
58 .PP
59 pg_ctl
60 is a utility for initializing a
61 PostgreSQL
62 database cluster, starting, stopping, or restarting the
63 PostgreSQL
64 database server (\fBpostgres\fR(1)), or displaying the status of a running server\&. Although the server can be started manually,
65 pg_ctl
66 encapsulates tasks such as redirecting log output and properly detaching from the terminal and process group\&. It also provides convenient options for controlled shutdown\&.
67 .PP
68 The
69 \fBinit\fR
70 or
71 \fBinitdb\fR
72 mode creates a new
73 PostgreSQL
74 database cluster, that is, a collection of databases that will be managed by a single server instance\&. This mode invokes the
75 \fBinitdb\fR
76 command\&. See
77 \fBinitdb\fR(1)
78 for details\&.
79 .PP
80 \fBstart\fR
81 mode launches a new server\&. The server is started in the background, and its standard input is attached to
82 /dev/null
83 (or
84 nul
85 on Windows)\&. On Unix\-like systems, by default, the server\*(Aqs standard output and standard error are sent to
86 pg_ctl\*(Aqs standard output (not standard error)\&. The standard output of
87 pg_ctl
88 should then be redirected to a file or piped to another process such as a log rotating program like
89 rotatelogs; otherwise
90 \fBpostgres\fR
91 will write its output to the controlling terminal (from the background) and will not leave the shell\*(Aqs process group\&. On Windows, by default the server\*(Aqs standard output and standard error are sent to the terminal\&. These default behaviors can be changed by using
92 \fB\-l\fR
93 to append the server\*(Aqs output to a log file\&. Use of either
94 \fB\-l\fR
95 or output redirection is recommended\&.
96 .PP
97 \fBstop\fR
98 mode shuts down the server that is running in the specified data directory\&. Three different shutdown methods can be selected with the
99 \fB\-m\fR
100 option\&.
101 \(lqSmart\(rq
102 mode disallows new connections, then waits for all existing clients to disconnect\&. If the server is in hot standby, recovery and streaming replication will be terminated once all clients have disconnected\&.
103 \(lqFast\(rq
104 mode (the default) does not wait for clients to disconnect\&. All active transactions are rolled back and clients are forcibly disconnected, then the server is shut down\&.
105 \(lqImmediate\(rq
106 mode will abort all server processes immediately, without a clean shutdown\&. This choice will lead to a crash\-recovery cycle during the next server start\&.
107 .PP
108 \fBrestart\fR
109 mode effectively executes a stop followed by a start\&. This allows changing the
110 \fBpostgres\fR
111 command\-line options, or changing configuration\-file options that cannot be changed without restarting the server\&. If relative paths were used on the command line during server start,
112 \fBrestart\fR
113 might fail unless
114 pg_ctl
115 is executed in the same current directory as it was during server start\&.
116 .PP
117 \fBreload\fR
118 mode simply sends the
119 \fBpostgres\fR
120 server process a
121 SIGHUP
122 signal, causing it to reread its configuration files (postgresql\&.conf,
123 pg_hba\&.conf, etc\&.)\&. This allows changing configuration\-file options that do not require a full server restart to take effect\&.
124 .PP
125 \fBstatus\fR
126 mode checks whether a server is running in the specified data directory\&. If it is, the server\*(Aqs
127 PID
128 and the command line options that were used to invoke it are displayed\&. If the server is not running,
129 pg_ctl
130 returns an exit status of 3\&. If an accessible data directory is not specified,
131 pg_ctl
132 returns an exit status of 4\&.
133 .PP
134 \fBpromote\fR
135 mode commands the standby server that is running in the specified data directory to end standby mode and begin read\-write operations\&.
136 .PP
137 \fBlogrotate\fR
138 mode rotates the server log file\&. For details on how to use this mode with external log rotation tools, see
139 Section\ \&24.3\&.
140 .PP
141 \fBkill\fR
142 mode sends a signal to a specified process\&. This is primarily valuable on
143 Microsoft Windows
144 which does not have a built\-in
145 kill
146 command\&. Use
147 \-\-help
148 to see a list of supported signal names\&.
149 .PP
150 \fBregister\fR
151 mode registers the
152 PostgreSQL
153 server as a system service on
154 Microsoft Windows\&. The
155 \fB\-S\fR
156 option allows selection of service start type, either
157 \(lqauto\(rq
158 (start service automatically on system startup) or
159 \(lqdemand\(rq
160 (start service on demand)\&.
161 .PP
162 \fBunregister\fR
163 mode unregisters a system service on
164 Microsoft Windows\&. This undoes the effects of the
165 \fBregister\fR
166 command\&.
167 .SH "OPTIONS"
168 .PP
169 \fB\-c\fR
170 .br
171 \fB\-\-core\-files\fR
172 .RS 4
173 Attempt to allow server crashes to produce core files, on platforms where this is possible, by lifting any soft resource limit placed on core files\&. This is useful in debugging or diagnosing problems by allowing a stack trace to be obtained from a failed server process\&.
174 .RE
175 .PP
176 \fB\-D \fR\fB\fIdatadir\fR\fR
177 .br
178 \fB\-\-pgdata=\fR\fB\fIdatadir\fR\fR
179 .RS 4
180 Specifies the file system location of the database configuration files\&. If this option is omitted, the environment variable
181 \fBPGDATA\fR
182 is used\&.
183 .RE
184 .PP
185 \fB\-l \fR\fB\fIfilename\fR\fR
186 .br
187 \fB\-\-log=\fR\fB\fIfilename\fR\fR
188 .RS 4
189 Append the server log output to
190 \fIfilename\fR\&. If the file does not exist, it is created\&. The
191 umask
192 is set to 077, so access to the log file is disallowed to other users by default\&.
193 .RE
194 .PP
195 \fB\-m \fR\fB\fImode\fR\fR
196 .br
197 \fB\-\-mode=\fR\fB\fImode\fR\fR
198 .RS 4
199 Specifies the shutdown mode\&.
200 \fImode\fR
201 can be
202 smart,
203 fast, or
204 immediate, or the first letter of one of these three\&. If this option is omitted,
205 fast
206 is the default\&.
207 .RE
208 .PP
209 \fB\-o \fR\fB\fIoptions\fR\fR
210 .br
211 \fB\-\-options=\fR\fB\fIoptions\fR\fR
212 .RS 4
213 Specifies options to be passed directly to the
214 \fBpostgres\fR
215 command\&.
216 \fB\-o\fR
217 can be specified multiple times, with all the given options being passed through\&.
218 .sp
219 The
220 \fIoptions\fR
221 should usually be surrounded by single or double quotes to ensure that they are passed through as a group\&.
222 .RE
223 .PP
224 \fB\-o \fR\fB\fIinitdb\-options\fR\fR
225 .br
226 \fB\-\-options=\fR\fB\fIinitdb\-options\fR\fR
227 .RS 4
228 Specifies options to be passed directly to the
229 \fBinitdb\fR
230 command\&.
231 \fB\-o\fR
232 can be specified multiple times, with all the given options being passed through\&.
233 .sp
234 The
235 \fIinitdb\-options\fR
236 should usually be surrounded by single or double quotes to ensure that they are passed through as a group\&.
237 .RE
238 .PP
239 \fB\-p \fR\fB\fIpath\fR\fR
240 .RS 4
241 Specifies the location of the
242 postgres
243 executable\&. By default the
244 postgres
245 executable is taken from the same directory as
246 \fBpg_ctl\fR, or failing that, the hard\-wired installation directory\&. It is not necessary to use this option unless you are doing something unusual and get errors that the
247 postgres
248 executable was not found\&.
249 .sp
250 In
251 init
252 mode, this option analogously specifies the location of the
253 initdb
254 executable\&.
255 .RE
256 .PP
257 \fB\-s\fR
258 .br
259 \fB\-\-silent\fR
260 .RS 4
261 Print only errors, no informational messages\&.
262 .RE
263 .PP
264 \fB\-t \fR\fB\fIseconds\fR\fR
265 .br
266 \fB\-\-timeout=\fR\fB\fIseconds\fR\fR
267 .RS 4
268 Specifies the maximum number of seconds to wait when waiting for an operation to complete (see option
269 \fB\-w\fR)\&. Defaults to the value of the
270 \fBPGCTLTIMEOUT\fR
271 environment variable or, if not set, to 60 seconds\&.
272 .RE
273 .PP
274 \fB\-V\fR
275 .br
276 \fB\-\-version\fR
277 .RS 4
278 Print the
279 pg_ctl
280 version and exit\&.
281 .RE
282 .PP
283 \fB\-w\fR
284 .br
285 \fB\-\-wait\fR
286 .RS 4
287 Wait for the operation to complete\&. This is supported for the modes
288 start,
289 stop,
290 restart,
291 promote, and
292 register, and is the default for those modes\&.
293 .sp
294 When waiting,
295 \fBpg_ctl\fR
296 repeatedly checks the server\*(Aqs
297 PID
298 file, sleeping for a short amount of time between checks\&. Startup is considered complete when the
299 PID
300 file indicates that the server is ready to accept connections\&. Shutdown is considered complete when the server removes the
301 PID
302 file\&.
303 \fBpg_ctl\fR
304 returns an exit code based on the success of the startup or shutdown\&.
305 .sp
306 If the operation does not complete within the timeout (see option
307 \fB\-t\fR), then
308 \fBpg_ctl\fR
309 exits with a nonzero exit status\&. But note that the operation might continue in the background and eventually succeed\&.
310 .RE
311 .PP
312 \fB\-W\fR
313 .br
314 \fB\-\-no\-wait\fR
315 .RS 4
316 Do not wait for the operation to complete\&. This is the opposite of the option
317 \fB\-w\fR\&.
318 .sp
319 If waiting is disabled, the requested action is triggered, but there is no feedback about its success\&. In that case, the server log file or an external monitoring system would have to be used to check the progress and success of the operation\&.
320 .sp
321 In prior releases of PostgreSQL, this was the default except for the
322 stop
323 mode\&.
324 .RE
325 .PP
326 \fB\-?\fR
327 .br
328 \fB\-\-help\fR
329 .RS 4
330 Show help about
331 pg_ctl
332 command line arguments, and exit\&.
333 .RE
334 .PP
335 If an option is specified that is valid, but not relevant to the selected operating mode,
336 pg_ctl
337 ignores it\&.
338 .SS "Options for Windows"
339 .PP
340 \fB\-e \fR\fB\fIsource\fR\fR
341 .RS 4
342 Name of the event source for
343 pg_ctl
344 to use for logging to the event log when running as a Windows service\&. The default is
345 PostgreSQL\&. Note that this only controls messages sent from
346 pg_ctl
347 itself; once started, the server will use the event source specified by its
348 event_source
349 parameter\&. Should the server fail very early in startup, before that parameter has been set, it might also log using the default event source name
350 PostgreSQL\&.
351 .RE
352 .PP
353 \fB\-N \fR\fB\fIservicename\fR\fR
354 .RS 4
355 Name of the system service to register\&. This name will be used as both the service name and the display name\&. The default is
356 PostgreSQL\&.
357 .RE
358 .PP
359 \fB\-P \fR\fB\fIpassword\fR\fR
360 .RS 4
361 Password for the user to run the service as\&.
362 .RE
363 .PP
364 \fB\-S \fR\fB\fIstart\-type\fR\fR
365 .RS 4
366 Start type of the system service\&.
367 \fIstart\-type\fR
368 can be
369 auto, or
370 demand, or the first letter of one of these two\&. If this option is omitted,
371 auto
372 is the default\&.
373 .RE
374 .PP
375 \fB\-U \fR\fB\fIusername\fR\fR
376 .RS 4
377 User name for the user to run the service as\&. For domain users, use the format
378 DOMAIN\eusername\&.
379 .RE
380 .SH "ENVIRONMENT"
381 .PP
382 \fBPGCTLTIMEOUT\fR
383 .RS 4
384 Default limit on the number of seconds to wait when waiting for startup or shutdown to complete\&. If not set, the default is 60 seconds\&.
385 .RE
386 .PP
387 \fBPGDATA\fR
388 .RS 4
389 Default data directory location\&.
390 .RE
391 .PP
392 Most
393 \fBpg_ctl\fR
394 modes require knowing the data directory location; therefore, the
395 \fB\-D\fR
396 option is required unless
397 \fBPGDATA\fR
398 is set\&.
399 .PP
400 For additional variables that affect the server, see
401 \fBpostgres\fR(1)\&.
402 .SH "FILES"
403 .PP
404 postmaster\&.pid
405 .RS 4
406 pg_ctl
407 examines this file in the data directory to determine whether the server is currently running\&.
408 .RE
409 .PP
410 postmaster\&.opts
411 .RS 4
412 If this file exists in the data directory,
413 pg_ctl
414 (in
415 \fBrestart\fR
416 mode) will pass the contents of the file as options to
417 postgres, unless overridden by the
418 \fB\-o\fR
419 option\&. The contents of this file are also displayed in
420 \fBstatus\fR
421 mode\&.
422 .RE
423 .SH "EXAMPLES"
424 .SS "Starting the Server"
425 .PP
426 To start the server, waiting until the server is accepting connections:
427 .sp
428 .if n \{\
429 .RS 4
430 .\}
431 .nf
432 $ \fBpg_ctl start\fR
433 .fi
434 .if n \{\
435 .RE
436 .\}
437 .PP
438 To start the server using port 5433, and running without
439 \fBfsync\fR, use:
440 .sp
441 .if n \{\
442 .RS 4
443 .\}
444 .nf
445 $ \fBpg_ctl \-o "\-F \-p 5433" start\fR
446 .fi
447 .if n \{\
448 .RE
449 .\}
450 .SS "Stopping the Server"
451 .PP
452 To stop the server, use:
453 .sp
454 .if n \{\
455 .RS 4
456 .\}
457 .nf
458 $ \fBpg_ctl stop\fR
459 .fi
460 .if n \{\
461 .RE
462 .\}
463 .sp
464 The
465 \fB\-m\fR
466 option allows control over
467 \fIhow\fR
468 the server shuts down:
469 .sp
470 .if n \{\
471 .RS 4
472 .\}
473 .nf
474 $ \fBpg_ctl stop \-m smart\fR
475 .fi
476 .if n \{\
477 .RE
478 .\}
479 .SS "Restarting the Server"
480 .PP
481 Restarting the server is almost equivalent to stopping the server and starting it again, except that by default,
482 \fBpg_ctl\fR
483 saves and reuses the command line options that were passed to the previously\-running instance\&. To restart the server using the same options as before, use:
484 .sp
485 .if n \{\
486 .RS 4
487 .\}
488 .nf
489 $ \fBpg_ctl restart\fR
490 .fi
491 .if n \{\
492 .RE
493 .\}
494 .PP
495 But if
496 \fB\-o\fR
497 is specified, that replaces any previous options\&. To restart using port 5433, disabling
498 \fBfsync\fR
499 upon restart:
500 .sp
501 .if n \{\
502 .RS 4
503 .\}
504 .nf
505 $ \fBpg_ctl \-o "\-F \-p 5433" restart\fR
506 .fi
507 .if n \{\
508 .RE
509 .\}
510 .SS "Showing the Server Status"
511 .PP
512 Here is sample status output from
513 pg_ctl:
514 .sp
515 .if n \{\
516 .RS 4
517 .\}
518 .nf
519 $ \fBpg_ctl status\fR
520
521 pg_ctl: server is running (PID: 13718)
522 /usr/local/pgsql/bin/postgres "\-D" "/usr/local/pgsql/data" "\-p" "5433" "\-B" "128"
523 .fi
524 .if n \{\
525 .RE
526 .\}
527 .sp
528 The second line is the command that would be invoked in restart mode\&.
529 .SH "SEE ALSO"
530 \fBinitdb\fR(1), \fBpostgres\fR(1)