1PG_CTL(1)               PostgreSQL Server Applications               PG_CTL(1)
2
3
4

NAME

6       pg_ctl - start, stop, or restart a PostgreSQL server
7
8

SYNOPSIS

10       pg_ctl start [ -w ]  [ -t seconds ]  [ -s ]  [ -D datadir ]  [ -l file‐
11       name ]  [ -o options ]  [ -p path ]  [ -c ]
12
13       pg_ctl stop [ -W ]  [ -t seconds ]  [ -s ]  [ -D datadir ]  [ -m
14         [ s[mart] ]  [ f[ast] ]  [ i[mmediate] ]
15        ]
16
17       pg_ctl restart [ -w ]  [ -t seconds ]  [ -s ]  [ -D datadir ]  [  -c  ]
18       [ -m
19         [ s[mart] ]  [ f[ast] ]  [ i[mmediate] ]
20        ]  [ -o options ]
21
22       pg_ctl reload [ -s ]  [ -D datadir ]
23
24       pg_ctl status [ -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 ]  [ -w ]  [ -t seconds ]  [ -s ]  [ -o options ]
30
31       pg_ctl unregister [ -N servicename ]
32

DESCRIPTION

34       pg_ctl is a utility for starting, stopping,  or  restarting  the  Post‐
35       greSQL backend server (postgres(1)), or displaying the status of a run‐
36       ning server. Although the server can be started manually, pg_ctl encap‐
37       sulates  tasks  such  as  redirecting log output and properly detaching
38       from the terminal  and  process  group.  It  also  provides  convenient
39       options for controlled shutdown.
40
41       In  start  mode, a new server is launched. The server is started in the
42       background, and standard input is attached to /dev/null.  The  standard
43       output  and standard error are either appended to a log file (if the -l
44       option is used), or redirected to pg_ctl's standard output  (not  stan‐
45       dard  error).  If  no log file is chosen, the standard output of pg_ctl
46       should be redirected to a file or piped to another process  such  as  a
47       log rotating program like rotatelogs; otherwise postgres will write its
48       output to the controlling terminal (from the background) and  will  not
49       leave the shell's process group.
50
51       In  stop  mode, the server that is running in the specified data direc‐
52       tory is shut down. Three different shutdown  methods  can  be  selected
53       with the -m option: ``Smart'' mode waits for online backup mode to fin‐
54       ish and all the clients to disconnect. This is the  default.   ``Fast''
55       mode  does  not  wait  for  clients to disconnect and will terminate an
56       online backup in progress. All active transactions are rolled back  and
57       clients  are  forcibly  disconnected,  then  the  server  is shut down.
58       ``Immediate'' mode will abort all  server  processes  without  a  clean
59       shutdown. This will lead to a recovery run on restart.
60
61       restart  mode  effectively  executes  a  stop followed by a start. This
62       allows changing the postgres command-line options.
63
64       reload mode simply sends the postgres process a SIGHUP signal,  causing
65       it  to  reread  its  configuration files (postgresql.conf, pg_hba.conf,
66       etc.). This allows changing of configuration-file options that  do  not
67       require a complete restart to take effect.
68
69       status  mode  checks  whether a server is running in the specified data
70       directory. If it is, the PID and the command  line  options  that  were
71       used to invoke it are displayed.
72
73       kill  mode  allows you to send a signal to a specified process. This is
74       particularly valuable for Microsoft Windows which does not have a  kill
75       command. Use --help to see a list of supported signal names.
76
77       register mode allows you to register a system service on Microsoft Win‐
78       dows.
79
80       unregister mode allows you to unregister a system service on  Microsoft
81       Windows, previously registered with the register command.
82

OPTIONS

