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

NAME

6       postgres - PostgreSQL database server
7

SYNOPSIS

9       postgres [option...]
10

DESCRIPTION

12       postgres is the PostgreSQL database server. In order for a client
13       application to access a database it connects (over a network or
14       locally) to a running postgres instance. The postgres instance then
15       starts a separate server process to handle the connection.
16
17       One postgres instance always manages the data of exactly one database
18       cluster. A database cluster is a collection of databases that is stored
19       at a common file system location (the “data area”). More than one
20       postgres instance can run on a system at one time, so long as they use
21       different data areas and different communication ports (see below).
22       When postgres starts it needs to know the location of the data area.
23       The location must be specified by the -D option or the PGDATA
24       environment variable; there is no default. Typically, -D or PGDATA
25       points directly to the data area directory created by initdb(1). Other
26       possible file layouts are discussed in Section 18.2, “File Locations”,
27       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
34       primary use for this mode is during bootstrapping by initdb(1).
35       Sometimes it is used for debugging or disaster recovery; note that
36       running a single-user server is not truly suitable for debugging the
37       server, since no realistic interprocess communication and locking will
38       happen. When invoked in single-user mode from the shell, the user can
39       enter queries and the results will be printed to the screen, but in a
40       form that is more useful for developers than end users. In the
41       single-user mode, the session user will be set to the user with ID 1,
42       and implicit superuser powers are granted to this user. This user does
43       not actually have to exist, so the single-user mode can be used to
44       manually recover from certain kinds of accidental damage to the system
45       catalogs.
46

OPTIONS

