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

pg_ctl

pg_ctl <refpurpose>initialize, start, stop, or control a <productname>PostgreSQL</productname> server</refpurpose> PostgreSQLサーバを初期化、起動、停止、制御する

概要

pg_ctl init[db] [-D datadir] [-s] [-o initdb-options]

pg_ctl start [-D datadir] [-l filename] [-W] [-t seconds] [-s] [-o options] [-p path] [-c]

pg_ctl stop [-D datadir] [-m s[mart] | f[ast] | i[mmediate] ] [-W] [-t seconds] [-s]

pg_ctl restart [-D datadir] [-m s[mart] | f[ast] | i[mmediate] ] [-W] [-t seconds] [-s] [-o options] [-c]

pg_ctl reload [-D datadir] [-s]

pg_ctl status [-D datadir]

pg_ctl promote [-D datadir] [-W] [-t seconds] [-s]

pg_ctl logrotate [-D datadir] [-s]

pg_ctl kill signal_name process_id

<para>On Microsoft Windows, also:</para>

Microsoft Windows上ではさらに

pg_ctl register [-D datadir] [-N servicename] [-U username] [-P password] [-S a[uto] | d[emand] ] [-e source] [-W] [-t seconds] [-s] [-o options]

pg_ctl unregister [-N servicename]

説明

<title>Description</title>

<application>pg_ctl</application> is a utility for initializing a <productname>PostgreSQL</productname> database cluster, starting, stopping, or restarting the <productname>PostgreSQL</productname> database server (<xref linkend="app-postgres"/>), or displaying the status of a running server. Although the server can be started manually, <application>pg_ctl</application> encapsulates tasks such as redirecting log output and properly detaching from the terminal and process group. It also provides convenient options for controlled shutdown. pg_ctlPostgreSQLデータベースクラスタの初期化、PostgreSQLのデータベースサーバ(postgres)を起動、停止、再起動する、あるいは稼働中のサーバの状態を表示するためのユーティリティです。 サーバは手動で起動することも可能ですが、pg_ctlは、ログ出力のリダイレクトや、端末とプロセスグループの適切な分離などの作業を隠蔽してくれます。 さらにシャットダウン制御のための便利なオプションも提供します。

The <option>init</option> or <option>initdb</option> mode creates a new <productname>PostgreSQL</productname> database cluster, that is, a collection of databases that will be managed by a single server instance. This mode invokes the <command>initdb</command> command. See <xref linkend="app-initdb"/> for details. initまたはinitdbモードはPostgreSQLの新しいデータベースクラスタ、つまり、単一のサーバインスタンスで管理されるデータベースの集合を作成します。 このモードはinitdbコマンドを呼び出します。 詳しくはinitdbを参照して下さい。

<option>start</option> mode launches a new server. The server is started in the background, and its standard input is attached to <filename>/dev/null</filename> (or <literal>nul</literal> on Windows). On Unix-like systems, by default, the server's standard output and standard error are sent to <application>pg_ctl</application>'s standard output (not standard error). The standard output of <application>pg_ctl</application> should then be redirected to a file or piped to another process such as a log rotating program like <application>rotatelogs</application>; otherwise <command>postgres</command> will write its output to the controlling terminal (from the background) and will not leave the shell's process group. On Windows, by default the server's standard output and standard error are sent to the terminal. These default behaviors can be changed by using <option>-l</option> to append the server's output to a log file. Use of either <option>-l</option> or output redirection is recommended. startモードは、新しいサーバを起動します。 サーバはバックグラウンドで起動され、その標準入力は/dev/null(Windowsの場合はnul)に接続されます。 Unix系のシステムではデフォルトで、サーバの標準出力と標準エラーはpg_ctlの標準出力に転送されます(標準エラー出力には転送されません)。 pg_ctlの標準出力はファイルにリダイレクトするか、例えばrotatelogsなどのログローテーションプログラムのような別プロセスにパイプで渡すべきです。 こうしないと、postgresはその出力を(バックグラウンドから)制御端末に書き出しますので、シェルのプロセスグループから切り離すことができません。 Windowsではデフォルトで、サーバの標準出力と標準エラーは端末に送信されます。 こうしたデフォルトの動作は-lを用いてサーバの出力をログファイルに追加するように変更することができます。 -lまたは出力のリダイレクトのどちらかを使用することを勧めます。

