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