48       postgres accepts the following command-line arguments. For a detailed
49       discussion of the options consult Chapter 18, Server Configuration, in
50       the documentation. You can save typing most of these options by setting
51       up a configuration file. Some (safe) options can also be set from the
52       connecting client in an application-dependent way to apply only for
53       that session. For example, if the environment variable PGOPTIONS is
54       set, then libpq-based clients will pass that string to the server,
55       which will interpret it as postgres command-line options.
56
57   General Purpose
58       -A 0|1
59           Enables run-time assertion checks, which is a debugging aid to
60           detect programming mistakes. This option is only available if
61           assertions were enabled when PostgreSQL was compiled. If so, the
62           default is on.
63
64       -B nbuffers
65           Sets the number of shared buffers for use by the server processes.
66           The default value of this parameter is chosen automatically by
67           initdb. Specifying this option is equivalent to setting the
68           shared_buffers configuration parameter.
69
70       -c name=value
71           Sets a named run-time parameter. The configuration parameters
72           supported by PostgreSQL are described in Chapter 18, Server
73           Configuration, in the documentation. Most of the other command line
74           options are in fact short forms of such a parameter assignment.  -c
75           can appear multiple times to set multiple parameters.
76
77       -C name
78           Prints the value of the named run-time parameter, and exits. (See
79           the -c option above for details.) This can be used on a running
80           server, and returns values from postgresql.conf, modified by any
81           parameters supplied in this invocation. It does not reflect
82           parameters supplied when the cluster was started.
83
84           This option is meant for other programs that interact with a server
85           instance, such as pg_ctl(1), to query configuration parameter
86           values. User-facing applications should instead use SHOW(7) or the
87           pg_settings view.
88
89       -d debug-level
90           Sets the debug level. The higher this value is set, the more
91           debugging output is written to the server log. Values are from 1 to
92           5. It is also possible to pass -d 0 for a specific session, which
93           will prevent the server log level of the parent postgres process
94           from being propagated to this session.
95
96       -D datadir
97           Specifies the file system location of the data directory or
98           configuration file(s). See Section 18.2, “File Locations”, in the
99           documentation for details.
100
101       -e
102           Sets the default date style to “European”, that is DMY ordering of
103           input date fields. This also causes the day to be printed before
104           the month in certain date output formats. See Section 8.5,
105           “Date/Time Types”, in the documentation for more information.
106
107       -F
108           Disables fsync calls for improved performance, at the risk of data
109           corruption in the event of a system crash. Specifying this option
110           is equivalent to disabling the fsync configuration parameter. Read
111           the detailed documentation before using this!
112
113       -h hostname
114           Specifies the IP host name or address on which postgres is to
115           listen for TCP/IP connections from client applications. The value
116           can also be a comma-separated list of addresses, or * to specify
117           listening on all available interfaces. An empty value specifies not
118           listening on any IP addresses, in which case only Unix-domain
119           sockets can be used to connect to the server. Defaults to listening
120           only on localhost. Specifying this option is equivalent to setting
121           the listen_addresses configuration parameter.
122
123       -i
124           Allows remote clients to connect via TCP/IP (Internet domain)
125           connections. Without this option, only local connections are
126           accepted. This option is equivalent to setting listen_addresses to
127           * in postgresql.conf or via -h.
128
129           This option is deprecated since it does not allow access to the
130           full functionality of listen_addresses. It's usually better to set
131           listen_addresses directly.
132
133       -k directory
134           Specifies the directory of the Unix-domain socket on which postgres
135           is to listen for connections from client applications. The value
136           can also be a comma-separated list of directories. An empty value
137           specifies not listening on any Unix-domain sockets, in which case
138           only TCP/IP sockets can be used to connect to the server. The
139           default value is normally /tmp, but that can be changed at build
140           time. Specifying this option is equivalent to setting the
141           unix_socket_directories configuration parameter.
142
143       -l
144           Enables secure connections using SSL.  PostgreSQL must have been
145           compiled with support for SSL for this option to be available. For
146           more information on using SSL, refer to Section 17.9, “Secure
147           TCP/IP Connections with SSL”, in the documentation.
148
149       -N max-connections
150           Sets the maximum number of client connections that this server will
151           accept. The default value of this parameter is chosen automatically
152           by initdb. Specifying this option is equivalent to setting the
153           max_connections configuration parameter.
154
155       -o extra-options
156           The command-line-style options specified in extra-options are
157           passed to all server processes started by this postgres process. If
158           the option string contains any spaces, the entire string must be
159           quoted.
160
161           The use of this option is obsolete; all command-line options for
162           server processes can be specified directly on the postgres command
163           line.
164
165       -p port
166           Specifies the TCP/IP port or local Unix domain socket file
167           extension on which postgres is to listen for connections from
168           client applications. Defaults to the value of the PGPORT
169           environment variable, or if PGPORT is not set, then defaults to the
170           value established during compilation (normally 5432). If you
171           specify a port other than the default port, then all client
172           applications must specify the same port using either command-line
173           options or PGPORT.
174
175       -s
176           Print time information and other statistics at the end of each
177           command. This is useful for benchmarking or for use in tuning the
178           number of buffers.
179
180       -S work-mem
181           Specifies the amount of memory to be used by internal sorts and
182           hashes before resorting to temporary disk files. See the
183           description of the work_mem configuration parameter in Section
184           18.4.1, “Memory”, in the documentation.
185
186       -V, --version
187           Print the postgres version and exit.
188
189       --name=value
190           Sets a named run-time parameter; a shorter form of -c.
191
192       --describe-config
193           This option dumps out the server's internal configuration
194           variables, descriptions, and defaults in tab-delimited COPY format.
195           It is designed primarily for use by administration tools.
196
197       -?, --help
198           Show help about postgres command line arguments, and exit.
199
200   Semi-internal Options
201       The options described here are used mainly for debugging purposes, and
202       in some cases to assist with recovery of severely damaged databases.
203       There should be no reason to use them in a production database setup.
204       They are listed here only for use by PostgreSQL system developers.
205       Furthermore, these options might change or be removed in a future
206       release without notice.
207
208       -f { s | i | o | b | t | n | m | h }
209           Forbids the use of particular scan and join methods: s and i
210           disable sequential and index scans respectively, o, b and t disable
211           index-only scans, bitmap index scans, and TID scans respectively,
212           while n, m, and h disable nested-loop, merge and hash joins
213           respectively.
214
215           Neither sequential scans nor nested-loop joins can be disabled
216           completely; the -fs and -fn options simply discourage the optimizer
217           from using those plan types if it has any other alternative.
218
219       -n
220           This option is for debugging problems that cause a server process
221           to die abnormally. The ordinary strategy in this situation is to
222           notify all other server processes that they must terminate and then
223           reinitialize the shared memory and semaphores. This is because an
224           errant server process could have corrupted some shared state before
225           terminating. This option specifies that postgres will not
226           reinitialize shared data structures. A knowledgeable system
227           programmer can then use a debugger to examine shared memory and
228           semaphore state.
229
230       -O
231           Allows the structure of system tables to be modified. This is used
232           by initdb.
233
234       -P
235           Ignore system indexes when reading system tables, but still update
236           the indexes when modifying the tables. This is useful when
237           recovering from damaged system indexes.
238
239       -t pa[rser] | pl[anner] | e[xecutor]
240           Print timing statistics for each query relating to each of the
241           major system modules. This option cannot be used together with the
242           -s option.
243
244       -T
245           This option is for debugging problems that cause a server process
246           to die abnormally. The ordinary strategy in this situation is to
247           notify all other server processes that they must terminate and then
248           reinitialize the shared memory and semaphores. This is because an
249           errant server process could have corrupted some shared state before
250           terminating. This option specifies that postgres will stop all
251           other server processes by sending the signal SIGSTOP, but will not
252           cause them to terminate. This permits system programmers to collect
253           core dumps from all server processes by hand.
254
255       -v protocol
256           Specifies the version number of the frontend/backend protocol to be
257           used for a particular session. This option is for internal use
258           only.
259
260       -W seconds
261           A delay of this many seconds occurs when a new server process is
262           started, after it conducts the authentication procedure. This is
263           intended to give an opportunity to attach to the server process
264           with a debugger.
265
266   Options for Single-User Mode
267       The following options only apply to the single-user mode.
268
269       --single
270           Selects the single-user mode. This must be the first argument on
271           the command line.
272
273       database
274           Specifies the name of the database to be accessed. This must be the
275           last argument on the command line. If it is omitted it defaults to
276           the user name.
277
278       -E
279           Echo all commands.
280
281       -j
282           Disables use of newline as a statement delimiter.
283
284       -r filename
285           Send all server log output to filename. In normal multiuser mode,
286           this option is ignored, and stderr is used by all processes.
287

