|
- <?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>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 V1.79.1" /><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><div xmlns="http://www.w3.org/TR/xhtml1/transitional" 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 12.4 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></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</h2></div></div></div><a id="id-1.6.5.7.2" class="indexterm"></a><p>
- There are several ways to shut down the database server. You control
- the type of shutdown by sending different signals to the master
- <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.5.7.3.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 online backup mode, it additionally waits
- until online backup mode is no longer active. While backup mode is
- active, new connections will still be allowed, but only to superusers
- (this exception allows a superuser to connect to terminate
- online backup mode). 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.5.7.3.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.
- If the server is in online backup mode, backup mode will be
- terminated, rendering the backup useless.
- </p></dd><dt><span class="term"><span class="systemitem">SIGQUIT</span><a id="id-1.6.5.7.3.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 master 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.83. Server Signaling Functions">Table 9.83</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">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="runtime.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="upgrading.html">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">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>
|