]> begriffs open source - ai-pg/blob - full-docs/man1/postgres.1
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / man1 / postgres.1
1 '\" t
2 .\"     Title: postgres
3 .\"    Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\"      Date: 2025
6 .\"    Manual: PostgreSQL 18.0 Documentation
7 .\"    Source: PostgreSQL 18.0
8 .\"  Language: English
9 .\"
10 .TH "POSTGRES" "1" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 postgres \- PostgreSQL database server
32 .SH "SYNOPSIS"
33 .HP \w'\fBpostgres\fR\ 'u
34 \fBpostgres\fR [\fIoption\fR...]
35 .SH "DESCRIPTION"
36 .PP
37 \fBpostgres\fR
38 is the
39 PostgreSQL
40 database server\&. In order for a client application to access a database it connects (over a network or locally) to a running
41 \fBpostgres\fR
42 instance\&. The
43 \fBpostgres\fR
44 instance then starts a separate server process to handle the connection\&.
45 .PP
46 One
47 \fBpostgres\fR
48 instance always manages the data of exactly one database cluster\&. A database cluster is a collection of databases that is stored at a common file system location (the
49 \(lqdata area\(rq)\&. More than one
50 \fBpostgres\fR
51 instance can run on a system at one time, so long as they use different data areas and different communication ports (see below)\&. When
52 \fBpostgres\fR
53 starts it needs to know the location of the data area\&. The location must be specified by the
54 \fB\-D\fR
55 option or the
56 \fBPGDATA\fR
57 environment variable; there is no default\&. Typically,
58 \fB\-D\fR
59 or
60 \fBPGDATA\fR
61 points directly to the data area directory created by
62 \fBinitdb\fR(1)\&. Other possible file layouts are discussed in
63 Section\ \&19.2\&.
64 .PP
65 By default
66 \fBpostgres\fR
67 starts in the foreground and prints log messages to the standard error stream\&. In practical applications
68 \fBpostgres\fR
69 should be started as a background process, perhaps at boot time\&.
70 .PP
71 The
72 \fBpostgres\fR
73 command can also be called in single\-user mode\&. The primary use for this mode is during bootstrapping by
74 \fBinitdb\fR(1)\&. Sometimes it is used for debugging or disaster recovery; note that running a single\-user server is not truly suitable for debugging the server, since no realistic interprocess communication and locking will happen\&. When invoked in single\-user mode from the shell, the user can enter queries and the results will be printed to the screen, but in a form that is more useful for developers than end users\&. In the single\-user mode, the session user will be set to the user with ID 1, and implicit superuser powers are granted to this user\&. This user does not actually have to exist, so the single\-user mode can be used to manually recover from certain kinds of accidental damage to the system catalogs\&.
75 .SH "OPTIONS"
76 .PP
77 \fBpostgres\fR
78 accepts the following command\-line arguments\&. For a detailed discussion of the options consult
79 Chapter\ \&19\&. You can save typing most of these options by setting up a configuration file\&. Some (safe) options can also be set from the connecting client in an application\-dependent way to apply only for that session\&. For example, if the environment variable
80 \fBPGOPTIONS\fR
81 is set, then
82 libpq\-based clients will pass that string to the server, which will interpret it as
83 \fBpostgres\fR
84 command\-line options\&.
85 .SS "General Purpose"
86 .PP
87 \fB\-B \fR\fB\fInbuffers\fR\fR
88 .RS 4
89 Sets the number of shared buffers for use by the server processes\&. The default value of this parameter is chosen automatically by
90 initdb\&. Specifying this option is equivalent to setting the
91 shared_buffers
92 configuration parameter\&.
93 .RE
94 .PP
95 \fB\-c \fR\fB\fIname\fR\fR\fB=\fR\fB\fIvalue\fR\fR
96 .RS 4
97 Sets a named run\-time parameter\&. The configuration parameters supported by
98 PostgreSQL
99 are described in
100 Chapter\ \&19\&. Most of the other command line options are in fact short forms of such a parameter assignment\&.
101 \fB\-c\fR
102 can appear multiple times to set multiple parameters\&.
103 .RE
104 .PP
105 \fB\-C \fR\fB\fIname\fR\fR
106 .RS 4
107 Prints the value of the named run\-time parameter, and exits\&. (See the
108 \fB\-c\fR
109 option above for details\&.) This returns values from
110 postgresql\&.conf, modified by any parameters supplied in this invocation\&. It does not reflect parameters supplied when the cluster was started\&.
111 .sp
112 This can be used on a running server for most parameters\&. However, the server must be shut down for some runtime\-computed parameters (e\&.g\&.,
113 shared_memory_size,
114 shared_memory_size_in_huge_pages, and
115 wal_segment_size)\&.
116 .sp
117 This option is meant for other programs that interact with a server instance, such as
118 \fBpg_ctl\fR(1), to query configuration parameter values\&. User\-facing applications should instead use
119 \fBSHOW\fR
120 or the
121 pg_settings
122 view\&.
123 .RE
124 .PP
125 \fB\-d \fR\fB\fIdebug\-level\fR\fR
126 .RS 4
127 Sets the debug level\&. The higher this value is set, the more debugging output is written to the server log\&. Values are from 1 to 5\&. It is also possible to pass
128 \-d 0
129 for a specific session, which will prevent the server log level of the parent
130 \fBpostgres\fR
131 process from being propagated to this session\&.
132 .RE
133 .PP
134 \fB\-D \fR\fB\fIdatadir\fR\fR
135 .RS 4
136 Specifies the file system location of the database configuration files\&. See
137 Section\ \&19.2
138 for details\&.
139 .RE
140 .PP
141 \fB\-e\fR
142 .RS 4
143 Sets the default date style to
144 \(lqEuropean\(rq, that is
145 DMY
146 ordering of input date fields\&. This also causes the day to be printed before the month in certain date output formats\&. See
147 Section\ \&8.5
148 for more information\&.
149 .RE
150 .PP
151 \fB\-F\fR
152 .RS 4
153 Disables
154 \fBfsync\fR
155 calls for improved performance, at the risk of data corruption in the event of a system crash\&. Specifying this option is equivalent to disabling the
156 fsync
157 configuration parameter\&. Read the detailed documentation before using this!
158 .RE
159 .PP
160 \fB\-h \fR\fB\fIhostname\fR\fR
161 .RS 4
162 Specifies the IP host name or address on which
163 \fBpostgres\fR
164 is to listen for TCP/IP connections from client applications\&. The value can also be a comma\-separated list of addresses, or
165 *
166 to specify listening on all available interfaces\&. An empty value specifies not listening on any IP addresses, in which case only Unix\-domain sockets can be used to connect to the server\&. Defaults to listening only on
167 localhost\&. Specifying this option is equivalent to setting the
168 listen_addresses
169 configuration parameter\&.
170 .RE
171 .PP
172 \fB\-i\fR
173 .RS 4
174 Allows remote clients to connect via TCP/IP (Internet domain) connections\&. Without this option, only local connections are accepted\&. This option is equivalent to setting
175 \fIlisten_addresses\fR
176 to
177 *
178 in
179 postgresql\&.conf
180 or via
181 \fB\-h\fR\&.
182 .sp
183 This option is deprecated since it does not allow access to the full functionality of
184 listen_addresses\&. It\*(Aqs usually better to set
185 \fIlisten_addresses\fR
186 directly\&.
187 .RE
188 .PP
189 \fB\-k \fR\fB\fIdirectory\fR\fR
190 .RS 4
191 Specifies the directory of the Unix\-domain socket on which
192 \fBpostgres\fR
193 is to listen for connections from client applications\&. The value can also be a comma\-separated list of directories\&. An empty value specifies not listening on any Unix\-domain sockets, in which case only TCP/IP sockets can be used to connect to the server\&. The default value is normally
194 /tmp, but that can be changed at build time\&. Specifying this option is equivalent to setting the
195 unix_socket_directories
196 configuration parameter\&.
197 .RE
198 .PP
199 \fB\-l\fR
200 .RS 4
201 Enables secure connections using
202 SSL\&.
203 PostgreSQL
204 must have been compiled with support for
205 SSL
206 for this option to be available\&. For more information on using
207 SSL, refer to
208 Section\ \&18.9\&.
209 .RE
210 .PP
211 \fB\-N \fR\fB\fImax\-connections\fR\fR
212 .RS 4
213 Sets the maximum number of client connections that this server will accept\&. The default value of this parameter is chosen automatically by
214 initdb\&. Specifying this option is equivalent to setting the
215 max_connections
216 configuration parameter\&.
217 .RE
218 .PP
219 \fB\-p \fR\fB\fIport\fR\fR
220 .RS 4
221 Specifies the TCP/IP port or local Unix domain socket file extension on which
222 \fBpostgres\fR
223 is to listen for connections from client applications\&. Defaults to the value of the
224 \fBPGPORT\fR
225 environment variable, or if
226 \fBPGPORT\fR
227 is not set, then defaults to the value established during compilation (normally 5432)\&. If you specify a port other than the default port, then all client applications must specify the same port using either command\-line options or
228 \fBPGPORT\fR\&.
229 .RE
230 .PP
231 \fB\-s\fR
232 .RS 4
233 Print time information and other statistics at the end of each command\&. This is useful for benchmarking or for use in tuning the number of buffers\&.
234 .RE
235 .PP
236 \fB\-S\fR \fIwork\-mem\fR
237 .RS 4
238 Specifies the base amount of memory to be used by sorts and hash tables before resorting to temporary disk files\&. See the description of the
239 \fIwork_mem\fR
240 configuration parameter in
241 Section\ \&19.4.1\&.
242 .RE
243 .PP
244 \fB\-V\fR
245 .br
246 \fB\-\-version\fR
247 .RS 4
248 Print the
249 postgres
250 version and exit\&.
251 .RE
252 .PP
253 \fB\-\-\fR\fB\fIname\fR\fR\fB=\fR\fB\fIvalue\fR\fR
254 .RS 4
255 Sets a named run\-time parameter; a shorter form of
256 \fB\-c\fR\&.
257 .RE
258 .PP
259 \fB\-\-describe\-config\fR
260 .RS 4
261 This option dumps out the server\*(Aqs internal configuration variables, descriptions, and defaults in tab\-delimited
262 \fBCOPY\fR
263 format\&. It is designed primarily for use by administration tools\&.
264 .RE
265 .PP
266 \fB\-?\fR
267 .br
268 \fB\-\-help\fR
269 .RS 4
270 Show help about
271 postgres
272 command line arguments, and exit\&.
273 .RE
274 .SS "Semi\-Internal Options"
275 .PP
276 The options described here are used mainly for debugging purposes, and in some cases to assist with recovery of severely damaged databases\&. There should be no reason to use them in a production database setup\&. They are listed here only for use by
277 PostgreSQL
278 system developers\&. Furthermore, these options might change or be removed in a future release without notice\&.
279 .PP
280 \fB\-f\fR { s | i | o | b | t | n | m | h }
281 .RS 4
282 Forbids the use of particular scan and join methods:
283 s
284 and
285 i
286 disable sequential and index scans respectively,
287 o,
288 b
289 and
290 t
291 disable index\-only scans, bitmap index scans, and TID scans respectively, while
292 n,
293 m, and
294 h
295 disable nested\-loop, merge and hash joins respectively\&.
296 .sp
297 Neither sequential scans nor nested\-loop joins can be disabled completely; the
298 \-fs
299 and
300 \-fn
301 options simply discourage the optimizer from using those plan types if it has any other alternative\&.
302 .RE
303 .PP
304 \fB\-O\fR
305 .RS 4
306 Allows the structure of system tables to be modified\&. This is used by
307 \fBinitdb\fR\&.
308 .RE
309 .PP
310 \fB\-P\fR
311 .RS 4
312 Ignore system indexes when reading system tables, but still update the indexes when modifying the tables\&. This is useful when recovering from damaged system indexes\&.
313 .RE
314 .PP
315 \fB\-t\fR pa[rser] | pl[anner] | e[xecutor]
316 .RS 4
317 Print timing statistics for each query relating to each of the major system modules\&. This option cannot be used together with the
318 \fB\-s\fR
319 option\&.
320 .RE
321 .PP
322 \fB\-T\fR
323 .RS 4
324 This option is for debugging problems that cause a server process to die abnormally\&. The ordinary strategy in this situation is to notify all other server processes that they must terminate, by sending them
325 SIGQUIT
326 signals\&. With this option,
327 SIGABRT
328 will be sent instead, resulting in production of core dump files\&.
329 .RE
330 .PP
331 \fB\-v\fR \fIprotocol\fR
332 .RS 4
333 Specifies the version number of the frontend/backend protocol to be used for a particular session\&. This option is for internal use only\&.
334 .RE
335 .PP
336 \fB\-W\fR \fIseconds\fR
337 .RS 4
338 A delay of this many seconds occurs when a new server process is started, after it conducts the authentication procedure\&. This is intended to give an opportunity to attach to the server process with a debugger\&.
339 .RE
340 .SS "Options for Single\-User Mode"
341 .PP
342 The following options only apply to the single\-user mode (see
343 Single-User Mode
344 below)\&.
345 .PP
346 \fB\-\-single\fR
347 .RS 4
348 Selects the single\-user mode\&. This must be the first argument on the command line\&.
349 .RE
350 .PP
351 \fIdatabase\fR
352 .RS 4
353 Specifies the name of the database to be accessed\&. This must be the last argument on the command line\&. If it is omitted it defaults to the user name\&.
354 .RE
355 .PP
356 \fB\-E\fR
357 .RS 4
358 Echo all commands to standard output before executing them\&.
359 .RE
360 .PP
361 \fB\-j\fR
362 .RS 4
363 Use semicolon followed by two newlines, rather than just newline, as the command entry terminator\&.
364 .RE
365 .PP
366 \fB\-r\fR \fIfilename\fR
367 .RS 4
368 Send all server log output to
369 \fIfilename\fR\&. This option is only honored when supplied as a command\-line option\&.
370 .RE
371 .SH "ENVIRONMENT"
372 .PP
373 \fBPGCLIENTENCODING\fR
374 .RS 4
375 Default character encoding used by clients\&. (The clients can override this individually\&.) This value can also be set in the configuration file\&.
376 .RE
377 .PP
378 \fBPGDATA\fR
379 .RS 4
380 Default data directory location
381 .RE
382 .PP
383 \fBPGDATESTYLE\fR
384 .RS 4
385 Default value of the
386 DateStyle
387 run\-time parameter\&. (The use of this environment variable is deprecated\&.)
388 .RE
389 .PP
390 \fBPGPORT\fR
391 .RS 4
392 Default port number (preferably set in the configuration file)
393 .RE
394 .SH "DIAGNOSTICS"
395 .PP
396 A failure message mentioning
397 semget
398 or
399 shmget
400 probably indicates you need to configure your kernel to provide adequate shared memory and semaphores\&. For more discussion see
401 Section\ \&18.4\&. You might be able to postpone reconfiguring your kernel by decreasing
402 shared_buffers
403 to reduce the shared memory consumption of
404 PostgreSQL, and/or by reducing
405 max_connections
406 to reduce the semaphore consumption\&.
407 .PP
408 A failure message suggesting that another server is already running should be checked carefully, for example by using the command
409 .sp
410 .if n \{\
411 .RS 4
412 .\}
413 .nf
414 $ \fBps ax | grep postgres\fR
415 .fi
416 .if n \{\
417 .RE
418 .\}
419 .sp
420 or
421 .sp
422 .if n \{\
423 .RS 4
424 .\}
425 .nf
426 $ \fBps \-ef | grep postgres\fR
427 .fi
428 .if n \{\
429 .RE
430 .\}
431 .sp
432 depending on your system\&. If you are certain that no conflicting server is running, you can remove the lock file mentioned in the message and try again\&.
433 .PP
434 A failure message indicating inability to bind to a port might indicate that that port is already in use by some non\-PostgreSQL
435 process\&. You might also get this error if you terminate
436 \fBpostgres\fR
437 and immediately restart it using the same port; in this case, you must simply wait a few seconds until the operating system closes the port before trying again\&. Finally, you might get this error if you specify a port number that your operating system considers to be reserved\&. For example, many versions of Unix consider port numbers under 1024 to be
438 \(lqtrusted\(rq
439 and only permit the Unix superuser to access them\&.
440 .SH "NOTES"
441 .PP
442 The utility command
443 \fBpg_ctl\fR(1)
444 can be used to start and shut down the
445 \fBpostgres\fR
446 server safely and comfortably\&.
447 .PP
448 If at all possible,
449 \fIdo not\fR
450 use
451 SIGKILL
452 to kill the main
453 \fBpostgres\fR
454 server\&. Doing so will prevent
455 \fBpostgres\fR
456 from freeing the system resources (e\&.g\&., shared memory and semaphores) that it holds before terminating\&. This might cause problems for starting a fresh
457 \fBpostgres\fR
458 run\&.
459 .PP
460 To terminate the
461 \fBpostgres\fR
462 server normally, the signals
463 SIGTERM,
464 SIGINT, or
465 SIGQUIT
466 can be used\&. The first will wait for all clients to terminate before quitting, the second will forcefully disconnect all clients, and the third will quit immediately without proper shutdown, resulting in a recovery run during restart\&.
467 .PP
468 The
469 SIGHUP
470 signal will reload the server configuration files\&. It is also possible to send
471 SIGHUP
472 to an individual server process, but that is usually not sensible\&.
473 .PP
474 To cancel a running query, send the
475 SIGINT
476 signal to the process running that command\&. To terminate a backend process cleanly, send
477 SIGTERM
478 to that process\&. See also
479 \fBpg_cancel_backend\fR
480 and
481 \fBpg_terminate_backend\fR
482 in
483 Section\ \&9.28.2
484 for the SQL\-callable equivalents of these two actions\&.
485 .PP
486 The
487 \fBpostgres\fR
488 server uses
489 SIGQUIT
490 to tell subordinate server processes to terminate without normal cleanup\&. This signal
491 \fIshould not\fR
492 be used by users\&. It is also unwise to send
493 SIGKILL
494 to a server process \(em the main
495 \fBpostgres\fR
496 process will interpret this as a crash and will force all the sibling processes to quit as part of its standard crash\-recovery procedure\&.
497 .SH "BUGS"
498 .PP
499 The
500 \fB\-\-\fR
501 options will not work on
502 FreeBSD
503 or
504 OpenBSD\&. Use
505 \fB\-c\fR
506 instead\&. This is a bug in the affected operating systems; a future release of
507 PostgreSQL
508 will provide a workaround if this is not fixed\&.
509 .SH "SINGLE\-USER MODE"
510 .PP
511 To start a single\-user mode server, use a command like
512 .sp
513 .if n \{\
514 .RS 4
515 .\}
516 .nf
517 \fBpostgres \-\-single \-D /usr/local/pgsql/data \fR\fB\fIother\-options\fR\fR\fB my_database\fR
518 .fi
519 .if n \{\
520 .RE
521 .\}
522 .sp
523 Provide the correct path to the database directory with
524 \fB\-D\fR, or make sure that the environment variable
525 \fBPGDATA\fR
526 is set\&. Also specify the name of the particular database you want to work in\&.
527 .PP
528 Normally, the single\-user mode server treats newline as the command entry terminator; there is no intelligence about semicolons, as there is in
529 psql\&. To continue a command across multiple lines, you must type backslash just before each newline except the last one\&. The backslash and adjacent newline are both dropped from the input command\&. Note that this will happen even when within a string literal or comment\&.
530 .PP
531 But if you use the
532 \fB\-j\fR
533 command line switch, a single newline does not terminate command entry; instead, the sequence semicolon\-newline\-newline does\&. That is, type a semicolon immediately followed by a completely empty line\&. Backslash\-newline is not treated specially in this mode\&. Again, there is no intelligence about such a sequence appearing within a string literal or comment\&.
534 .PP
535 In either input mode, if you type a semicolon that is not just before or part of a command entry terminator, it is considered a command separator\&. When you do type a command entry terminator, the multiple statements you\*(Aqve entered will be executed as a single transaction\&.
536 .PP
537 To quit the session, type
538 EOF
539 (Control+D, usually)\&. If you\*(Aqve entered any text since the last command entry terminator, then
540 EOF
541 will be taken as a command entry terminator, and another
542 EOF
543 will be needed to exit\&.
544 .PP
545 Note that the single\-user mode server does not provide sophisticated line\-editing features (no command history, for example)\&. Single\-user mode also does not do any background processing, such as automatic checkpoints or replication\&.
546 .SH "EXAMPLES"
547 .PP
548 To start
549 \fBpostgres\fR
550 in the background using default values, type:
551 .sp
552 .if n \{\
553 .RS 4
554 .\}
555 .nf
556 $ \fBnohup postgres >logfile 2>&1 </dev/null &\fR
557 .fi
558 .if n \{\
559 .RE
560 .\}
561 .PP
562 To start
563 \fBpostgres\fR
564 with a specific port, e\&.g\&., 1234:
565 .sp
566 .if n \{\
567 .RS 4
568 .\}
569 .nf
570 $ \fBpostgres \-p 1234\fR
571 .fi
572 .if n \{\
573 .RE
574 .\}
575 .sp
576 To connect to this server using
577 psql, specify this port with the \-p option:
578 .sp
579 .if n \{\
580 .RS 4
581 .\}
582 .nf
583 $ \fBpsql \-p 1234\fR
584 .fi
585 .if n \{\
586 .RE
587 .\}
588 .sp
589 or set the environment variable
590 \fBPGPORT\fR:
591 .sp
592 .if n \{\
593 .RS 4
594 .\}
595 .nf
596 $ \fBexport PGPORT=1234\fR
597 $ \fBpsql\fR
598 .fi
599 .if n \{\
600 .RE
601 .\}
602 .PP
603 Named run\-time parameters can be set in either of these styles:
604 .sp
605 .if n \{\
606 .RS 4
607 .\}
608 .nf
609 $ \fBpostgres \-c work_mem=1234\fR
610 $ \fBpostgres \-\-work\-mem=1234\fR
611 .fi
612 .if n \{\
613 .RE
614 .\}
615 .sp
616 Either form overrides whatever setting might exist for
617 \fIwork_mem\fR
618 in
619 postgresql\&.conf\&. Notice that underscores in parameter names can be written as either underscore or dash on the command line\&. Except for short\-term experiments, it\*(Aqs probably better practice to edit the setting in
620 postgresql\&.conf
621 than to rely on a command\-line switch to set a parameter\&.
622 .SH "SEE ALSO"
623 .PP
624 \fBinitdb\fR(1),
625 \fBpg_ctl\fR(1)