postgres
[option
...]postgres
is the PostgreSQL database server. In order for a client application to access a database it connects (over a network or locally) to a running postgres
instance. The postgres
instance then starts a separate server process to handle the connection.postgres
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 “data area”). More than one postgres
instance can run on a system at one time, so long as they use different data areas and different communication ports (see below). When postgres
starts it needs to know the location of the data area. The location must be specified by the -D
option or the PGDATA
environment variable; there is no default. Typically, -D
or PGDATA
points directly to the data area directory created by initdb. Other possible file layouts are discussed in Section 19.2.postgres
starts in the foreground and prints log messages to the standard error stream. In practical applications postgres
should be started as a background process, perhaps at boot time.postgres
command can also be called in single-user mode. The primary use for this mode is during bootstrapping by initdb. 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.postgres
accepts the following command-line arguments. For a detailed discussion of the options consult 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 PGOPTIONS
is set, then libpq-based clients will pass that string to the server, which will interpret it as postgres
command-line options.-B
nbuffers
-c
name
=value
-c
can appear multiple times to set multiple parameters.-C
name
-c
option above for details.) This can be used on a running server, and returns values frompostgresql.conf
, modified by any parameters supplied in this invocation. It does not reflect parameters supplied when the cluster was started.-d
debug-level
-d 0
for a specific session, which will prevent the server log level of the parent postgres
process from being propagated to this session.-D
datadir
-e
DMY
ordering of input date fields. This also causes the day to be printed before the month in certain date output formats. See Section 8.5 for more information.-F
fsync
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 fsyncconfiguration parameter. Read the detailed documentation before using this!-h
hostname
postgres
is to listen for TCP/IP connections from client applications. The value can also be a comma-separated list of addresses, or *
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 localhost. Specifying this option is equivalent to setting the listen_addresses configuration parameter.-i
listen_addresses
to *
in postgresql.conf
or via -h
.listen_addresses
directly.-k
directory
postgres
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 /tmp
, but that can be changed at build time. Specifying this option is equivalent to setting the unix_socket_directories configuration parameter.-l
-N
max-connections
-o
extra-options
extra-options
are passed to all server processes started by this postgres
process.extra-options
are considered to separate arguments, unless escaped with a backslash (\
); write \\
to represent a literal backslash. Multiple arguments can also be specified via multiple uses of -o
.postgres
command line.-p
port
postgres
is to listen for connections from client applications. Defaults to the value of the PGPORT
environment variable, or if PGPORT
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 PGPORT
.-s
-S
work-mem
work_mem
configuration parameter in Section 19.4.1.-V
--version
--
name
=value
-c
.--describe-config
COPY
format. It is designed primarily for use by administration tools.-?
--help
-f
{ s | i | o | b | t | n | m | h }
s
and i
disable sequential and index scans respectively, o
, b
and t
disable index-only scans, bitmap index scans, and TID scans respectively, while n
, m
, and h
disable nested-loop, merge and hash joins respectively.-fs
and -fn
options simply discourage the optimizer from using those plan types if it has any other alternative.-n
postgres
will not reinitialize shared data structures. A knowledgeable system programmer can then use a debugger to examine shared memory and semaphore state.-O
initdb
.-P
-t
pa[rser] | pl[anner] | e[xecutor]
-s
option.-T
postgres
will stop all other server processes by sending the signal SIGSTOP
, but will not cause them to terminate. This permits system programmers to collect core dumps from all server processes by hand.-v
protocol
-W
seconds
--single
database
-E
-j
-r
filename
filename
. This option is only honored when supplied as a command-line option.PGCLIENTENCODING
PGDATA
PGDATESTYLE
PGPORT
semget
or shmget
probably indicates you need to configure your kernel to provide adequate shared memory and semaphores. For more discussion see Section 18.4. You might be able to postpone reconfiguring your kernel by decreasing shared_buffers to reduce the shared memory consumption of PostgreSQL, and/or by reducing max_connections to reduce the semaphore consumption.postgres
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 “trusted” and only permit the Unix superuser to access them.postgres
server safely and comfortably.SIGKILL
to kill the main postgres
server. Doing so will prevent postgres
from freeing the system resources (e.g., shared memory and semaphores) that it holds before terminating. This might cause problems for starting a fresh postgres
run.postgres
server normally, the signals SIGTERM
, SIGINT
, or SIGQUIT
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.SIGHUP
signal will reload the server configuration files. It is also possible to send SIGHUP
to an individual server process, but that is usually not sensible.SIGINT
signal to the process running that command. To terminate a backend process cleanly, send SIGTERM
to that process. See also pg_cancel_backend
and pg_terminate_backend
in Section 9.26.2 for the SQL-callable equivalents of these two actions.postgres
server uses SIGQUIT
to tell subordinate server processes to terminate without normal cleanup. This signal should not be used by users. It is also unwise to send SIGKILL
to a server process — the main postgres
process will interpret this as a crash and will force all the sibling processes to quit as part of its standard crash-recovery procedure.--
options will not work on FreeBSD or OpenBSD. Use -c
instead. This is a bug in the affected operating systems; a future release of PostgreSQL will provide a workaround if this is not fixed.-D
, or make sure that the environment variable PGDATA
is set. Also specify the name of the particular database you want to work in.-j
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.postgres
in the background using default values, type:postgres
with a specific port, e.g. 1234:PGPORT
:work_mem
in 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's probably better practice to edit the setting in postgresql.conf
than to rely on a command-line switch to set a parameter.