<option>stop</option> mode shuts down the server that is running in the specified data directory. Three different shutdown methods can be selected with the <option>-m</option> option. <quote>Smart</quote> mode disallows new connections, then waits for all existing clients to disconnect. If the server is in hot standby, recovery and streaming replication will be terminated once all clients have disconnected. <quote>Fast</quote> mode (the default) does not wait for clients to disconnect. All active transactions are rolled back and clients are forcibly disconnected, then the server is shut down. <quote>Immediate</quote> mode will abort all server processes immediately, without a clean shutdown. This choice will lead to a crash-recovery cycle during the next server start. stopモードは、指定されたデータディレクトリで稼働しているサーバを停止(シャットダウン)します。 -mオプションでは、3つの異なる停止方式を選択できます。 smartモードは、新しい接続を禁止してから、全ての接続しているクライアントが切断するまで待ちます。 サーバがホットスタンバイ状態の場合、すべてのクライアント接続が切断された後にリカバリとストリーミングレプリケーションは終了します。 fastモード(デフォルト)はクライアントが切断するまで待ちません。 全ての実行中のトランザクションをロールバックし、クライアントとの接続を強制的に切断した後、サーバを停止します。 immediateモードは、クリーンアップ処理なしで、全てのサーバプロセスを即座に中断します。 これを選択すると、次回のサーバ起動時にクラッシュリカバリサイクルが始まります。

<option>restart</option> mode effectively executes a stop followed by a start. This allows changing the <command>postgres</command> command-line options, or changing configuration-file options that cannot be changed without restarting the server. If relative paths were used on the command line during server start, <option>restart</option> might fail unless <application>pg_ctl</application> is executed in the same current directory as it was during server start. restartモードは、実質的にはstopを実行して、その後、startを実行します。 この時、postgresのコマンドラインオプションを変更、またはサーバの再起動なしには変更できない設定ファイルオプションを変更することができます。 サーバ起動時に相対パスがコマンドラインから使用されていた場合、サーバ起動時と同じカレントディレクトリでpg_ctlを実行しなければ、restartが失敗する可能性があります。

<option>reload</option> mode simply sends the <command>postgres</command> server process a <systemitem>SIGHUP</systemitem> signal, causing it to reread its configuration files (<filename>postgresql.conf</filename>, <filename>pg_hba.conf</filename>, etc.). This allows changing configuration-file options that do not require a full server restart to take effect. reloadモードは、単にpostgresサーバプロセスにSIGHUPシグナルを送り、(postgresql.confpg_hba.confなどの)設定ファイルの再読み込みを実行させます。 これにより、設定ファイルのオプションで完全なサーバ再起動を必要としないものについて、変更を反映させることができます。

<option>status</option> mode checks whether a server is running in the specified data directory. If it is, the server's <acronym>PID</acronym> and the command line options that were used to invoke it are displayed. If the server is not running, <application>pg_ctl</application> returns an exit status of 3. If an accessible data directory is not specified, <application>pg_ctl</application> returns an exit status of 4. statusモードは指定したデータディレクトリでサーバが稼働しているかどうかを確認します。 稼働している場合はサーバのPIDと、サーバを起動する時に使われたコマンドラインオプションを表示します。 サーバが稼働していない場合、pg_ctlは終了ステータス3を返します。 アクセス可能なデータディレクトリが指定されていない場合、pg_ctlは終了ステータス4を返します。

<option>promote</option> mode commands the standby server that is running in the specified data directory to end standby mode and begin read-write operations. promoteモードは、指定したデータディレクトリで実行中のスタンバイサーバに、スタンバイモードを終了し、読み書きの操作を開始するように指示します。

<option>logrotate</option> mode rotates the server log file. For details on how to use this mode with external log rotation tools, see <xref linkend="logfile-maintenance"/>. logrotateモードはサーバログファイルをローテーションします。 外部のログローテーションツールでこのモードを使う方法の詳細については、25.3を参照してください。

<option>kill</option> mode sends a signal to a specified process. This is primarily valuable on <productname>Microsoft Windows</productname> which does not have a built-in <application>kill</application> command. Use <literal>&#45;-help</literal> to see a list of supported signal names. killモードは指定したプロセスにシグナルを送信します。 これは主に、組み込みのkillコマンドがないMicrosoft Windowsで有用です。 サポートされているシグナル名の一覧を見るには--helpを使ってください。

<option>register</option> mode registers the <productname>PostgreSQL</productname> server as a system service on <productname>Microsoft Windows</productname>. The <option>-S</option> option allows selection of service start type, either <quote>auto</quote> (start service automatically on system startup) or <quote>demand</quote> (start service on demand). registerモードはPostgreSQLサーバをMicrosoft Windows上のシステムサービスとして登録します。 -Sオプションにより、auto(システムの起動時に自動的にサービスを開始する)とdemand(要求に応じてサービスを開始する)のいずれかのサービス開始種別を選択できます。

