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

NAME

6       postgres - PostgreSQL database server
7
8

SYNOPSIS

10       postgres [ option... ]
11

DESCRIPTION

13       postgres  is  the  PostgreSQL  database  server.  In order for a client
14       application to access  a  database  it  connects  (over  a  network  or
15       locally)  to  a  running  postgres process.  The postgres instance then
16       starts a separate server process to handle the connection.
17
18       One postgres instance always manages the data from exactly one database
19       cluster. A database cluster is a collection of databases that is stored
20       at a common file system location (the ``data  area'').  More  than  one
21       postgres  process  can run on a system at one time, so long as they use
22       different data areas and different  communication  ports  (see  below).
23       When  postgres  starts  it needs to know the location of the data area.
24       The location must be specified by the -D option or the PGDATA  environ‐
25       ment  variable;  there  is  no  default. Typically, -D or PGDATA points
26       directly to the data area directory created by initdb(1). Other  possi‐
27       ble file layouts are discussed in in the documentation.
28
29       By default postgres starts in the foreground and prints log messages to
30       the standard error stream. In practical applications postgres should be
31       started as a background process, perhaps at boot time.
32
33       The  postgres  command can also be called in single-user mode. The pri‐
34       mary use for this mode is during bootstrapping by initdb(1).  Sometimes
35       it  is used for debugging or disaster recovery (but note that running a
36       single-user server is not truly  suitable  for  debugging  the  server,
37       since no realistic interprocess communication and locking will happen).
38       When invoked in single-user mode from the shell,  the  user  can  enter
39       queries  and  the  results will be printed to the screen, but in a form
40       that is more useful for developers than end users. In  the  single-user
41       mode,  the session user will be set to the user with ID 1, and implicit
42       superuser powers are granted to this user.  This user does not actually
43       have  to exist, so the single-user mode can be used to manually recover
44       from certain kinds of accidental damage to the system catalogs.
45

OPTIONS