84       -c     Attempt  to allow server crashes to produce core files, on plat‐
85              forms where this available, by lifting any soft  resource  limit
86              placed on them.  This is useful in debugging or diagnosing prob‐
87              lems by allowing a stack trace to  be  obtained  from  a  failed
88              server process.
89
90       -D datadir
91              Specifies  the  file  system  location of the database files. If
92              this is omitted, the environment variable PGDATA is used.
93
94       -l filename
95              Append the server log output to filename. If the file  does  not
96              exist,  it is created. The umask is set to 077, so access to the
97              log file from other users is disallowed by default.
98
99       -m mode
100              Specifies the shutdown mode. mode can be smart, fast, or immedi‐
101              ate, or the first letter of one of these three.
102
103       -o options
104              Specifies options to be passed directly to the postgres command.
105
106              The options are usually surrounded by single or double quotes to
107              ensure that they are passed through as a group.
108
109       -p path
110              Specifies the location of the postgres  executable.  By  default
111              the  postgres  executable  is  taken  from the same directory as
112              pg_ctl, or failing that, the hard-wired installation  directory.
113              It  is  not  necessary  to  use this option unless you are doing
114              something unusual and get errors that  the  postgres  executable
115              was not found.
116
117       -s     Only print errors, no informational messages.
118
119       -t     The number of seconds to wait when waiting for start or shutdown
120              to complete.
121
122       -w     Wait for the start or shutdown to  complete.  The  default  wait
123              time  is 60 seconds. This is the default option for shutdowns. A
124              successful shutdown is indicated by removal of the PID file. For
125              starting up, a successful psql -l indicates success. pg_ctl will
126              attempt to use the proper port  for  psql.  If  the  environment
127              variable  PGPORT exists, that is used. Otherwise, it will see if
128              a port has been set in the postgresql.conf file.  If neither  of
129              those  is used, it will use the default port that PostgreSQL was
130              compiled with (5432  by  default).  When  waiting,  pg_ctl  will
131              return an accurate exit code based on the success of the startup
132              or shutdown.
133
134       -W     Do not wait for start or  shutdown  to  complete.  This  is  the
135              default for starts and restarts.
136
137   OPTIONS FOR WINDOWS
138       -N servicename
139              Name of the system service to register. The name will be used as
140              both the service name and the display name.
141
142       -P password
143              Password for the user to start the service.
144
145       -U username
146              User name for the user to start the service. For  domain  users,
147              use the format DOMAIN\username.
148

ENVIRONMENT

150       PGDATA Default data directory location.
151
152       PGPORT Default port for psql(1) (used by the -w option).
153
154       For  additional  server variables, see postgres(1).  This utility, like
155       most other PostgreSQL utilities, also uses  the  environment  variables
156       supported by libpq (see in the documentation).
157

FILES

159       postmaster.pid
160              The existence of this file in the data directory is used to help
161              pg_ctl determine if the server is currently running or not.
162
163       postmaster.opts
164              If this file exists in the data directory,  pg_ctl  (in  restart
165              mode) will pass the contents of the file as options to postgres,
166              unless overridden by the -o option. The contents  of  this  file
167              are also displayed in status mode.
168
169       postgresql.conf
170              This  file, located in the data directory, is parsed to find the
171              proper port to use with psql when the -w is given in start mode.
172

NOTES

174       Waiting for complete start is not a well-defined  operation  and  might
175       fail  if access control is set up so that a local client cannot connect
176       without manual interaction (e.g., password authentication).  For  addi‐
177       tional  connection  variables,  see in the documentation, and for pass‐
178       words, also see in the documentation.
179

EXAMPLES

181   STARTING THE SERVER
182       To start up a server:
183
184       $ pg_ctl start
185
186
187       An example of starting the server, blocking until the server  has  come
188       up is:
189
190       $ pg_ctl -w start
191
192
193       For a server using port 5433, and running without fsync, use:
194
195       $ pg_ctl -o "-F -p 5433" start
196
197
198   STOPPING THE SERVER
199       $ pg_ctl stop
200
201       stops  the  server.  Using  the -m switch allows one to control how the
202       backend shuts down.
203
204   RESTARTING THE SERVER
205       Restarting the server is almost equivalent to stopping the  server  and
206       starting  it again except that pg_ctl saves and reuses the command line
207       options that were passed to the previously running instance. To restart
208       the server in the simplest form, use:
209
210       $ pg_ctl restart
211
212
213       To restart server, waiting for it to shut down and to come up:
214
215       $ pg_ctl -w restart
216
217
218       To restart using port 5433 and disabling fsync after restarting:
219
220       $ pg_ctl -o "-F -p 5433" restart
221
222
223   SHOWING THE SERVER STATUS
224       Here is a sample status output from pg_ctl:
225
226       $ pg_ctl status
227       pg_ctl: server is running (pid: 13718)
228       Command line was:
229       /usr/local/pgsql/bin/postgres '-D' '/usr/local/pgsql/data' '-p' '5433' '-B' '128'
230
231       This is the command line that would be invoked in restart mode.
232

SEE ALSO

234       postgres(1)
235
236
237
238Application                       2014-02-17                         PG_CTL(1)
Impressum