1PG_CTL(1)               PostgreSQL 9.2.24 Documentation              PG_CTL(1)
2
3
4

NAME

6       pg_ctl - initialize, start, stop, or control a PostgreSQL server
7

SYNOPSIS

9       pg_ctl init[db] [-s] [-D datadir] [-o initdb-options]
10
11       pg_ctl start [-w] [-t seconds] [-s] [-D datadir] [-l filename]
12              [-o options] [-p path] [-c]
13
14       pg_ctl stop [-W] [-t seconds] [-s] [-D datadir]
15              [-m s[mart] | f[ast] | i[mmediate]]
16
17       pg_ctl restart [-w] [-t seconds] [-s] [-D datadir] [-c]
18              [-m s[mart] | f[ast] | i[mmediate]] [-o options]
19
20       pg_ctl reload [-s] [-D datadir]
21
22       pg_ctl status [-D datadir]
23
24       pg_ctl promote [-s] [-D datadir]
25
26       pg_ctl kill signal_name process_id
27
28       pg_ctl register [-N servicename] [-U username] [-P password]
29              [-D datadir] [-S a[uto] | d[emand]] [-w] [-t seconds] [-s]
30              [-o options]
31
32       pg_ctl unregister [-N servicename]
33

DESCRIPTION

35       pg_ctl is a utility for initializing a PostgreSQL database cluster,
36       starting, stopping, or restarting the PostgreSQL database server
37       (postgres(1)), or displaying the status of a running server. Although
38       the server can be started manually, pg_ctl encapsulates tasks such as
39       redirecting log output and properly detaching from the terminal and
40       process group. It also provides convenient options for controlled
41       shutdown.
42
43       The init or initdb mode creates a new PostgreSQL database cluster. A
44       database cluster is a collection of databases that are managed by a
45       single server instance. This mode invokes the initdb command. See
46       initdb(1) for details.
47
48       In start mode, a new server is launched. The server is started in the
49       background, and its standard input is attached to /dev/null (or nul on
50       Windows). On Unix-like systems, by default, the server's standard
51       output and standard error are sent to pg_ctl's standard output (not
52       standard error). The standard output of pg_ctl should then be
53       redirected to a file or piped to another process such as a log rotating
54       program like rotatelogs; otherwise postgres will write its output to
55       the controlling terminal (from the background) and will not leave the
56       shell's process group. On Windows, by default the server's standard
57       output and standard error are sent to the terminal. These default
58       behaviors can be changed by using -l to append the server's output to a
59       log file. Use of either -l or output redirection is recommended.
60
61       In stop mode, the server that is running in the specified data
62       directory is shut down. Three different shutdown methods can be
63       selected with the -m option.  “Smart” mode (the default) waits for all
64       active clients to disconnect and any online backup to finish. If the
65       server is in hot standby, recovery and streaming replication will be
66       terminated once all clients have disconnected.  “Fast” mode does not
67       wait for clients to disconnect and will terminate an online backup in
68       progress. All active transactions are rolled back and clients are
69       forcibly disconnected, then the server is shut down.  “Immediate” mode
70       will abort all server processes immediately, without a clean shutdown.
71       This will lead to a crash-recovery run on the next restart.
72
73       restart mode effectively executes a stop followed by a start. This
74       allows changing the postgres command-line options.
75
76       reload mode simply sends the postgres process a SIGHUP signal, causing
77       it to reread its configuration files (postgresql.conf, pg_hba.conf,
78       etc.). This allows changing of configuration-file options that do not
79       require a complete restart to take effect.
80
81       status mode checks whether a server is running in the specified data
82       directory. If it is, the PID and the command line options that were
83       used to invoke it are displayed. If the server is not running, the
84       process returns an exit status of 3.
85
86       In promote mode, the standby server that is running in the specified
87       data directory is commanded to exit recovery and begin read-write
88       operations.
89
90       kill mode allows you to send a signal to a specified process. This is
91       particularly valuable for Microsoft Windows which does not have a kill
92       command. Use --help to see a list of supported signal names.
93
94       register mode allows you to register a system service on Microsoft
95       Windows. The -S option allows selection of service start type, either
96       “auto” (start service automatically on system startup) or “demand”
97       (start service on demand).
98
99       unregister mode allows you to unregister a system service on Microsoft
100       Windows. This undoes the effects of the register command.
101

OPTIONS