47       postgres accepts the following command-line arguments. For  a  detailed
48       discussion  of  the  options consult in the documentation. You can save
49       typing most of these options by setting up a configuration  file.  Some
50       (safe)  options can also be set from the connecting client in an appli‐
51       cation-dependent way to apply only for that session.  For  example,  if
52       the  environment  variable  PGOPTIONS  is set, then libpq-based clients
53       will pass that string to the server, which will interpret it  as  post‐
54       gres command-line options.
55
56   GENERAL PURPOSE
57       -A 0|1 Enables  run-time  assertion checks, which is a debugging aid to
58              detect programming mistakes. This option is  only  available  if
59              assertions were enabled when PostgreSQL was compiled. If so, the
60              default is on.
61
62       -B nbuffers
63              Sets the number of shared buffers for use  by  the  server  pro‐
64              cesses.  The default value of this parameter is chosen automati‐
65              cally by initdb; refer to in the documentation for more informa‐
66              tion.
67
68       -c name=value
69              Sets  a  named  run-time parameter. The configuration parameters
70              supported by PostgreSQL are described in in  the  documentation.
71              Most  of  the other command line options are in fact short forms
72              of such a parameter assignment. -c can appear multiple times  to
73              set multiple parameters.
74
75       -d debug-level
76              Sets  the  debug  level.  The higher this value is set, the more
77              debugging output is written to the server log. Values are from 1
78              to  5.  It is also possible to pass -d 0 for a specific session,
79              which will prevent the server log level of the  parent  postgres
80              process from being propagated to this session.
81
82       -D datadir
83              Specifies the file system location of the data directory or con‐
84              figuration file(s). See in the documentation for details.
85
86       -e     Sets the default date style to ``European'', that is DMY  order‐
87              ing of input date fields. This also causes the day to be printed
88              before the month in certain date output  formats.   See  in  the
89              documentation for more information.
90
91       -F     Disables  fsync  calls  for improved performance, at the risk of
92              data corruption in the event of a system crash. Specifying  this
93              option is equivalent to disabling the fsync configuration param‐
94              eter. Read the detailed documentation before using this!
95
96       -h hostname
97              Specifies the IP host name or address on which  postgres  is  to
98              listen  for  TCP/IP  connections  from  client applications. The
99              value can also be a comma-separated list of addresses, or  *  to
100              specify  listening  on  all available interfaces. An empty value
101              specifies not listening on any IP addresses, in which case  only
102              Unix-domain  sockets  can  be  used  to  connect  to the server.
103              Defaults to listening only on localhost.  Specifying this option
104              is  equivalent  to  setting  the  listen_addresses configuration
105              parameter.
106
107       -i     Allows remote clients to connect via  TCP/IP  (Internet  domain)
108              connections.  Without  this  option,  only local connections are
109              accepted. This option is equivalent to setting  listen_addresses
110              to * in postgresql.conf or via -h.
111
112              This  option is deprecated since it does not allow access to the
113              full functionality of listen_addresses.  It's usually better  to
114              set listen_addresses directly.
115
116       -k directory
117              Specifies the directory of the Unix-domain socket on which post‐
118              gres is to listen for connections from client applications.  The
119              default is normally /tmp, but can be changed at build time.
120
121       -l     Enables secure connections using SSL.  PostgreSQL must have been
122              compiled with support for SSL for this option to  be  available.
123              For  more  information  on using SSL, refer to in the documenta‐
124              tion.
125
126       -N max-connections
127              Sets the maximum number of client connections that  this  server
128              will  accept. By default, this value is 32, but it can be set as
129              high as your system will support. (Note that -B is  required  to
130              be  at least twice -N. See in the documentation for a discussion
131              of system resource requirements for large numbers of client con‐
132              nections.)  Specifying  this option is equivalent to setting the
133              max_connections configuration parameter.
134
135       -o extra-options
136              The command line-style options specified  in  extra-options  are
137              passed to all server processes started by this postgres process.
138              If the option string contains any spaces, the entire string must
139              be quoted.
140
141              The use of this option is obsolete; all command-line options for
142              server processes can be specified directly on the postgres  com‐
143              mand line.
144
145       -p port
146              Specifies  the  TCP/IP  port  or  local  Unix domain socket file
147              extension on which postgres is to listen  for  connections  from
148              client  applications.  Defaults to the value of the PGPORT envi‐
149              ronment variable, or if PGPORT is not set, then defaults to  the
150              value  established  during  compilation  (normally 5432). If you
151              specify a port other than the  default  port,  then  all  client
152              applications  must  specify  the same port using either command-
153              line options or PGPORT.
154
155       -s     Print time information and other statistics at the end  of  each
156              command.   This  is useful for benchmarking or for use in tuning
157              the number of buffers.
158
159       -S work-mem
160              Specifies the amount of memory to be used by internal sorts  and
161              hashes  before  resorting  to  temporary  disk  files.  See  the
162              description of the work_mem configuration parameter  in  in  the
163              documentation.
164
165       --name=value
166              Sets a named run-time parameter; a shorter form of -c.
167
168       --describe-config
169              This  option dumps out the server's internal configuration vari‐
170              ables, descriptions, and defaults in tab-delimited COPY  format.
171              It is designed primarily for use by administration tools.
172
173   SEMI-INTERNAL OPTIONS
174       There  are several other options that may be specified, used mainly for
175       debugging purposes and in some cases to assist with recovery of severe‐
176       ly  damaged  databases. There should be no reason to use them in a pro‐
177       duction database setup. These are listed here only for the use by Post‐
178       greSQL  system developers. Furthermore, any of these options may disap‐
179       pear or change in a future release without notice.
180
181       -f { s | i | m | n | h }
182              Forbids the use of particular scan and join  methods:  s  and  i
183              disable sequential and index scans respectively, while n, m, and
184              h disable nested-loop, merge and hash joins respectively.
185
186              Neither sequential scans nor nested-loop joins can  be  disabled
187              completely;  the -fs and -fn options simply discourage the opti‐
188              mizer from using those plan types if it has any  other  alterna‐
189              tive.
190
191       -n     This  option  is  for  debugging  problems  that  cause a server
192              process to die abnormally. The ordinary strategy in this  situa‐
193              tion is to notify all other server processes that they must ter‐
194              minate and then reinitialize the shared memory  and  semaphores.
195              This  is  because  an errant server process could have corrupted
196              some shared state before terminating. This option specifies that
197              postgres  will not reinitialize shared data structures. A knowl‐
198              edgeable system programmer can then use a  debugger  to  examine
199              shared memory and semaphore state.
200
201       -O     Allows  the  structure  of system tables to be modified. This is
202              used by initdb.
203
204       -P     Ignore system indexes when  reading  system  tables  (but  still
205              update  the  indexes  when modifying the tables). This is useful
206              when recovering from damaged system indexes.
207
208       -t pa[rser] | pl[anner] | e[xecutor]
209              Print timing statistics for each query relating to each  of  the
210              major  system  modules. This option cannot be used together with
211              the -s option.
212
213       -T     This option is  for  debugging  problems  that  cause  a  server
214              process  to die abnormally. The ordinary strategy in this situa‐
215              tion is to notify all other server processes that they must ter‐
216              minate  and  then reinitialize the shared memory and semaphores.
217              This is because an errant server process  could  have  corrupted
218              some shared state before terminating. This option specifies that
219              postgres will stop all other server  processes  by  sending  the
220              signal  SIGSTOP, but will not cause them to terminate. This per‐
221              mits system programmers to collect core dumps  from  all  server
222              processes by hand.
223
224       -v protocol
225              Specifies the version number of the frontend/backend protocol to
226              be used for a particular session. This option  is  for  internal
227              use only.
228
229       -W seconds
230              A delay of this many seconds occurs when a new server process is
231              started, after it conducts the authentication  procedure.   This
232              is  intended  to  give  an  opportunity  to attach to the server
233              process with a debugger.
234
235       -y database
236              Indicates that this is a subprocess started by a parent postgres
237              process,  and  specifies the database to use. This option is for
238              internal use only.
239
240   OPTIONS FOR SINGLE-USER MODE
241       The following options only apply to the single-user mode.
242
243       --single
244              Selects the single-user mode. This must be the first argument on
245              the command line.
246
247       database
248              Specifies  the  name  of  the  database to be accessed. If it is
249              omitted it defaults to the user name.
250
251       -E     Echo all commands.
252
253       -j     Disables use of newline as a statement delimiter.
254
255       -r filename
256              Send all server log output  to  filename.  In  normal  multiuser
257              mode,  this  option  is  ignored, and stderr is used by all pro‐
258              cesses.
259

