バージョンごとのドキュメント一覧

19.5. サーバのシャットダウン #

<title>Shutting Down the Server</title>

There are several ways to shut down the database server. Under the hood, they all reduce to sending a signal to the supervisor <command>postgres</command> process. データベースサーバをシャットダウンする方法は複数あります。 内部的には、これらはすべてスーパーバイザのpostgresプロセスにシグナルを送信することになります。

If you are using a pre-packaged version of <productname>PostgreSQL</productname>, 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. パッケージ化された版のPostgreSQLを使用していて、サーバの起動にその規定を使用した場合は、サーバの停止にもその規定を使用する必要があります。 詳細についてはパッケージレベルのドキュメントを参照してください。

When managing the server directly, you can control the type of shutdown by sending different signals to the <command>postgres</command> process: サーバを直接管理する場合は、postgresプロセスに異なるシグナルを送信することで、シャットダウンのタイプを制御できます。

SIGTERM

This is the <firstterm>Smart Shutdown</firstterm> mode. After receiving <systemitem>SIGTERM</systemitem>, 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. これはスマートシャットダウンモードです。 SIGTERMを受信した後、サーバーは新しい接続を禁止しますが、既存のセッションは正常に終了させます。 サーバーはすべてのセッションが終了した後にのみシャットダウンします。 スマートシャットダウンが要求されたときにサーバーがリカバリ中の場合、リカバリとストリーミングレプリケーションはすべての通常セッションが終了した後にのみ停止します。

SIGINT

This is the <firstterm>Fast Shutdown</firstterm> mode. The server disallows new connections and sends all existing server processes <systemitem>SIGTERM</systemitem>, 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. これは高速シャットダウンモードです。 サーバは新しい接続を禁止しすべての存在するサーバプロセスにSIGTERMを送り、この結果サーバプロセスは現在のトランザクションをアボートし、即座に終了します。 そして サーバはすべてのサーバプロセスの終了を待って、最後にシャットダウンします。

SIGQUIT

This is the <firstterm>Immediate Shutdown</firstterm> mode. The server will send <systemitem>SIGQUIT</systemitem> to all child processes and wait for them to terminate. If any do not terminate within 5 seconds, they will be sent <systemitem>SIGKILL</systemitem>. 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. これは即時シャットダウンモードです。 サーバは、すべての子プロセスにSIGQUITを送信し、それらが終了するのを待ちます。 5秒以内に終了しないものには、SIGKILLが送られます。 すべての子プロセスが終了したら、スーパーバイザサーバプロセスはすぐに終了しますが、このとき通常のデータベースのシャットダウン処理を実行しません。 これは次の起動時に(WALログを再実行することで)リカバリをすることになります。 これは緊急の時にのみ使うことを勧めます。

The <xref linkend="app-pg-ctl"/> program provides a convenient interface for sending these signals to shut down the server. Alternatively, you can send the signal directly using <command>kill</command> on non-Windows systems. The <acronym>PID</acronym> of the <command>postgres</command> process can be found using the <command>ps</command> program, or from the file <filename>postmaster.pid</filename> in the data directory. For example, to do a fast shutdown: pg_ctlプログラムは、サーバをシャットダウンさせるシグナルを送信するための便利なインタフェースを提供します。 他にも、Windows以外のシステムではkillを使用して直接シグナルを送信することもできます。 postgresプロセスのPIDは、psプログラム、もしくはデータディレクトリの中のpostmaster.pidファイルを使用して見つけることができます。 例えば、高速シャットダウンをするためには下記のようになります。

$ kill -INT `head -1 /usr/local/pgsql/data/postmaster.pid`

重要

It is best not to use <systemitem>SIGKILL</systemitem> to shut down the server. Doing so will prevent the server from releasing shared memory and semaphores. Furthermore, <systemitem>SIGKILL</systemitem> kills the <command>postgres</command> process without letting it relay the signal to its subprocesses, so it might be necessary to kill the individual subprocesses by hand as well. サーバをシャットダウンするためにSIGKILLを使わない方が良いでしょう。 これによってサーバが共有メモリとセマフォを解放できなくなります。 さらに、SIGKILLは、子プロセスにシグナルを中継することなくpostgresを停止させます。 このため、個々の子プロセスを停止させるために、同じ作業を手作業で行わなければならなくなります。

To terminate an individual session while allowing other sessions to continue, use <function>pg_terminate_backend()</function> (see <xref linkend="functions-admin-signal-table"/>) or send a <systemitem>SIGTERM</systemitem> signal to the child process associated with the session. 他のセッションを継続させながら個別のセッションを停止するにはpg_terminate_backend()表 9.90を参照)を使用するか、そのセッションに関連する子プロセスにSIGTERMシグナルを送ります。