Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
server-shutdown.html66 linesDownload Raw Back to 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>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 16.3 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 <a href="#SERVER-SHUTDOWN" class="id_link">#</a></h2></div></div></div><a id="id-1.6.6.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 supervisor5   <code class="command">postgres</code> process.6  </p><p>7   If you are using a pre-packaged version8   of <span class="productname">PostgreSQL</span>, and you used its provisions9   for starting the server, then you should also use its provisions for10   stopping the server.  Consult the package-level documentation for11   details.12  </p><p>13   When managing the server directly, you can control the type of shutdown14   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.6.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 server20       disallows new connections, but lets existing sessions end their21       work normally. It shuts down only after all of the sessions terminate.22       If the server is in recovery when a smart23       shutdown is requested, recovery and streaming replication will be24       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.6.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 existing28       server processes <span class="systemitem">SIGTERM</span>, which will cause them29       to abort their current transactions and exit promptly. It then30       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.6.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 child34      processes and wait for them to terminate.  If any do not terminate35      within 5 seconds, they will be sent <span class="systemitem">SIGKILL</span>.36      The supervisor server process exits as soon as all child processes have37      exited, without doing normal database shutdown processing.38      This will lead to recovery (by39      replaying the WAL log) upon next start-up. This is recommended40      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 convenient44   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 be48   found using the <code class="command">ps</code> program, or from the file49   <code class="filename">postmaster.pid</code> in the data directory. For50   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 the56    server.  Doing so will prevent the server from releasing shared memory and57    semaphores.  Furthermore, <span class="systemitem">SIGKILL</span> kills58    the <code class="command">postgres</code> process without letting it relay the59    signal to its subprocesses, so it might be necessary to kill the60    individual subprocesses by hand as well.61   </p></div><p>62   To terminate an individual session while allowing other sessions to63   continue, use <code class="function">pg_terminate_backend()</code> (see <a class="xref" href="functions-admin.html#FUNCTIONS-ADMIN-SIGNAL-TABLE" title="Table 9.90. Server Signaling Functions">Table 9.90</a>) or send a64   <span class="systemitem">SIGTERM</span> signal to the child process associated with65   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="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 16.3 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>
codekingpro/portable-devtools · Team Ai