ENVIRONMENT

261       PGCLIENTENCODING
262              Default character encoding used by  clients.  (The  clients  may
263              override  this  individually.) This value can also be set in the
264              configuration file.
265
266       PGDATA Default data directory location
267
268       PGDATESTYLE
269              Default value of the datestyle run-time parameter. (The  use  of
270              this environment variable is deprecated.)
271
272       PGPORT Default port (preferably set in the configuration file)
273
274       TZ     Server time zone
275

DIAGNOSTICS

277       A  failure  message  mentioning semget or shmget probably indicates you
278       need to configure your kernel to provide  adequate  shared  memory  and
279       semaphores.  For  more  discussion see in the documentation. You may be
280       able to postpone reconfiguring your kernel by decreasing shared_buffers
281       to reduce the shared memory consumption of PostgreSQL, and/or by reduc‐
282       ing max_connections to reduce the semaphore consumption.
283
284       A failure message suggesting that another  server  is  already  running
285       should be checked carefully, for example by using the command
286
287       $ ps ax | grep postgres
288
289       or
290
291       $ ps -ef | grep postgres
292
293       depending on your system. If you are certain that no conflicting server
294       is running, you may remove the lock file mentioned in the  message  and
295       try again.
296
297       A  failure  message indicating inability to bind to a port may indicate
298       that that port is already in use by some  non-PostgreSQL  process.  You
299       may  also  get  this  error  if  you terminate postgres and immediately
300       restart it using the same port; in this case, you must  simply  wait  a
301       few  seconds  until  the operating system closes the port before trying
302       again. Finally, you may get this error if you  specify  a  port  number
303       that  your operating system considers to be reserved. For example, many
304       versions of Unix consider port numbers under 1024 to be ``trusted'' and
305       only permit the Unix superuser to access them.
306