<option>unregister</option> mode unregisters a system service on <productname>Microsoft Windows</productname>. This undoes the effects of the <option>register</option> command. unregisterモードによりMicrosoft Windows上のシステムサービスを登録解除することができます。 これは過去にregisterコマンドによりなされた変更を元に戻します。

オプション

<title>Options</title>
-c
--core-files

Attempt to allow server crashes to produce core files, on platforms where this is possible, by lifting any soft resource limit placed on core files. This is useful in debugging or diagnosing problems by allowing a stack trace to be obtained from a failed server process. 実現可能なプラットフォームにおいて、サーバクラッシュ時にcoreファイルを生成できるように関連するソフトリソース制限を上げます。 障害が起きたサーバプロセスからスタックトレースを取得できますので、問題のデバッグや診断の際に有用です。

-D datadir
--pgdata=datadir

Specifies the file system location of the database configuration files. If this option is omitted, the environment variable <envar>PGDATA</envar> is used. データベース設定ファイルのファイルシステム上の場所を指定します。 このオプションが省略された場合、環境変数PGDATAが使われます。

-l filename
--log=filename

Append the server log output to <replaceable>filename</replaceable>. If the file does not exist, it is created. The <systemitem>umask</systemitem> is set to 077, so access to the log file is disallowed to other users by default. サーバログ出力をfilenameに追記します。 そのファイルが存在しない場合は作成されます。 umaskは077に設定されますので、他のユーザからのログファイルへのアクセスはデフォルトでは許可されません。

-m mode
--mode=mode

Specifies the shutdown mode. <replaceable>mode</replaceable> can be <literal>smart</literal>, <literal>fast</literal>, or <literal>immediate</literal>, or the first letter of one of these three. If this option is omitted, <literal>fast</literal> is the default. 停止(シャットダウン)モードを指定します。 modesmartfastimmediate、もしくはこの3つのモード名の最初の1文字をとることができます。 このオプションが省略された時はfastがデフォルトとなります。

-o options
--options=options

Specifies options to be passed directly to the <command>postgres</command> command. <option>-o</option> can be specified multiple times, with all the given options being passed through. postgresコマンドに直接渡されるオプションを指定します。 -oは複数回指定することができ、そこで指定されたすべてのオプションが渡されます。

The <replaceable>options</replaceable> should usually be surrounded by single or double quotes to ensure that they are passed through as a group. optionsはそれが一つのグループとして渡されるようにするため、通常は単一引用符または二重引用符で括るべきです。

-o initdb-options
--options=initdb-options

Specifies options to be passed directly to the <command>initdb</command> command. <option>-o</option> can be specified multiple times, with all the given options being passed through. initdbコマンドに直接渡されるオプションを指定します。 -oは複数回指定することができ、そこで指定されたすべてのオプションが渡されます。

The <replaceable>initdb-options</replaceable> should usually be surrounded by single or double quotes to ensure that they are passed through as a group. initdb-optionsはそれが一つのグループとして渡されるようにするため、通常は単一引用符または二重引用符で括るべきです。

-p path

Specifies the location of the <filename>postgres</filename> executable. By default the <filename>postgres</filename> executable is taken from the same directory as <command>pg_ctl</command>, or failing that, the hard-wired installation directory. It is not necessary to use this option unless you are doing something unusual and get errors that the <filename>postgres</filename> executable was not found. postgresの実行プログラムの位置を指定します。 デフォルトではpostgresの実行プログラムはpg_ctlと同じディレクトリにあるものとみなされます。また、このディレクトリに存在しなければ、構築時に指定したインストールディレクトリが使われます。 このオプションは、何か異例なことをしていてpostgresが見つからないというようなエラーが出ない限り、使う必要はありません。

In <literal>init</literal> mode, this option analogously specifies the location of the <filename>initdb</filename> executable. initモードでは、このオプションは同様にinitdb実行プログラムの場所を指定します。

-s
--silent

Print only errors, no informational messages. エラーメッセージのみを表示し、その他の情報を表示しません。

-t seconds
--timeout=seconds

Specifies the maximum number of seconds to wait when waiting for an operation to complete (see option <option>-w</option>). Defaults to the value of the <envar>PGCTLTIMEOUT</envar> environment variable or, if not set, to 60 seconds. 操作が完了するまで待機する最大の秒数を指定します(オプション-wを参照)。 デフォルトは環境変数PGCTLTIMEOUTの値で、それが設定されていなければ60秒です。

