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

pg_receivewal

pg_receivewal <refpurpose>stream write-ahead logs from a <productname>PostgreSQL</productname> server</refpurpose> PostgreSQLサーバから先行書き込みログをストリームする

概要

pg_receivewal [option...]

説明

<title>Description</title>

<application>pg_receivewal</application> is used to stream the write-ahead log from a running <productname>PostgreSQL</productname> cluster. The write-ahead log is streamed using the streaming replication protocol, and is written to a local directory of files. This directory can be used as the archive location for doing a restore using point-in-time recovery (see <xref linkend="continuous-archiving"/>). pg_receivewalは実行中のPostgreSQLクラスタから先行書き込みログをストリームするために使用されます。 先行書き込みログはストリーミングレプリケーションプロトコルを使用してストリームされ、ローカルディレクトリのファイルとして書き出されます。 このディレクトリはポイントインタイムリカバリ(26.3参照)を用いてリストアする際のアーカイブ場所として使用することができます。

<application>pg_receivewal</application> streams the write-ahead log in real time as it's being generated on the server, and does not wait for segments to complete like <xref linkend="guc-archive-command"/> and <xref linkend="guc-archive-library"/> do. For this reason, it is not necessary to set <xref linkend="guc-archive-timeout"/> when using <application>pg_receivewal</application>. pg_receivewalは、先行書き込みログをサーバでの生成に合わせてリアルタイムでストリームし、archive_commandarchive_libraryとは異なり、セグメントが完了するまで待機することはありません。 このため、pg_receivewalを使用する場合にはarchive_timeoutを設定する必要はありません。

Unlike the WAL receiver of a PostgreSQL standby server, <application>pg_receivewal</application> by default flushes WAL data only when a WAL file is closed. The option <option>&#45;-synchronous</option> must be specified to flush WAL data in real time. Since <application>pg_receivewal</application> does not apply WAL, you should not allow it to become a synchronous standby when <xref linkend="guc-synchronous-commit"/> equals <literal>remote_apply</literal>. If it does, it will appear to be a standby that never catches up, and will cause transaction commits to block. To avoid this, you should either configure an appropriate value for <xref linkend="guc-synchronous-standby-names"/>, or specify <varname>application_name</varname> for <application>pg_receivewal</application> that does not match it, or change the value of <varname>synchronous_commit</varname> to something other than <literal>remote_apply</literal>. PostgreSQLのスタンバイサーバのWALレシーバと異なり、pg_receivewalはデフォルトでは、WALファイルがクローズされた時にのみ、WALデータをフラッシュします。 WALデータをリアルタイムでフラッシュするには--synchronousオプションを指定する必要があります。 pg_receivewalはWALを適用しないので、synchronous_commitremote_applyのときにこれを同期スタンバイにすることはできません。 そのようにした場合、決してキャッチアップすることのないスタンバイになり、トランザクションコミットのブロックをひき起こします。 これを避けるには、synchronous_standby_namesに適切な値を設定するか、pg_receivewalに対して一致しないapplication_nameを指定する、あるいは、synchronous_commitの値をremote_apply以外の値に変更してください。

The write-ahead log is streamed over a regular <productname>PostgreSQL</productname> connection and uses the replication protocol. The connection must be made with a user having <literal>REPLICATION</literal> permissions (see <xref linkend="role-attributes"/>) or a superuser, and <filename>pg_hba.conf</filename> must permit the replication connection. The server must also be configured with <xref linkend="guc-max-wal-senders"/> set high enough to leave at least one session available for the stream. 先行書き込みログは通常のPostgreSQL接続を経由して、そしてレプリケーションプロトコルを使用して、ストリームされます。 この接続はREPLICATION権限(22.2参照)を持つユーザまたはスーパーユーザによって確立されなければなりません。 そしてpg_hba.confでレプリケーション用の接続を許可しなければなりません。 またサーバではストリーム用に利用できるセッションが少なくとも1つ存在できるためにmax_wal_sendersを十分大きく設定しなければなりません。

The starting point of the write-ahead log streaming is calculated when <application>pg_receivewal</application> starts: 先行書き込みログのストリーミングの開始点はpg_receivewalの開始時に以下のように計算されます。

  1. First, scan the directory where the WAL segment files are written and find the newest completed segment file, using as the starting point the beginning of the next WAL segment file. まず、WALセグメントファイルが書き込まれるディレクトリを走査して、最新の完了したセグメントファイルを見つけ、次のWALセグメントファイルの始まりを開始点として使います。

  2. If a starting point cannot be calculated with the previous method, and if a replication slot is used, an extra <command>READ_REPLICATION_SLOT</command> command is issued to retrieve the slot's <literal>restart_lsn</literal> to use as the starting point. This option is only available when streaming write-ahead logs from <productname>PostgreSQL</productname> 15 and up. 前の方法で開始点を計算できず、レプリケーションスロットが使用されている場合、追加のREAD_REPLICATION_SLOTコマンドを発行してスロットのrestart_lsnを取得し、開始点として使用します。 このオプションは、PostgreSQL 15以降から先行書き込みログをストリーミングする場合にのみ使用できます。

  3. If a starting point cannot be calculated with the previous method, the latest WAL flush location is used as reported by the server from an <literal>IDENTIFY_SYSTEM</literal> command. 開始点が前の方法で計算できなければ、サーバのIDENTIFY_SYSTEMコマンドで報告された最新のWALのフラッシュ位置が使われます。