NOTES

308       If  at  all  possible,  do  not  use  SIGKILL to kill the main postgres
309       server.  Doing  so  will  prevent  postgres  from  freeing  the  system
310       resources  (e.g.,  shared  memory  and semaphores) that it holds before
311       terminating. This may cause problems for starting a fresh postgres run.
312
313       To terminate the postgres server normally, the signals SIGTERM, SIGINT,
314       or  SIGQUIT  can be used. The first will wait for all clients to termi‐
315       nate  before  quitting,  the  second  will  forcefully  disconnect  all
316       clients,  and  the third will quit immediately without proper shutdown,
317       resulting in a recovery run during  restart.  The  SIGHUP  signal  will
318       reload  the  server  configuration  files.  It is also possible to send
319       SIGHUP to an individual server process, but that is usually not  sensi‐
320       ble.
321
322       The  utility  command  pg_ctl(1) can be used to start and shut down the
323       postgres server safely and comfortably.
324
325       To cancel a running query, send the SIGINT signal to the  process  run‐
326       ning that command.
327
328       The  postgres  server uses SIGTERM to tell subordinate server processes
329       to quit normally and SIGQUIT to terminate without the  normal  cleanup.
330       These  signals  should  not be used by users. It is also unwise to send
331       SIGKILL to a server process — the main postgres process will  interpret
332       this  as  a  crash  and will force all the sibling processes to quit as
333       part of its standard crash-recovery procedure.
334

BUGS

336       The -- options will not work on FreeBSD or OpenBSD.   Use  -c  instead.
337       This  is  a  bug in the affected operating systems; a future release of
338       PostgreSQL will provide a workaround if this is not fixed.
339

USAGE

341       To start a single-user mode server, use a command like
342
343       postgres --single -D /usr/local/pgsql/data other-options my_database
344
345       Provide the correct path to the database directory  with  -D,  or  make
346       sure  that  the  environment  variable PGDATA is set.  Also specify the
347       name of the particular database you want to work in.
348
349       Normally, the single-user mode server treats  newline  as  the  command
350       entry  terminator;  there is no intelligence about semicolons, as there
351       is in psql. To continue a command across multiple lines, you must  type
352       backslash just before each newline except the last one.
353
354       But if you use the -j command line switch, then newline does not termi‐
355       nate command entry. In this case, the server  will  read  the  standard
356       input  until  the end-of-file (EOF) marker, then process the input as a
357       single command string. Backslash-newline is not  treated  specially  in
358       this case.
359
360       To quit the session, type EOF (Control+D, usually).  If you've used -j,
361       two consecutive EOFs are needed to exit.
362
363       Note that the single-user mode server does  not  provide  sophisticated
364       line-editing features (no command history, for example).
365

EXAMPLES

367       To start postgres in the background using default values, type:
368
369       $ nohup postgres >logfile 2>&1 </dev/null &
370
371
372       To start postgres with a specific port:
373
374       $ postgres -p 1234
375
376       This  command  will  start  up  postgres communicating through the port
377       1234. In order to connect to this server using psql, you would need  to
378       run it as
379
380       $ psql -p 1234
381
382       or set the environment variable PGPORT:
383
384       $ export PGPORT=1234
385       $ psql
386
387
388       Named run-time parameters can be set in either of these styles:
389
390       $ postgres -c work_mem=1234
391       $ postgres --work-mem=1234
392
393       Either  form  overrides  whatever  setting  might exist for work_mem in
394       postgresql.conf. Notice that underscores  in  parameter  names  can  be
395       written  as  either  underscore or dash on the command line. Except for
396       short-term experiments, it's probably better practice to edit the  set‐
397       ting  in postgresql.conf than to rely on a command-line switch to set a
398       parameter.
399

SEE ALSO

401       initdb(1), pg_ctl(1)
402
403
404
405Application                       2008-06-08                       POSTGRES(1)
Impressum