]> begriffs open source - ai-pg/blob - full-docs/src/sgml/html/server-shutdown.html
WIP: toc builder
[ai-pg] / full-docs / src / sgml / html / server-shutdown.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>18.5. Shutting Down the Server</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="kernel-resources.html" title="18.4. Managing Kernel Resources" /><link rel="next" href="upgrading.html" title="18.6. Upgrading a PostgreSQL Cluster" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">18.5. Shutting Down the Server</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="kernel-resources.html" title="18.4. Managing Kernel Resources">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="runtime.html" title="Chapter 18. Server Setup and Operation">Up</a></td><th width="60%" align="center">Chapter 18. Server Setup and Operation</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="upgrading.html" title="18.6. Upgrading a PostgreSQL Cluster">Next</a></td></tr></table><hr /></div><div class="sect1" id="SERVER-SHUTDOWN"><div class="titlepage"><div><div><h2 class="title" style="clear: both">18.5. Shutting Down the Server <a href="#SERVER-SHUTDOWN" class="id_link">#</a></h2></div></div></div><a id="id-1.6.5.8.2" class="indexterm"></a><p>
3    There are several ways to shut down the database server.
4    Under the hood, they all reduce to sending a signal to the supervisor
5    <code class="command">postgres</code> process.
6   </p><p>
7    If you are using a pre-packaged version
8    of <span class="productname">PostgreSQL</span>, and you used its provisions
9    for starting the server, then you should also use its provisions for
10    stopping the server.  Consult the package-level documentation for
11    details.
12   </p><p>
13    When managing the server directly, you can control the type of shutdown
14    by sending different signals to the <code class="command">postgres</code>
15    process:
16
17    </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="systemitem">SIGTERM</span><a id="id-1.6.5.8.5.2.1.1.2" class="indexterm"></a></span></dt><dd><p>
18        This is the <em class="firstterm">Smart Shutdown</em> mode.
19        After receiving <span class="systemitem">SIGTERM</span>, the server
20        disallows new connections, but lets existing sessions end their
21        work normally. It shuts down only after all of the sessions terminate.
22        If the server is in recovery when a smart
23        shutdown is requested, recovery and streaming replication will be
24        stopped only after all regular sessions have terminated.
25       </p></dd><dt><span class="term"><span class="systemitem">SIGINT</span><a id="id-1.6.5.8.5.2.2.1.2" class="indexterm"></a></span></dt><dd><p>
26        This is the <em class="firstterm">Fast Shutdown</em> mode.
27        The server disallows new connections and sends all existing
28        server processes <span class="systemitem">SIGTERM</span>, which will cause them
29        to abort their current transactions and exit promptly. It then
30        waits for all server processes to exit and finally shuts down.
31       </p></dd><dt><span class="term"><span class="systemitem">SIGQUIT</span><a id="id-1.6.5.8.5.2.3.1.2" class="indexterm"></a></span></dt><dd><p>
32       This is the <em class="firstterm">Immediate Shutdown</em> mode.
33       The server will send <span class="systemitem">SIGQUIT</span> to all child
34       processes and wait for them to terminate.  If any do not terminate
35       within 5 seconds, they will be sent <span class="systemitem">SIGKILL</span>.
36       The supervisor server process exits as soon as all child processes have
37       exited, without doing normal database shutdown processing.
38       This will lead to recovery (by
39       replaying the WAL log) upon next start-up. This is recommended
40       only in emergencies.
41       </p></dd></dl></div><p>
42   </p><p>
43    The <a class="xref" href="app-pg-ctl.html" title="pg_ctl"><span class="refentrytitle"><span class="application">pg_ctl</span></span></a> program provides a convenient
44    interface for sending these signals to shut down the server.
45    Alternatively, you can send the signal directly using <code class="command">kill</code>
46    on non-Windows systems.
47    The <acronym class="acronym">PID</acronym> of the <code class="command">postgres</code> process can be
48    found using the <code class="command">ps</code> program, or from the file
49    <code class="filename">postmaster.pid</code> in the data directory. For
50    example, to do a fast shutdown:
51 </p><pre class="screen">
52 $ <strong class="userinput"><code>kill -INT `head -1 /usr/local/pgsql/data/postmaster.pid`</code></strong>
53 </pre><p>
54   </p><div class="important"><h3 class="title">Important</h3><p>
55     It is best not to use <span class="systemitem">SIGKILL</span> to shut down the
56     server.  Doing so will prevent the server from releasing shared memory and
57     semaphores.  Furthermore, <span class="systemitem">SIGKILL</span> kills
58     the <code class="command">postgres</code> process without letting it relay the
59     signal to its subprocesses, so it might be necessary to kill the
60     individual subprocesses by hand as well.
61    </p></div><p>
62    To terminate an individual session while allowing other sessions to
63    continue, use <code class="function">pg_terminate_backend()</code> (see <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-SIGNAL-TABLE" title="Table 9.96. Server Signaling Functions">Table 9.96</a>) or send a
64    <span class="systemitem">SIGTERM</span> signal to the child process associated with
65    the session.
66   </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="kernel-resources.html" title="18.4. Managing Kernel Resources">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="runtime.html" title="Chapter 18. Server Setup and Operation">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="upgrading.html" title="18.6. Upgrading a PostgreSQL Cluster">Next</a></td></tr><tr><td width="40%" align="left" valign="top">18.4. Managing Kernel Resources </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 18.6. Upgrading a <span class="productname">PostgreSQL</span> Cluster</td></tr></table></div></body></html>