-V
--version

Print the <application>pg_ctl</application> version and exit. pg_ctlのバージョンを表示し、終了します。

-w
--wait

Wait for the operation to complete. This is supported for the modes <literal>start</literal>, <literal>stop</literal>, <literal>restart</literal>, <literal>promote</literal>, and <literal>register</literal>, and is the default for those modes. 操作が完了するのを待ちます。 これはstartstoprestartpromoteregisterのモードについてサポートされており、これらのモードについてのデフォルトです。

When waiting, <command>pg_ctl</command> repeatedly checks the server's <acronym>PID</acronym> file, sleeping for a short amount of time between checks. Startup is considered complete when the <acronym>PID</acronym> file indicates that the server is ready to accept connections. Shutdown is considered complete when the server removes the <acronym>PID</acronym> file. <command>pg_ctl</command> returns an exit code based on the success of the startup or shutdown. 待機している場合、pg_ctlは繰り返しサーバのPIDファイルを確認し、確認と確認の間は少しの時間スリープします。 起動は、サーバが接続を受け付ける準備ができたことをPIDファイルが示した時に、完了したとみなされます。 停止は、サーバがPIDファイルを削除した時に、完了したとみなされます。 pg_ctlは、起動もしくは停止が成功したかどうかに基づいて終了コードを返します。

If the operation does not complete within the timeout (see option <option>-t</option>), then <command>pg_ctl</command> exits with a nonzero exit status. But note that the operation might continue in the background and eventually succeed. 操作がタイムアウト(オプション-t参照)までに完了しなかった場合、pg_ctlは非ゼロの終了コードで終了します。 しかし、その操作はバックグラウンドで実行し続け、最終的に成功するかもしれないことに注意してください。

-W
--no-wait

Do not wait for the operation to complete. This is the opposite of the option <option>-w</option>. 操作が完了するのを待ちません。 オプション-wの反対です。

If waiting is disabled, the requested action is triggered, but there is no feedback about its success. In that case, the server log file or an external monitoring system would have to be used to check the progress and success of the operation. 待機が無効化されていると、要求された操作は実行されますが、それが成功したかどうかのフィードバックがなくなります。 その場合、サーバのログファイルや外部のモニタリングシステムを使って操作の進行状況や成功したかどうかを確認する必要があるでしょう。

In prior releases of PostgreSQL, this was the default except for the <literal>stop</literal> mode. PostgreSQLの以前のリリースでは、stopモードを除き、これがデフォルトでした。

-?
--help

Show help about <application>pg_ctl</application> command line arguments, and exit. pg_ctlコマンドライン引数の説明を表示し、終了します。

If an option is specified that is valid, but not relevant to the selected operating mode, <application>pg_ctl</application> ignores it. 指定されたオプションが有効ではあるが、指定の操作モードと関係ないものである場合、pg_ctlはそれを無視します。

Windows用オプション

<title>Options for Windows</title>
-e source

Name of the event source for <application>pg_ctl</application> to use for logging to the event log when running as a Windows service. The default is <literal>PostgreSQL</literal>. Note that this only controls messages sent from <application>pg_ctl</application> itself; once started, the server will use the event source specified by its <xref linkend="guc-event-source"/> parameter. Should the server fail very early in startup, before that parameter has been set, it might also log using the default event source name <literal>PostgreSQL</literal>. Windowsのサービスとして実行する際に、イベントログへの出力用にpg_ctlが使用するイベントソースの名前です。 デフォルトはPostgreSQLです。 これはpg_ctl自体からのメッセージのみを制御することに注意してください。 サーバが起動した後は、event_sourceで指定したイベントソースが使用されます。 サーバが起動の非常に早い段階のパラメータが設定されるより前に障害を起こした場合は、デフォルトのイベントソース名のPostgreSQLを使用するかもしれません。

-N servicename

Name of the system service to register. This name will be used as both the service name and the display name. The default is <literal>PostgreSQL</literal>. 登録するシステムサービスの名前です。 この名前は、システム名としても表示名としても使用されます。 デフォルトはPostgreSQLです。

-P password

Password for the user to run the service as. サービスを開始するユーザ用のパスワードです。

-S start-type

Start type of the system service. <replaceable>start-type</replaceable> can be <literal>auto</literal>, or <literal>demand</literal>, or the first letter of one of these two. If this option is omitted, <literal>auto</literal> is the default. システムサービスの起動種類です。 start-typeautodemand、またはこれら2単語の先頭の文字のいずれかです。 このオプションを省略した時はautoがデフォルトとなります。