If the connection is lost, or if it cannot be initially established, with a non-fatal error, <application>pg_receivewal</application> will retry the connection indefinitely, and reestablish streaming as soon as possible. To avoid this behavior, use the <literal>-n</literal> parameter. 接続が失われた場合、または、致命的ではないエラーで初期確立ができなかった場合、pg_receivewalは無期限に接続を再試行しできるだけ早くストリーミングを再確立します。 この動作を止めるためには-nパラメータを使用してください。

In the absence of fatal errors, <application>pg_receivewal</application> will run until terminated by the <systemitem>SIGINT</systemitem> (<keycombo action="simul"><keycap>Control</keycap><keycap>C</keycap></keycombo>) or <systemitem>SIGTERM</systemitem> signal. 致命的なエラーが無い場合、pg_receivewalSIGINTControl+C)またはSIGTERMシグナルで停止されるまで実行を続けます。

オプション

<title>Options</title>
-D directory
--directory=directory

Directory to write the output to. 出力を書き出すディレクトリです。

This parameter is required. このパラメータは必須です。

-E lsn
--endpos=lsn

Automatically stop replication and exit with normal exit status 0 when receiving reaches the specified LSN. 受信が指定したLSNに達したなら、自動的にレプリケーションを停止して、通常の終了ステータス0で終了します。

If there is a record with LSN exactly equal to <replaceable>lsn</replaceable>, the record will be processed. lsnとちょうど等しいLSNのレコードがある場合、そのレコードは処理されます。

--if-not-exists

Do not error out when <option>&#45;-create-slot</option> is specified and a slot with the specified name already exists. --create-slotが指定され、指定された名前のスロットが既に存在していた場合に、エラーを発生させません。

-n
--no-loop

Don't loop on connection errors. Instead, exit right away with an error. 接続エラー時に繰り返しません。 代わりにエラーですぐに終了します。

--no-sync

This option causes <command>pg_receivewal</command> to not force WAL data to be flushed to disk. This is faster, but means that a subsequent operating system crash can leave the WAL segments corrupt. Generally, this option is useful for testing but should not be used when doing WAL archiving on a production deployment. このオプションはpg_receivewalがWALデータをディスクに強制的にフラッシュさせないようにします。 これはより高速ですが、オペレーションシステムのクラッシュ後にWALセグメントが破損している可能性があります。 一般に、このオプションはテストには有益ですが、本番配備でWALのアーカイビングを行うときに使うべきではありません。

This option is incompatible with <literal>&#45;-synchronous</literal>. このオプションは--synchronousと両立しません。

-s interval
--status-interval=interval

Specifies the number of seconds between status packets sent back to the server. This allows for easier monitoring of the progress from server. A value of zero disables the periodic status updates completely, although an update will still be sent when requested by the server, to avoid timeout disconnect. The default value is 10 seconds. サーバに状態パケットを返答する間隔を秒単位で指定します。 これによりサーバからより簡単に進行状況を監視することができます。 ゼロという値は状態の定期的な更新を完全に無効にします。 しかしタイムアウトによる切断を防ぐために、サーバから要求された時には更新を送信します。 デフォルト値は10秒です。

-S slotname
--slot=slotname

Require <application>pg_receivewal</application> to use an existing replication slot (see <xref linkend="streaming-replication-slots"/>). When this option is used, <application>pg_receivewal</application> will report a flush position to the server, indicating when each segment has been synchronized to disk so that the server can remove that segment if it is not otherwise needed. pg_receivewalが既存のレプリケーションスロットを使うようにします(27.2.6を参照してください)。 このオプションが使われると、pg_receivewalはフラッシュ位置をサーバに報告します。 これは、各セグメントがいつディスクに同期されたかを示し、それによりサーバが必要のなくなったセグメントを削除できるようになります。

