1POSTGRES(1)              PostgreSQL 15.4 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 20.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(1).
34       Sometimes it is used for debugging or disaster recovery; note that
35       running a single-user server is not truly suitable for debugging the
36       server, since no realistic interprocess communication and locking will
37       happen. When invoked in single-user mode from the shell, the user can
38       enter queries and the results will be printed to the screen, but in a
39       form that is more useful for developers than end users. In the
40       single-user mode, the session user will be set to the user with ID 1,
41       and implicit superuser powers are granted to this user. This user does
42       not actually have to exist, so the single-user mode can be used to
43       manually recover from certain kinds of accidental damage to the system
44       catalogs.
45

OPTIONS

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

ENVIRONMENT

279       PGCLIENTENCODING
280           Default character encoding used by clients. (The clients can
281           override this individually.) This value can also be set in the
282           configuration file.
283
284       PGDATA
285           Default data directory location
286
287       PGDATESTYLE
288           Default value of the DateStyle run-time parameter. (The use of this
289           environment variable is deprecated.)
290
291       PGPORT
292           Default port number (preferably set in the configuration file)
293

DIAGNOSTICS

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

NOTES

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

BUGS

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

SINGLE-USER MODE

364       To start a single-user mode server, use a command like
365
366           postgres --single -D /usr/local/pgsql/data other-options my_database
367
368       Provide the correct path to the database directory with -D, or make
369       sure that the environment variable PGDATA is set. Also specify the name
370       of the particular database you want to work in.
371
372       Normally, the single-user mode server treats newline as the command
373       entry terminator; there is no intelligence about semicolons, as there
374       is in psql. To continue a command across multiple lines, you must type
375       backslash just before each newline except the last one. The backslash
376       and adjacent newline are both dropped from the input command. Note that
377       this will happen even when within a string literal or comment.
378
379       But if you use the -j command line switch, a single newline does not
380       terminate command entry; instead, the sequence
381       semicolon-newline-newline does. That is, type a semicolon immediately
382       followed by a completely empty line. Backslash-newline is not treated
383       specially in this mode. Again, there is no intelligence about such a
384       sequence appearing within a string literal or comment.
385
386       In either input mode, if you type a semicolon that is not just before
387       or part of a command entry terminator, it is considered a command
388       separator. When you do type a command entry terminator, the multiple
389       statements you've entered will be executed as a single transaction.
390
391       To quit the session, type EOF (Control+D, usually). If you've entered
392       any text since the last command entry terminator, then EOF will be
393       taken as a command entry terminator, and another EOF will be needed to
394       exit.
395
396       Note that the single-user mode server does not provide sophisticated
397       line-editing features (no command history, for example). Single-user
398       mode also does not do any background processing, such as automatic
399       checkpoints or replication.
400

EXAMPLES

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

SEE ALSO

433       initdb(1), pg_ctl(1)
434
435
436
437PostgreSQL 15.4                      2023                          POSTGRES(1)
Impressum