]> begriffs open source - ai-pg/blob - full-docs/txt/app-postgres.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / app-postgres.txt
1
2 postgres
3
4    postgres — PostgreSQL database server
5
6 Synopsis
7
8    postgres [option...]
9
10 Description
11
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. Other
26    possible file layouts are discussed in Section 19.2.
27
28    By default postgres starts in the foreground and prints log messages to
29    the standard error stream. In practical applications postgres should be
30    started as a background process, perhaps at boot time.
31
32    The postgres command can also be called in single-user mode. The
33    primary use for this mode is during bootstrapping by initdb. Sometimes
34    it is used for debugging or disaster recovery; note that running a
35    single-user server is not truly suitable for debugging the server,
36    since no realistic interprocess communication and locking will happen.
37    When invoked in single-user mode from the shell, the user can enter
38    queries and the results will be printed to the screen, but in a form
39    that is more useful for developers than end users. In the single-user
40    mode, the session user will be set to the user with ID 1, and implicit
41    superuser powers are granted to this user. This user does not actually
42    have to exist, so the single-user mode can be used to manually recover
43    from certain kinds of accidental damage to the system catalogs.
44
45 Options
46
47    postgres accepts the following command-line arguments. For a detailed
48    discussion of the options consult Chapter 19. You can save typing most
49    of these options by setting up a configuration file. Some (safe)
50    options can also be set from the connecting client in an
51    application-dependent way to apply only for that session. For example,
52    if the environment variable PGOPTIONS is set, then libpq-based clients
53    will pass that string to the server, which will interpret it as
54    postgres command-line options.
55
56 General Purpose
57
58    -B nbuffers
59           Sets the number of shared buffers for use by the server
60           processes. The default value of this parameter is chosen
61           automatically by initdb. Specifying this option is equivalent to
62           setting the shared_buffers configuration parameter.
63
64    -c name=value
65           Sets a named run-time parameter. The configuration parameters
66           supported by PostgreSQL are described in Chapter 19. Most of the
67           other command line options are in fact short forms of such a
68           parameter assignment. -c can appear multiple times to set
69           multiple parameters.
70
71    -C name
72           Prints the value of the named run-time parameter, and exits.
73           (See the -c option above for details.) This returns values from
74           postgresql.conf, modified by any parameters supplied in this
75           invocation. It does not reflect parameters supplied when the
76           cluster was started.
77
78           This can be used on a running server for most parameters.
79           However, the server must be shut down for some runtime-computed
80           parameters (e.g., shared_memory_size,
81           shared_memory_size_in_huge_pages, and wal_segment_size).
82
83           This option is meant for other programs that interact with a
84           server instance, such as pg_ctl, to query configuration
85           parameter values. User-facing applications should instead use
86           SHOW or the pg_settings view.
87
88    -d debug-level
89           Sets the debug level. The higher this value is set, the more
90           debugging output is written to the server log. Values are from 1
91           to 5. It is also possible to pass -d 0 for a specific session,
92           which will prevent the server log level of the parent postgres
93           process from being propagated to this session.
94
95    -D datadir
96           Specifies the file system location of the database configuration
97           files. See Section 19.2 for details.
98
99    -e
100           Sets the default date style to “European”, that is DMY ordering
101           of input date fields. This also causes the day to be printed
102           before the month in certain date output formats. See Section 8.5
103           for more information.
104
105    -F
106           Disables fsync calls for improved performance, at the risk of
107           data corruption in the event of a system crash. Specifying this
108           option is equivalent to disabling the fsync configuration
109           parameter. Read the detailed documentation before using this!
110
111    -h hostname
112           Specifies the IP host name or address on which postgres is to
113           listen for TCP/IP connections from client applications. The
114           value can also be a comma-separated list of addresses, or * to
115           specify listening on all available interfaces. An empty value
116           specifies not listening on any IP addresses, in which case only
117           Unix-domain sockets can be used to connect to the server.
118           Defaults to listening only on localhost. Specifying this option
119           is equivalent to setting the listen_addresses configuration
120           parameter.
121
122    -i
123           Allows remote clients to connect via TCP/IP (Internet domain)
124           connections. Without this option, only local connections are
125           accepted. This option is equivalent to setting listen_addresses
126           to * in postgresql.conf or via -h.
127
128           This option is deprecated since it does not allow access to the
129           full functionality of listen_addresses. It's usually better to
130           set listen_addresses directly.
131
132    -k directory
133           Specifies the directory of the Unix-domain socket on which
134           postgres is to listen for connections from client applications.
135           The value can also be a comma-separated list of directories. An
136           empty value specifies not listening on any Unix-domain sockets,
137           in which case only TCP/IP sockets can be used to connect to the
138           server. The default value is normally /tmp, but that can be
139           changed at build time. Specifying this option is equivalent to
140           setting the unix_socket_directories configuration parameter.
141
142    -l
143           Enables secure connections using SSL. PostgreSQL must have been
144           compiled with support for SSL for this option to be available.
145           For more information on using SSL, refer to Section 18.9.
146
147    -N max-connections
148           Sets the maximum number of client connections that this server
149           will accept. The default value of this parameter is chosen
150           automatically by initdb. Specifying this option is equivalent to
151           setting the max_connections configuration parameter.
152
153    -p port
154           Specifies the TCP/IP port or local Unix domain socket file
155           extension on which postgres is to listen for connections from
156           client applications. Defaults to the value of the PGPORT
157           environment variable, or if PGPORT is not set, then defaults to
158           the value established during compilation (normally 5432). If you
159           specify a port other than the default port, then all client
160           applications must specify the same port using either
161           command-line options or PGPORT.
162
163    -s
164           Print time information and other statistics at the end of each
165           command. This is useful for benchmarking or for use in tuning
166           the number of buffers.
167
168    -S work-mem
169           Specifies the base amount of memory to be used by sorts and hash
170           tables before resorting to temporary disk files. See the
171           description of the work_mem configuration parameter in
172           Section 19.4.1.
173
174    -V
175           --version
176           Print the postgres version and exit.
177
178    --name=value
179           Sets a named run-time parameter; a shorter form of -c.
180
181    --describe-config
182           This option dumps out the server's internal configuration
183           variables, descriptions, and defaults in tab-delimited COPY
184           format. It is designed primarily for use by administration
185           tools.
186
187    -?
188           --help
189           Show help about postgres command line arguments, and exit.
190
191 Semi-Internal Options
192
193    The options described here are used mainly for debugging purposes, and
194    in some cases to assist with recovery of severely damaged databases.
195    There should be no reason to use them in a production database setup.
196    They are listed here only for use by PostgreSQL system developers.
197    Furthermore, these options might change or be removed in a future
198    release without notice.
199
200    -f { s | i | o | b | t | n | m | h }
201           Forbids the use of particular scan and join methods: s and i
202           disable sequential and index scans respectively, o, b and t
203           disable index-only scans, bitmap index scans, and TID scans
204           respectively, while n, m, and h disable nested-loop, merge and
205           hash joins respectively.
206
207           Neither sequential scans nor nested-loop joins can be disabled
208           completely; the -fs and -fn options simply discourage the
209           optimizer from using those plan types if it has any other
210           alternative.
211
212    -O
213           Allows the structure of system tables to be modified. This is
214           used by initdb.
215
216    -P
217           Ignore system indexes when reading system tables, but still
218           update the indexes when modifying the tables. This is useful
219           when recovering from damaged system indexes.
220
221    -t pa[rser] | pl[anner] | e[xecutor]
222           Print timing statistics for each query relating to each of the
223           major system modules. This option cannot be used together with
224           the -s option.
225
226    -T
227           This option is for debugging problems that cause a server
228           process to die abnormally. The ordinary strategy in this
229           situation is to notify all other server processes that they must
230           terminate, by sending them SIGQUIT signals. With this option,
231           SIGABRT will be sent instead, resulting in production of core
232           dump files.
233
234    -v protocol
235           Specifies the version number of the frontend/backend protocol to
236           be used for a particular session. This option is for internal
237           use only.
238
239    -W seconds
240           A delay of this many seconds occurs when a new server process is
241           started, after it conducts the authentication procedure. This is
242           intended to give an opportunity to attach to the server process
243           with a debugger.
244
245 Options for Single-User Mode
246
247    The following options only apply to the single-user mode (see
248    Single-User Mode below).
249
250    --single
251           Selects the single-user mode. This must be the first argument on
252           the command line.
253
254    database
255           Specifies the name of the database to be accessed. This must be
256           the last argument on the command line. If it is omitted it
257           defaults to the user name.
258
259    -E
260           Echo all commands to standard output before executing them.
261
262    -j
263           Use semicolon followed by two newlines, rather than just
264           newline, as the command entry terminator.
265
266    -r filename
267           Send all server log output to filename. This option is only
268           honored when supplied as a command-line option.
269
270 Environment
271
272    PGCLIENTENCODING
273           Default character encoding used by clients. (The clients can
274           override this individually.) This value can also be set in the
275           configuration file.
276
277    PGDATA
278           Default data directory location
279
280    PGDATESTYLE
281           Default value of the DateStyle run-time parameter. (The use of
282           this environment variable is deprecated.)
283
284    PGPORT
285           Default port number (preferably set in the configuration file)
286
287 Diagnostics
288
289    A failure message mentioning semget or shmget probably indicates you
290    need to configure your kernel to provide adequate shared memory and
291    semaphores. For more discussion see Section 18.4. You might be able to
292    postpone reconfiguring your kernel by decreasing shared_buffers to
293    reduce the shared memory consumption of PostgreSQL, and/or by reducing
294    max_connections to reduce the semaphore consumption.
295
296    A failure message suggesting that another server is already running
297    should be checked carefully, for example by using the command
298 $ ps ax | grep postgres
299
300    or
301 $ ps -ef | grep postgres
302
303    depending on your system. If you are certain that no conflicting server
304    is running, you can remove the lock file mentioned in the message and
305    try again.
306
307    A failure message indicating inability to bind to a port might indicate
308    that that port is already in use by some non-PostgreSQL process. You
309    might also get this error if you terminate postgres and immediately
310    restart it using the same port; in this case, you must simply wait a
311    few seconds until the operating system closes the port before trying
312    again. Finally, you might get this error if you specify a port number
313    that your operating system considers to be reserved. For example, many
314    versions of Unix consider port numbers under 1024 to be “trusted” and
315    only permit the Unix superuser to access them.
316
317 Notes
318
319    The utility command pg_ctl can be used to start and shut down the
320    postgres server safely and comfortably.
321
322    If at all possible, do not use SIGKILL to kill the main postgres
323    server. Doing so will prevent postgres from freeing the system
324    resources (e.g., shared memory and semaphores) that it holds before
325    terminating. This might cause problems for starting a fresh postgres
326    run.
327
328    To terminate the postgres server normally, the signals SIGTERM, SIGINT,
329    or SIGQUIT can be used. The first will wait for all clients to
330    terminate before quitting, the second will forcefully disconnect all
331    clients, and the third will quit immediately without proper shutdown,
332    resulting in a recovery run during restart.
333
334    The SIGHUP signal will reload the server configuration files. It is
335    also possible to send SIGHUP to an individual server process, but that
336    is usually not sensible.
337
338    To cancel a running query, send the SIGINT signal to the process
339    running that command. To terminate a backend process cleanly, send
340    SIGTERM to that process. See also pg_cancel_backend and
341    pg_terminate_backend in Section 9.28.2 for the SQL-callable equivalents
342    of these two actions.
343
344    The postgres server uses SIGQUIT to tell subordinate server processes
345    to terminate without normal cleanup. This signal should not be used by
346    users. It is also unwise to send SIGKILL to a server process — the main
347    postgres process will interpret this as a crash and will force all the
348    sibling processes to quit as part of its standard crash-recovery
349    procedure.
350
351 Bugs
352
353    The -- options will not work on FreeBSD or OpenBSD. Use -c instead.
354    This is a bug in the affected operating systems; a future release of
355    PostgreSQL will provide a workaround if this is not fixed.
356
357 Single-User Mode
358
359    To start a single-user mode server, use a command like
360 postgres --single -D /usr/local/pgsql/data other-options my_database
361
362    Provide the correct path to the database directory with -D, or make
363    sure that the environment variable PGDATA is set. Also specify the name
364    of the particular database you want to work in.
365
366    Normally, the single-user mode server treats newline as the command
367    entry terminator; there is no intelligence about semicolons, as there
368    is in psql. To continue a command across multiple lines, you must type
369    backslash just before each newline except the last one. The backslash
370    and adjacent newline are both dropped from the input command. Note that
371    this will happen even when within a string literal or comment.
372
373    But if you use the -j command line switch, a single newline does not
374    terminate command entry; instead, the sequence
375    semicolon-newline-newline does. That is, type a semicolon immediately
376    followed by a completely empty line. Backslash-newline is not treated
377    specially in this mode. Again, there is no intelligence about such a
378    sequence appearing within a string literal or comment.
379
380    In either input mode, if you type a semicolon that is not just before
381    or part of a command entry terminator, it is considered a command
382    separator. When you do type a command entry terminator, the multiple
383    statements you've entered will be executed as a single transaction.
384
385    To quit the session, type EOF (Control+D, usually). If you've entered
386    any text since the last command entry terminator, then EOF will be
387    taken as a command entry terminator, and another EOF will be needed to
388    exit.
389
390    Note that the single-user mode server does not provide sophisticated
391    line-editing features (no command history, for example). Single-user
392    mode also does not do any background processing, such as automatic
393    checkpoints or replication.
394
395 Examples
396
397    To start postgres in the background using default values, type:
398 $ nohup postgres >logfile 2>&1 </dev/null &
399
400    To start postgres with a specific port, e.g., 1234:
401 $ postgres -p 1234
402
403    To connect to this server using psql, specify this port with the -p
404    option:
405 $ psql -p 1234
406
407    or set the environment variable PGPORT:
408 $ export PGPORT=1234
409 $ psql
410
411    Named run-time parameters can be set in either of these styles:
412 $ postgres -c work_mem=1234
413 $ postgres --work-mem=1234
414
415    Either form overrides whatever setting might exist for work_mem in
416    postgresql.conf. Notice that underscores in parameter names can be
417    written as either underscore or dash on the command line. Except for
418    short-term experiments, it's probably better practice to edit the
419    setting in postgresql.conf than to rely on a command-line switch to set
420    a parameter.
421
422 See Also
423
424    initdb, pg_ctl