103       -c, --core-file
104           Attempt to allow server crashes to produce core files, on platforms
105           where this is possible, by lifting any soft resource limit placed
106           on core files. This is useful in debugging or diagnosing problems
107           by allowing a stack trace to be obtained from a failed server
108           process.
109
110       -D datadir, --pgdata datadir
111           Specifies the file system location of the database files. If this
112           is omitted, the environment variable PGDATA is used.
113
114       -l filename, --log filename
115           Append the server log output to filename. If the file does not
116           exist, it is created. The umask is set to 077, so access to the log
117           file is disallowed to other users by default.
118
119       -m mode, --mode mode
120           Specifies the shutdown mode.  mode can be smart, fast, or
121           immediate, or the first letter of one of these three. If this is
122           omitted, smart is used.
123
124       -o options
125           Specifies options to be passed directly to the postgres command.
126
127           The options should usually be surrounded by single or double quotes
128           to ensure that they are passed through as a group.
129
130       -o initdb-options
131           Specifies options to be passed directly to the initdb command.
132
133           The options should usually be surrounded by single or double quotes
134           to ensure that they are passed through as a group.
135
136       -p path
137           Specifies the location of the postgres executable. By default the
138           postgres executable is taken from the same directory as pg_ctl, or
139           failing that, the hard-wired installation directory. It is not
140           necessary to use this option unless you are doing something unusual
141           and get errors that the postgres executable was not found.
142
143           In init mode, this option analogously specifies the location of the
144           initdb executable.
145
146       -s, --silent
147           Print only errors, no informational messages.
148
149       -t, --timeout
150           The maximum number of seconds to wait when waiting for startup or
151           shutdown to complete. Defaults to the value of the PGCTLTIMEOUT
152           environment variable or, if not set, to 60 seconds.
153
154       -V, --version
155           Print the pg_ctl version and exit.
156
157       -w
158           Wait for the startup or shutdown to complete. Waiting is the
159           default option for shutdowns, but not startups. When waiting for
160           startup, pg_ctl repeatedly attempts to connect to the server. When
161           waiting for shutdown, pg_ctl waits for the server to remove its PID
162           file.  pg_ctl returns an exit code based on the success of the
163           startup or shutdown.
164
165       -W
166           Do not wait for startup or shutdown to complete. This is the
167           default for start and restart modes.
168
169       -?, --help
170           Show help about pg_ctl command line arguments, and exit.
171
172   Options for Windows
173       -N servicename
174           Name of the system service to register. The name will be used as
175           both the service name and the display name.
176
177       -P password
178           Password for the user to start the service.
179
180       -S start-type
181           Start type of the system service to register. start-type can be
182           auto, or demand, or the first letter of one of these two. If this
183           is omitted, auto is used.
184
185       -U username
186           User name for the user to start the service. For domain users, use
187           the format DOMAIN\username.
188

ENVIRONMENT

190       PGCTLTIMEOUT
191           Default limit on the number of seconds to wait when waiting for
192           startup or shutdown to complete. If not set, the default is 60
193           seconds.
194
195       PGDATA
196           Default data directory location.
197
198       pg_ctl, like most other PostgreSQL utilities, also uses the environment
199       variables supported by libpq (see Section 31.14, “Environment
200       Variables”, in the documentation). For additional server variables, see
201       postgres(1).
202

FILES

204       postmaster.pid
205           The existence of this file in the data directory is used to help
206           pg_ctl determine if the server is currently running.
207
208       postmaster.opts
209           If this file exists in the data directory, pg_ctl (in restart mode)
210           will pass the contents of the file as options to postgres, unless
211           overridden by the -o option. The contents of this file are also
212           displayed in status mode.
213

EXAMPLES

215   Starting the Server
216       To start the server:
217
218           $ pg_ctl start
219
220       To start the server, waiting until the server is accepting connections:
221
222           $ pg_ctl -w start
223
224       To start the server using port 5433, and running without fsync, use:
225
226           $ pg_ctl -o "-F -p 5433" start
227
228   Stopping the Server
229       To stop the server, use:
230
231           $ pg_ctl stop
232
233       The -m option allows control over how the server shuts down:
234
235           $ pg_ctl stop -m fast
236
237   Restarting the Server
238       Restarting the server is almost equivalent to stopping the server and
239       starting it again, except that pg_ctl saves and reuses the command line
240       options that were passed to the previously running instance. To restart
241       the server in the simplest form, use:
242
243           $ pg_ctl restart
244
245       To restart the server, waiting for it to shut down and restart:
246
247           $ pg_ctl -w restart
248
249       To restart using port 5433, disabling fsync upon restart:
250
251           $ pg_ctl -o "-F -p 5433" restart
252
253   Showing the Server Status
254       Here is sample status output from pg_ctl:
255
256           $ pg_ctl status
257           pg_ctl: server is running (PID: 13718)
258           /usr/local/pgsql/bin/postgres "-D" "/usr/local/pgsql/data" "-p" "5433" "-B" "128"
259
260       This is the command line that would be invoked in restart mode.
261

SEE ALSO

263       initdb(1), postgres(1)
264
265
266
267PostgreSQL 9.2.24                 2017-11-06                         PG_CTL(1)
Impressum