1POSTGRES(1)              PostgreSQL 16.1 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       -O
208           Allows the structure of system tables to be modified. This is used
209           by initdb.
210
211       -P
212           Ignore system indexes when reading system tables, but still update
213           the indexes when modifying the tables. This is useful when
214           recovering from damaged system indexes.
215
216       -t pa[rser] | pl[anner] | e[xecutor]
217           Print timing statistics for each query relating to each of the
218           major system modules. This option cannot be used together with the
219           -s option.
220
221       -T
222           This option is for debugging problems that cause a server process
223           to die abnormally. The ordinary strategy in this situation is to
224           notify all other server processes that they must terminate, by
225           sending them SIGQUIT signals. With this option, SIGABRT will be
226           sent instead, resulting in production of core dump files.
227
228       -v protocol
229           Specifies the version number of the frontend/backend protocol to be
230           used for a particular session. This option is for internal use
231           only.
232
233       -W seconds
234           A delay of this many seconds occurs when a new server process is
235           started, after it conducts the authentication procedure. This is
236           intended to give an opportunity to attach to the server process
237           with a debugger.
238
239   Options for Single-User Mode
240       The following options only apply to the single-user mode (see Single-
241       User Mode below).
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. This must be the
249           last argument on the command line. If it is omitted it defaults to
250           the user name.
251
252       -E
253           Echo all commands to standard output before executing them.
254
255       -j
256           Use semicolon followed by two newlines, rather than just newline,
257           as the command entry terminator.
258
259       -r filename
260           Send all server log output to filename. This option is only honored
261           when supplied as a command-line option.
262

ENVIRONMENT

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

DIAGNOSTICS

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

NOTES

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

BUGS

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

SINGLE-USER MODE

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

EXAMPLES

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

SEE ALSO

418       initdb(1), pg_ctl(1)
419
420
421
422PostgreSQL 16.1                      2023                          POSTGRES(1)
Impressum