]> begriffs open source - ai-pg/blob - full-docs/txt/server-shutdown.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / server-shutdown.txt
1
2 18.5. Shutting Down the Server #
3
4    There are several ways to shut down the database server. Under the
5    hood, they all reduce to sending a signal to the supervisor postgres
6    process.
7
8    If you are using a pre-packaged version of PostgreSQL, and you used its
9    provisions for starting the server, then you should also use its
10    provisions for stopping the server. Consult the package-level
11    documentation for details.
12
13    When managing the server directly, you can control the type of shutdown
14    by sending different signals to the postgres process:
15
16    SIGTERM
17           This is the Smart Shutdown mode. After receiving SIGTERM, the
18           server disallows new connections, but lets existing sessions end
19           their work normally. It shuts down only after all of the
20           sessions terminate. If the server is in recovery when a smart
21           shutdown is requested, recovery and streaming replication will
22           be stopped only after all regular sessions have terminated.
23
24    SIGINT
25           This is the Fast Shutdown mode. The server disallows new
26           connections and sends all existing server processes SIGTERM,
27           which will cause them to abort their current transactions and
28           exit promptly. It then waits for all server processes to exit
29           and finally shuts down.
30
31    SIGQUIT
32           This is the Immediate Shutdown mode. The server will send
33           SIGQUIT to all child processes and wait for them to terminate.
34           If any do not terminate within 5 seconds, they will be sent
35           SIGKILL. The supervisor server process exits as soon as all
36           child processes have exited, without doing normal database
37           shutdown processing. This will lead to recovery (by replaying
38           the WAL log) upon next start-up. This is recommended only in
39           emergencies.
40
41    The pg_ctl program provides a convenient interface for sending these
42    signals to shut down the server. Alternatively, you can send the signal
43    directly using kill on non-Windows systems. The PID of the postgres
44    process can be found using the ps program, or from the file
45    postmaster.pid in the data directory. For example, to do a fast
46    shutdown:
47 $ kill -INT `head -1 /usr/local/pgsql/data/postmaster.pid`
48
49 Important
50
51    It is best not to use SIGKILL to shut down the server. Doing so will
52    prevent the server from releasing shared memory and semaphores.
53    Furthermore, SIGKILL kills the postgres process without letting it
54    relay the signal to its subprocesses, so it might be necessary to kill
55    the individual subprocesses by hand as well.
56
57    To terminate an individual session while allowing other sessions to
58    continue, use pg_terminate_backend() (see Table 9.96) or send a SIGTERM
59    signal to the child process associated with the session.