When the replication client of <application>pg_receivewal</application> is configured on the server as a synchronous standby, then using a replication slot will report the flush position to the server, but only when a WAL file is closed. Therefore, that configuration will cause transactions on the primary to wait for a long time and effectively not work satisfactorily. The option <literal>&#45;-synchronous</literal> (see below) must be specified in addition to make this work correctly. pg_receivewalのレプリケーションクライアントが同期スタンバイとしてサーバ上で構成されている場合、レプリケーションスロットを利用するとフラッシュ位置がサーバに報告されますが、それはWALファイルがクローズされる時のみです。 したがって、その構成ではプライマリ上のトランザクションが長時間待たされることになり、結果的に満足する動作を得られません。 これを正しく動作させるには、追加で--synchronousオプション(以下を参照)を指定する必要があります。

--synchronous

Flush the WAL data to disk immediately after it has been received. Also send a status packet back to the server immediately after flushing, regardless of <literal>&#45;-status-interval</literal>. WALデータを受け取ると即座にディスクにフラッシュします。 またフラッシュした直後に、--status-intervalの値が何であれ、ステータスパケットをサーバに送り返します。

This option should be specified if the replication client of <application>pg_receivewal</application> is configured on the server as a synchronous standby, to ensure that timely feedback is sent to the server. pg_receivewalのレプリケーションクライアントが同期スタンバイとしてサーバ上で構成されている場合、フィードバックが遅延なくサーバに送り返されることを確実にするため、このオプションを指定すべきです。

-v
--verbose

Enables verbose mode. 冗長モードを有効にします。

-Z level
-Z method[:detail]
--compress=level
--compress=method[:detail]

Enables compression of write-ahead logs. 先行書き込みログの圧縮を有効にします。