ENVIRONMENT

289       PGCLIENTENCODING
290           Default character encoding used by clients. (The clients can
291           override this individually.) This value can also be set in the
292           configuration file.
293
294       PGDATA
295           Default data directory location
296
297       PGDATESTYLE
298           Default value of the DateStyle run-time parameter. (The use of this
299           environment variable is deprecated.)
300
301       PGPORT
302           Default port number (preferably set in the configuration file)
303

DIAGNOSTICS

305       A failure message mentioning semget or shmget probably indicates you
306       need to configure your kernel to provide adequate shared memory and
307       semaphores. For more discussion see Section 17.4, “Managing Kernel
308       Resources”, in the documentation. You might be able to postpone
309       reconfiguring your kernel by decreasing shared_buffers to reduce the
310       shared memory consumption of PostgreSQL, and/or by reducing
311       max_connections to reduce the semaphore consumption.
312
313       A failure message suggesting that another server is already running
314       should be checked carefully, for example by using the command
315
316           $ ps ax | grep postgres
317
318       or
319
320           $ ps -ef | grep postgres
321
322       depending on your system. If you are certain that no conflicting server
323       is running, you can remove the lock file mentioned in the message and
324       try again.
325
326       A failure message indicating inability to bind to a port might indicate
327       that that port is already in use by some non-PostgreSQL process. You
328       might also get this error if you terminate postgres and immediately
329       restart it using the same port; in this case, you must simply wait a
330       few seconds until the operating system closes the port before trying
331       again. Finally, you might get this error if you specify a port number
332       that your operating system considers to be reserved. For example, many
333       versions of Unix consider port numbers under 1024 to be “trusted” and
334       only permit the Unix superuser to access them.
335

