3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
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 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 pg_ctl \- initialize, start, stop, or control a PostgreSQL server
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
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]
60 is a utility for initializing a
62 database cluster, starting, stopping, or restarting the
64 database server (\fBpostgres\fR(1)), or displaying the status of a running server\&. Although the server can be started manually,
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\&.
74 database cluster, that is, a collection of databases that will be managed by a single server instance\&. This mode invokes the
81 mode launches a new server\&. The server is started in the background, and its standard input is attached to
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
88 should then be redirected to a file or piped to another process such as a log rotating program like
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
93 to append the server\*(Aqs output to a log file\&. Use of either
95 or output redirection is recommended\&.
98 mode shuts down the server that is running in the specified data directory\&. Three different shutdown methods can be selected with the
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\&.
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\&.
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\&.
109 mode effectively executes a stop followed by a start\&. This allows changing the
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,
115 is executed in the same current directory as it was during server start\&.
118 mode simply sends the
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\&.
126 mode checks whether a server is running in the specified data directory\&. If it is, the server\*(Aqs
128 and the command line options that were used to invoke it are displayed\&. If the server is not running,
130 returns an exit status of 3\&. If an accessible data directory is not specified,
132 returns an exit status of 4\&.
135 mode commands the standby server that is running in the specified data directory to end standby mode and begin read\-write operations\&.
138 mode rotates the server log file\&. For details on how to use this mode with external log rotation tools, see
142 mode sends a signal to a specified process\&. This is primarily valuable on
144 which does not have a built\-in
148 to see a list of supported signal names\&.
153 server as a system service on
154 Microsoft Windows\&. The
156 option allows selection of service start type, either
158 (start service automatically on system startup) or
160 (start service on demand)\&.
163 mode unregisters a system service on
164 Microsoft Windows\&. This undoes the effects of the
171 \fB\-\-core\-files\fR
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\&.
176 \fB\-D \fR\fB\fIdatadir\fR\fR
178 \fB\-\-pgdata=\fR\fB\fIdatadir\fR\fR
180 Specifies the file system location of the database configuration files\&. If this option is omitted, the environment variable
185 \fB\-l \fR\fB\fIfilename\fR\fR
187 \fB\-\-log=\fR\fB\fIfilename\fR\fR
189 Append the server log output to
190 \fIfilename\fR\&. If the file does not exist, it is created\&. The
192 is set to 077, so access to the log file is disallowed to other users by default\&.
195 \fB\-m \fR\fB\fImode\fR\fR
197 \fB\-\-mode=\fR\fB\fImode\fR\fR
199 Specifies the shutdown mode\&.
204 immediate, or the first letter of one of these three\&. If this option is omitted,
209 \fB\-o \fR\fB\fIoptions\fR\fR
211 \fB\-\-options=\fR\fB\fIoptions\fR\fR
213 Specifies options to be passed directly to the
217 can be specified multiple times, with all the given options being passed through\&.
221 should usually be surrounded by single or double quotes to ensure that they are passed through as a group\&.
224 \fB\-o \fR\fB\fIinitdb\-options\fR\fR
226 \fB\-\-options=\fR\fB\fIinitdb\-options\fR\fR
228 Specifies options to be passed directly to the
232 can be specified multiple times, with all the given options being passed through\&.
235 \fIinitdb\-options\fR
236 should usually be surrounded by single or double quotes to ensure that they are passed through as a group\&.
239 \fB\-p \fR\fB\fIpath\fR\fR
241 Specifies the location of the
243 executable\&. By default the
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
248 executable was not found\&.
252 mode, this option analogously specifies the location of the
261 Print only errors, no informational messages\&.
264 \fB\-t \fR\fB\fIseconds\fR\fR
266 \fB\-\-timeout=\fR\fB\fIseconds\fR\fR
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
271 environment variable or, if not set, to 60 seconds\&.
287 Wait for the operation to complete\&. This is supported for the modes
292 register, and is the default for those modes\&.
296 repeatedly checks the server\*(Aqs
298 file, sleeping for a short amount of time between checks\&. Startup is considered complete when the
300 file indicates that the server is ready to accept connections\&. Shutdown is considered complete when the server removes the
304 returns an exit code based on the success of the startup or shutdown\&.
306 If the operation does not complete within the timeout (see option
309 exits with a nonzero exit status\&. But note that the operation might continue in the background and eventually succeed\&.
316 Do not wait for the operation to complete\&. This is the opposite of the option
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\&.
321 In prior releases of PostgreSQL, this was the default except for the
332 command line arguments, and exit\&.
335 If an option is specified that is valid, but not relevant to the selected operating mode,
338 .SS "Options for Windows"
340 \fB\-e \fR\fB\fIsource\fR\fR
342 Name of the event source for
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
347 itself; once started, the server will use the event source specified by its
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
353 \fB\-N \fR\fB\fIservicename\fR\fR
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
359 \fB\-P \fR\fB\fIpassword\fR\fR
361 Password for the user to run the service as\&.
364 \fB\-S \fR\fB\fIstart\-type\fR\fR
366 Start type of the system service\&.
370 demand, or the first letter of one of these two\&. If this option is omitted,
375 \fB\-U \fR\fB\fIusername\fR\fR
377 User name for the user to run the service as\&. For domain users, use the format
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\&.
389 Default data directory location\&.
394 modes require knowing the data directory location; therefore, the
396 option is required unless
400 For additional variables that affect the server, see
407 examines this file in the data directory to determine whether the server is currently running\&.
412 If this file exists in the data directory,
416 mode) will pass the contents of the file as options to
417 postgres, unless overridden by the
419 option\&. The contents of this file are also displayed in
424 .SS "Starting the Server"
426 To start the server, waiting until the server is accepting connections:
438 To start the server using port 5433, and running without
445 $ \fBpg_ctl \-o "\-F \-p 5433" start\fR
450 .SS "Stopping the Server"
452 To stop the server, use:
466 option allows control over
468 the server shuts down:
474 $ \fBpg_ctl stop \-m smart\fR
479 .SS "Restarting the Server"
481 Restarting the server is almost equivalent to stopping the server and starting it again, except that by default,
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:
489 $ \fBpg_ctl restart\fR
497 is specified, that replaces any previous options\&. To restart using port 5433, disabling
505 $ \fBpg_ctl \-o "\-F \-p 5433" restart\fR
510 .SS "Showing the Server Status"
512 Here is sample status output from
519 $ \fBpg_ctl status\fR
521 pg_ctl: server is running (PID: 13718)
522 /usr/local/pgsql/bin/postgres "\-D" "/usr/local/pgsql/data" "\-p" "5433" "\-B" "128"
528 The second line is the command that would be invoked in restart mode\&.
530 \fBinitdb\fR(1), \fBpostgres\fR(1)