-U username

User name for the user to run the service as. For domain users, use the format <literal>DOMAIN\username</literal>. サービスを起動するユーザのユーザ名です。 ドメインユーザの場合はDOMAIN\username書式を使用してください。

環境

<title>Environment</title>
PGCTLTIMEOUT

Default limit on the number of seconds to wait when waiting for startup or shutdown to complete. If not set, the default is 60 seconds. 起動または終了が完了するまでに待機する秒数のデフォルトの最大値です。 設定されていない場合のデフォルトは60秒です。

PGDATA

Default data directory location. デフォルトのデータディレクトリの場所です。

Most <command>pg_ctl</command> modes require knowing the data directory location; therefore, the <option>-D</option> option is required unless <envar>PGDATA</envar> is set. ほとんどのpg_ctlのモードはデータディレクトリの位置を知っている必要があるため、PGDATAが設定されていないときは-Dオプションが必須です。

<command>pg_ctl</command>, like most other <productname>PostgreSQL</productname> utilities, also uses the environment variables supported by <application>libpq</application> (see <xref linkend="libpq-envars"/>). また、pg_ctlは、他のほとんどのPostgreSQLユーティリティと同様、libpqでサポートされる環境変数を使用します(34.15を参照してください)。

For additional variables that affect the server, see <xref linkend="app-postgres"/>. サーバに影響を与える他の変数についてはpostgresを参照してください。

ファイル

<title>Files</title>
postmaster.pid

<application>pg_ctl</application> examines this file in the data directory to determine whether the server is currently running. pg_ctlは、データディレクトリのこのファイルを検査して、サーバが現在稼働中かどうかを決定します。

postmaster.opts
<para>If this file exists in the data directory, <application>pg_ctl</application> (in <option>restart</option> mode) will pass the contents of the file as options to <application>postgres</application>, unless overridden by the <option>-o</option> option. The contents of this file are also displayed in <option>status</option> mode.

このファイルがデータディレクトリにあれば、pg_ctl(のrestartモード)は、-oで上書きされるものを除き、このファイルの内容をオプションとしてpostgresに渡します。 また、このファイルの内容がstatusモードで表示されます。

<title>Examples</title>

サーバの起動

<title>Starting the Server</title>

To start the server, waiting until the server is accepting connections: 以下はサーバが接続を植え付けられるようになるまで待機する起動例です。

$ pg_ctl start

To start the server using port 5433, and running without <function>fsync</function>, use: ポート5433を使いfsyncなしでサーバを起動します。

$ pg_ctl -o "-F -p 5433" start

サーバの停止

<title>Stopping the Server</title>

To stop the server, use: サーバを停止するためには以下を使用します。

$ pg_ctl stop

The <option>-m</option> option allows control over <emphasis>how</emphasis> the server shuts down: -mオプションによりどのようにバックエンドを停止させるかを制御できます。

$ pg_ctl stop -m smart

サーバの再起動

<title>Restarting the Server</title>

Restarting the server is almost equivalent to stopping the server and starting it again, except that by default, <command>pg_ctl</command> saves and reuses the command line options that were passed to the previously-running instance. To restart the server using the same options as before, use: サーバの再起動は、サーバを停止してもう一度起動するのとほぼ同じですが、違うのは、pg_ctlがデフォルトでは以前起動していたインスタンスに渡されていたコマンドラインオプションを保存し再利用することです。 下記はサーバを以前と同じオプションを使って再起動する方法です。

$ pg_ctl restart

But if <option>-o</option> is specified, that replaces any previous options. To restart using port 5433, disabling <function>fsync</function> upon restart: しかし、-oを指定すれば、それによって以前のオプションが置換されます。 以下はポート5433を使って再起動し、再起動後にfsyncを無効にする方法です。

$ pg_ctl -o "-F -p 5433" restart

サーバの状態表示

<title>Showing the Server Status</title>

Here is sample status output from <application>pg_ctl</application>: 下記はpg_ctlからの状態の出力の例です。

$ pg_ctl status

pg_ctl: server is running (PID: 13718)
/usr/local/pgsql/bin/postgres "-D" "/usr/local/pgsql/data" "-p" "5433" "-B" "128"

The second line is the command that would be invoked in restart mode. 2行目は再起動(restart)モードで呼び出されるコマンドラインです。

関連項目

<title>See Also</title> initdb, postgres