NOTES

337       The utility command pg_ctl(1) can be used to start and shut down the
338       postgres server safely and comfortably.
339
340       If at all possible, do not use SIGKILL to kill the main postgres
341       server. Doing so will prevent postgres from freeing the system
342       resources (e.g., shared memory and semaphores) that it holds before
343       terminating. This might cause problems for starting a fresh postgres
344       run.
345
346       To terminate the postgres server normally, the signals SIGTERM, SIGINT,
347       or SIGQUIT can be used. The first will wait for all clients to
348       terminate before quitting, the second will forcefully disconnect all
349       clients, and the third will quit immediately without proper shutdown,
350       resulting in a recovery run during restart.
351
352       The SIGHUP signal will reload the server configuration files. It is
353       also possible to send SIGHUP to an individual server process, but that
354       is usually not sensible.
355
356       To cancel a running query, send the SIGINT signal to the process
357       running that command.
358
359       The postgres server uses SIGTERM to tell subordinate server processes
360       to quit normally and SIGQUIT to terminate without the normal cleanup.
361       These signals should not be used by users. It is also unwise to send
362       SIGKILL to a server process — the main postgres process will interpret
363       this as a crash and will force all the sibling processes to quit as
364       part of its standard crash-recovery procedure.
365

BUGS

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

USAGE

372       To start a single-user mode server, use a command like
373
374           postgres --single -D /usr/local/pgsql/data other-options my_database
375
376       Provide the correct path to the database directory with -D, or make
377       sure that the environment variable PGDATA is set. Also specify the name
378       of the particular database you want to work in.
379
380       Normally, the single-user mode server treats newline as the command
381       entry terminator; there is no intelligence about semicolons, as there
382       is in psql. To continue a command across multiple lines, you must type
383       backslash just before each newline except the last one.
384
385       But if you use the -j command line switch, then newline does not
386       terminate command entry. In this case, the server will read the
387       standard input until the end-of-file (EOF) marker, then process the
388       input as a single command string. Backslash-newline is not treated
389       specially in this case.
390
391       To quit the session, type EOF (Control+D, usually). If you've used -j,
392       two consecutive EOFs are needed to exit.
393
394       Note that the single-user mode server does not provide sophisticated
395       line-editing features (no command history, for example). Single-User
396       mode also does not do any background processing, like automatic
397       checkpoints.
398

EXAMPLES

400       To start postgres in the background using default values, type:
401
402           $ nohup postgres >logfile 2>&1 </dev/null &
403
404       To start postgres with a specific port, e.g. 1234:
405
406           $ postgres -p 1234
407
408       To connect to this server using psql, specify this port with the -p
409       option:
410
411           $ psql -p 1234
412
413       or set the environment variable PGPORT:
414
415           $ export PGPORT=1234
416           $ psql
417
418       Named run-time parameters can be set in either of these styles:
419
420           $ postgres -c work_mem=1234
421           $ postgres --work-mem=1234
422
423       Either form overrides whatever setting might exist for work_mem in
424       postgresql.conf. Notice that underscores in parameter names can be
425       written as either underscore or dash on the command line. Except for
426       short-term experiments, it's probably better practice to edit the
427       setting in postgresql.conf than to rely on a command-line switch to set
428       a parameter.
429

SEE ALSO

431       initdb(1), pg_ctl(1)
432
433
434
435PostgreSQL 9.2.24                 2017-11-06                       POSTGRES(1)
Impressum