The compression method can be set to <literal>gzip</literal>, <literal>lz4</literal> (if <productname>PostgreSQL</productname> was compiled with <option>&#45;-with-lz4</option>) or <literal>none</literal> for no compression. A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form <literal>keyword</literal> or <literal>keyword=value</literal>. Currently, the only supported keyword is <literal>level</literal>. 圧縮の手法はgzip、(PostgreSQL--with-lz4でコンパイルされた場合)lz4に設定できます。非圧縮の場合はnoneです。 圧縮の詳細文字列はオプションで指定できます。 詳細文字列が整数の場合は、圧縮レベルを指定します。 それ以外の場合は、keywordまたはkeyword=valueの形式のカンマで区切られた項目リストにします。 現在サポートされているキーワードはlevelのみです。

If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, <literal>gzip</literal> compression will be used if the level is greater than 0, and no compression will be used if the level is 0. 圧縮レベルが指定されていない場合、デフォルトの圧縮レベルが使用されます。 アルゴリズムを指定せずにレベルのみが指定されている場合、レベルが0より大きい場合はgzip圧縮が使用され、レベルが0の場合は圧縮が使用されません。

The suffix <filename>.gz</filename> will automatically be added to all filenames when using <literal>gzip</literal>, and the suffix <filename>.lz4</filename> is added when using <literal>lz4</literal>. gzipを使用している場合は、すべてのファイル名に自動的に接尾辞.gzが追加されます。lz4を使用している場合は、接尾辞.lz4が追加されます。

The following command-line options control the database connection parameters. 以下のコマンドラインオプションはデータベース接続パラメータを制御します。

-d connstr
--dbname=connstr

Specifies parameters used to connect to the server, as a <link linkend="libpq-connstring">connection string</link>; these will override any conflicting command line options. サーバに接続するために使用するパラメータを、接続文字列として指定します。 これは衝突するコマンドラインオプションよりも優先します。

The option is called <literal>&#45;-dbname</literal> for consistency with other client applications, but because <application>pg_receivewal</application> doesn't connect to any particular database in the cluster, database name in the connection string will be ignored. このオプションは他のクライアントアプリケーションとの整合性のために--dbnameと呼ばれます。 しかし、pg_receivewalはクラスタ内のどの特定のデータベースにも接続しませんので、接続文字列内のデータベース名は無視されます。

-h host
--host=host

Specifies the host name of the machine on which the server is running. If the value begins with a slash, it is used as the directory for the Unix domain socket. The default is taken from the <envar>PGHOST</envar> environment variable, if set, else a Unix domain socket connection is attempted. サーバが稼働しているマシンのホスト名を指定します。 名前がスラッシュから始まる場合、Unixドメインソケット用のディレクトリとして使用されます。 デフォルトは環境変数PGHOSTが設定されていればその値から取られ、設定されていない場合はUnixドメインソケット接続が試行されます。

-p port
--port=port

Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to the <envar>PGPORT</envar> environment variable, if set, or a compiled-in default. サーバが接続を待ち受けるTCPポートまたはUnixドメインソケットファイルの拡張子を指定します。 デフォルトは環境変数PGPORTが指定されていればその値から取られ、設定されていない場合はコンパイル時のデフォルト値から取られます。

-U username
--username=username

User name to connect as. 接続するユーザ名です。

-w
--no-password

Never issue a password prompt. If the server requires password authentication and a password is not available by other means such as a <filename>.pgpass</filename> file, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password. パスワード入力を促しません。 サーバがパスワード認証を必要とし、かつ、.pgpassファイルなど他の手段でパスワードが入手できない場合、接続試行は失敗します。 このオプションは、パスワードを入力するユーザが存在しないバッチジョブやスクリプトで有用になります。

-W
--password

Force <application>pg_receivewal</application> to prompt for a password before connecting to a database. pg_receivewalはデータベースに接続する前にパスワード入力を強制的に促します。

This option is never essential, since <application>pg_receivewal</application> will automatically prompt for a password if the server demands password authentication. However, <application>pg_receivewal</application> will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing <option>-W</option> to avoid the extra connection attempt. このオプションは重要ではありません。 pg_receivewalは、サーバがパスワード認証を要求した場合に自動的にパスワードを促すためです。 しかしpg_receivewalは、サーバがパスワードを要求するかどうかを確認するために接続試行を浪費します。 -Wと入力して無駄な接続試行を防止することが有意である場合があります。

<application>pg_receivewal</application> can perform one of the two following actions in order to control physical replication slots: pg_receivewalは物理的なレプリケーションスロットを制御するため、以下の2つの動作のうちの1つを実行できます。

--create-slot

Create a new physical replication slot with the name specified in <option>&#45;-slot</option>, then exit. --slotで指定された名前の新しい物理的なレプリケーションスロットを作成して終了します。

--drop-slot

Drop the replication slot with the name specified in <option>&#45;-slot</option>, then exit. --slotで指定された名前の物理的なレプリケーションスロットを削除して終了します。

Other options are also available: この他に以下のオプションも使用することができます。

-V
--version

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

-?
--help

Show help about <application>pg_receivewal</application> command line arguments, and exit. pg_receivewalコマンドライン引数についてのヘルプを表示し、終了します。

終了ステータス

<title>Exit Status</title>

<application>pg_receivewal</application> will exit with status 0 when terminated by the <systemitem>SIGINT</systemitem> or <systemitem>SIGTERM</systemitem> signal. (That is the normal way to end it. Hence it is not an error.) For fatal errors or other signals, the exit status will be nonzero. pg_receivewalSIGINTまたはSIGTERMシグナルで終了されたとき、ステータス0で終了します。 (これは止めるための通常の方法です。 そのためエラーではありません。) 致命的エラーや他のシグナルに対しては、終了ステータスは非ゼロになります。

環境

<title>Environment</title>

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

The environment variable <envar>PG_COLOR</envar> specifies whether to use color in diagnostic messages. Possible values are <literal>always</literal>, <literal>auto</literal> and <literal>never</literal>. 環境変数PG_COLORは診断メッセージで色を使うかどうかを指定します。 可能な値はalwaysautoneverです。

注釈

<title>Notes</title>

When using <application>pg_receivewal</application> instead of <xref linkend="guc-archive-command"/> or <xref linkend="guc-archive-library"/> as the main WAL backup method, it is strongly recommended to use replication slots. Otherwise, the server is free to recycle or remove write-ahead log files before they are backed up, because it does not have any information, either from <xref linkend="guc-archive-command"/> or <xref linkend="guc-archive-library"/> or the replication slots, about how far the WAL stream has been archived. Note, however, that a replication slot will fill up the server's disk space if the receiver does not keep up with fetching the WAL data. WALのバックアップのメインの方法として、archive_commandarchive_libraryの代わりにpg_receivewalを使用する場合、レプリケーションスロットを使用することを強く推奨します。 そうしなければ、サーバはarchive_commandarchive_library、レプリケーションスロットのいずれからもWALのストリームがどこまでアーカイブされているかの情報を得られないため、先行書き込みログファイルがバックアップされる前にそれを再利用または削除するかもしれないのです。 しかし、WALデータを受け取る側がそのフェッチに追いつけない場合、レプリケーションスロットがサーバのディスクスペースを一杯にしてしまうかもしれないことに注意してください。

<application>pg_receivewal</application> will preserve group permissions on the received WAL files if group permissions are enabled on the source cluster. pg_receivewalは、ソースクラスタでグループパーミッションが有効である場合、受け取ったWALファイルのグループパーミッションを維持します。

<title>Examples</title>

To stream the write-ahead log from the server at <literal>mydbserver</literal> and store it in the local directory <filename>/usr/local/pgsql/archive</filename>: 先行書き込みログをmydbserverにあるサーバからストリームし、それをローカルディレクトリ/usr/local/pgsql/archiveに格納します。

$ pg_receivewal -h mydbserver -D /usr/local/pgsql/archive

関連項目

<title>See Also</title> pg_basebackup