summaryrefslogtreecommitdiffstats
path: root/doc/src/sgml/html/server-shutdown.html
blob: 82eaf3dd7b0383f9de7d7d15c51592f1ef09376c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!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>19.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="19.4. Managing Kernel Resources" /><link rel="next" href="upgrading.html" title="19.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">19.5. Shutting Down the Server</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="kernel-resources.html" title="19.4. Managing Kernel Resources">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="runtime.html" title="Chapter 19. Server Setup and Operation">Up</a></td><th width="60%" align="center">Chapter 19. Server Setup and Operation</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 15.7 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="upgrading.html" title="19.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">19.5. Shutting Down the Server</h2></div></div></div><a id="id-1.6.6.8.2" class="indexterm"></a><p>
   There are several ways to shut down the database server.
   Under the hood, they all reduce to sending a signal to the supervisor
   <code class="command">postgres</code> process.
  </p><p>
   If you are using a pre-packaged version
   of <span class="productname">PostgreSQL</span>, and you used its provisions
   for starting the server, then you should also use its provisions for
   stopping the server.  Consult the package-level documentation for
   details.
  </p><p>
   When managing the server directly, you can control the type of shutdown
   by sending different signals to the <code class="command">postgres</code>
   process:

   </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="systemitem">SIGTERM</span><a id="id-1.6.6.8.5.2.1.1.2" class="indexterm"></a></span></dt><dd><p>
       This is the <em class="firstterm">Smart Shutdown</em> mode.
       After receiving <span class="systemitem">SIGTERM</span>, the server
       disallows new connections, but lets existing sessions end their
       work normally. It shuts down only after all of the sessions terminate.
       If the server is in recovery when a smart
       shutdown is requested, recovery and streaming replication will be
       stopped only after all regular sessions have terminated.
      </p></dd><dt><span class="term"><span class="systemitem">SIGINT</span><a id="id-1.6.6.8.5.2.2.1.2" class="indexterm"></a></span></dt><dd><p>
       This is the <em class="firstterm">Fast Shutdown</em> mode.
       The server disallows new connections and sends all existing
       server processes <span class="systemitem">SIGTERM</span>, which will cause them
       to abort their current transactions and exit promptly. It then
       waits for all server processes to exit and finally shuts down.
      </p></dd><dt><span class="term"><span class="systemitem">SIGQUIT</span><a id="id-1.6.6.8.5.2.3.1.2" class="indexterm"></a></span></dt><dd><p>
      This is the <em class="firstterm">Immediate Shutdown</em> mode.
      The server will send <span class="systemitem">SIGQUIT</span> to all child
      processes and wait for them to terminate.  If any do not terminate
      within 5 seconds, they will be sent <span class="systemitem">SIGKILL</span>.
      The supervisor server process exits as soon as all child processes have
      exited, without doing normal database shutdown processing.
      This will lead to recovery (by
      replaying the WAL log) upon next start-up. This is recommended
      only in emergencies.
      </p></dd></dl></div><p>
  </p><p>
   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
   interface for sending these signals to shut down the server.
   Alternatively, you can send the signal directly using <code class="command">kill</code>
   on non-Windows systems.
   The <acronym class="acronym">PID</acronym> of the <code class="command">postgres</code> process can be
   found using the <code class="command">ps</code> program, or from the file
   <code class="filename">postmaster.pid</code> in the data directory. For
   example, to do a fast shutdown:
</p><pre class="screen">
$ <strong class="userinput"><code>kill -INT `head -1 /usr/local/pgsql/data/postmaster.pid`</code></strong>
</pre><p>
  </p><div class="important"><h3 class="title">Important</h3><p>
    It is best not to use <span class="systemitem">SIGKILL</span> to shut down the
    server.  Doing so will prevent the server from releasing shared memory and
    semaphores.  Furthermore, <span class="systemitem">SIGKILL</span> kills
    the <code class="command">postgres</code> process without letting it relay the
    signal to its subprocesses, so it might be necessary to kill the
    individual subprocesses by hand as well.
   </p></div><p>
   To terminate an individual session while allowing other sessions to
   continue, use <code class="function">pg_terminate_backend()</code> (see <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-SIGNAL-TABLE" title="Table 9.88. Server Signaling Functions">Table 9.88</a>) or send a
   <span class="systemitem">SIGTERM</span> signal to the child process associated with
   the session.
  </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="19.4. Managing Kernel Resources">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="runtime.html" title="Chapter 19. Server Setup and Operation">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="upgrading.html" title="19.6. Upgrading a PostgreSQL Cluster">Next</a></td></tr><tr><td width="40%" align="left" valign="top">19.4. Managing Kernel Resources </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 15.7 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 19.6. Upgrading a <span class="productname">PostgreSQL</span> Cluster</td></tr></table></div></body></html>