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

pg_resetwal

pg_resetwal <refpurpose>reset the write-ahead log and other control information of a <productname>PostgreSQL</productname> database cluster</refpurpose> PostgreSQLデータベースクラスタの先行書き込みログやその他の制御情報を初期化する

概要

pg_resetwal [ -f | --force ] [ -n | --dry-run ] [option...] [ -D | --pgdata ]datadir

説明

<title>Description</title>

<command>pg_resetwal</command> clears the write-ahead log (WAL) and optionally resets some other control information stored in the <filename>pg_control</filename> file. This function is sometimes needed if these files have become corrupted. It should be used only as a last resort, when the server will not start due to such corruption. pg_resetwalは、先行書き込みログ(WAL)を消去し、さらにオプションでpg_controlファイル内に保存された制御情報の一部を初期化します。 この機能は、これらのファイルが破損した場合に必要になることがあります。 このような破損などが原因でサーバを起動できない場合の最後の手段としてのみ、この機能を使用してください。

After running this command, it should be possible to start the server, but bear in mind that the database might contain inconsistent data due to partially-committed transactions. You should immediately dump your data, run <command>initdb</command>, and restore. After restore, check for inconsistencies and repair as needed. このコマンドを実行すると、サーバが開始できるようになるはずです。 ただし、不完全にコミットされたトランザクションが原因でデータベースのデータに矛盾が起こる可能性があることに注意してください。 コマンドの実行後は、ただちにデータをダンプし、initdbを実行し、リストアすべきです。 リストア後、矛盾がないか検査し、必要に応じて修復を行ってください。

This utility can only be run by the user who installed the server, because it requires read/write access to the data directory. For safety reasons, you must specify the data directory on the command line. <command>pg_resetwal</command> does not use the environment variable <envar>PGDATA</envar>. このユーティリティの実行にはデータディレクトリへの読み込み/書き込みアクセス権限が必要となるため、サーバをインストールしたユーザのみが実行できます。 安全のため、データディレクトリをコマンドラインで指定する必要があります。 pg_resetwalは、環境変数PGDATAを使用しません。

If <command>pg_resetwal</command> complains that it cannot determine valid data for <filename>pg_control</filename>, you can force it to proceed anyway by specifying the <option>-f</option> (force) option. In this case plausible values will be substituted for the missing data. Most of the fields can be expected to match, but manual assistance might be needed for the next OID, next transaction ID and epoch, next multitransaction ID and offset, and WAL starting location fields. These fields can be set using the options discussed below. If you are not able to determine correct values for all these fields, <option>-f</option> can still be used, but the recovered database must be treated with even more suspicion than usual: an immediate dump and restore is imperative. <emphasis>Do not</emphasis> execute any data-modifying operations in the database before you dump, as any such action is likely to make the corruption worse. pg_resetwalpg_controlに対する有効なデータを判別できない場合、-f(force,強制)オプションを指定すれば強制的に処理を進めることができます。 その場合、欠落したデータは無難な値で代用されます。 ほとんどのフィールドでは適切な値が使用されますが、次のOID、次のトランザクションIDとエポック時間、マルチトランザクションIDとそのオフセット、WAL開始位置の値については、手動の操作が必要な場合があります。 これらの値は下記で説明するオプションを使用して設定することができます。 すべてに対して正しい値を決定できない場合でも-fを使用することができますが、この場合は回復したデータベースを通常よりさらに注意深く検査する必要があります。 必ず、ただちにダンプおよびリストアを行ってください。 決して、ダンプを行う前にデータ変更などの操作を行ってはなりません。 そのような操作は、破損状態をさらに悪化させます。

オプション

<title>Options</title>
-f
--force

Force <command>pg_resetwal</command> to proceed even if it cannot determine valid data for <filename>pg_control</filename>, as explained above. 上で説明したように、pg_controlに有効なデータが確認できない場合でも、強制的にpg_resetwalの処理を実行します。

-n
--dry-run

The <option>-n</option>/<option>&#45;-dry-run</option> option instructs <command>pg_resetwal</command> to print the values reconstructed from <filename>pg_control</filename> and values about to be changed, and then exit without modifying anything. This is mainly a debugging tool, but can be useful as a sanity check before allowing <command>pg_resetwal</command> to proceed for real. -n/--dry-runオプションを指定すると、pg_resetwalpg_controlから再構築した値、および変更される値を出力して、何も変更せずに終了します。 これは主にデバッグと目的としたツールですが、pg_resetwalを実際に進める前の検査としても有用な場合があります。

-V
--version

バージョン情報を表示して終了します。

-?
--help

ヘルプを表示して終了します。

The following options are only needed when <command>pg_resetwal</command> is unable to determine appropriate values by reading <filename>pg_control</filename>. Safe values can be determined as described below. For values that take numeric arguments, hexadecimal values can be specified by using the prefix <literal>0x</literal>. 以下のオプションはpg_resetwalpg_controlを読んでも適切な値を決定できない場合にのみ必要になります。 安全な値は以下で説明するようにして決定できます。 数値を引数として取る値については、0xの接頭辞をつけることで16進数の値を指定できます。

-c xid,xid
--commit-timestamp-ids=xid,xid

Manually set the oldest and newest transaction IDs for which the commit time can be retrieved. コミットの時刻が取り出せる最古のトランザクションIDと最新のトランザクションIDを手作業で設定します。

A safe value for the oldest transaction ID for which the commit time can be retrieved (first part) can be determined by looking for the numerically smallest file name in the directory <filename>pg_commit_ts</filename> under the data directory. Conversely, a safe value for the newest transaction ID for which the commit time can be retrieved (second part) can be determined by looking for the numerically greatest file name in the same directory. The file names are in hexadecimal. コミット時刻が取り出せる最古のトランザクションIDとして安全な値(1番目の部分)はデータディレクトリの下のpg_commit_tsディレクトリの中で、数値的に最小のファイル名を探すことで決定できます。 逆に、コミット時刻が取り出せる最新のトランザクションIDとして安全な値(2番目の部分)は同じディレクトリの中で、数値的に最大のファイル名を探すことで決定できます。 ファイル名は16進数になっています。

-e xid_epoch
--epoch=xid_epoch

Manually set the next transaction ID's epoch. 次のトランザクションIDのエポック時間を手作業で設定します。

The transaction ID epoch is not actually stored anywhere in the database except in the field that is set by <command>pg_resetwal</command>, so any value will work so far as the database itself is concerned. You might need to adjust this value to ensure that replication systems such as <application>Slony-I</application> and <application>Skytools</application> work correctly &mdash; if so, an appropriate value should be obtainable from the state of the downstream replicated database. pg_resetwalで設定されるフィールドを除き、トランザクションIDのエポック時間は実際にはデータベース内のどこにも格納されません。 そのため、データベース自体だけを考えるのであれば、任意の値で動作するでしょう。 Slony-ISkytoolsなどのレプリケーションシステムが確実に正しく動作するように、この値を調整しなければならない可能性があります。 その場合、適切な値は下流で複製されたデータベースの状態から得られるはずです。

-l walfile
--next-wal-file=walfile

Manually set the WAL starting location by specifying the name of the next WAL segment file. 次のWALセグメントファイル名を指定することでWAL開始位置を手動で設定します。

The name of next WAL segment file should be larger than any WAL segment file name currently existing in the directory <filename>pg_wal</filename> under the data directory. These names are also in hexadecimal and have three parts. The first part is the <quote>timeline ID</quote> and should usually be kept the same. For example, if <filename>00000001000000320000004A</filename> is the largest entry in <filename>pg_wal</filename>, use <literal>-l 00000001000000320000004B</literal> or higher. 次のWALセグメントファイル名は、データディレクトリ以下のpg_walに現在存在するどのWALセグメントファイル名よりも大きくならなければなりません。 この名前も16進数で、3つの部分に分かれています。 最初の部分は時系列IDで、通常、この値は変更すべきではありません。 例えば、pg_wal内で最大のエントリが00000001000000320000004Aである場合は、-l 00000001000000320000004B以上を使用してください。

Note that when using nondefault WAL segment sizes, the numbers in the WAL file names are different from the LSNs that are reported by system functions and system views. This option takes a WAL file name, not an LSN. デフォルト以外のWALセグメントサイズを使用しているときには、WALファイル名の番号はシステム関数やシステムビューで報告されるLSNとは異なるということに注意してください。 このオプションはLSNではなくWALファイル名を引数に取ります。

注記

<command>pg_resetwal</command> itself looks at the files in <filename>pg_wal</filename> and chooses a default <option>-l</option> setting beyond the last existing file name. Therefore, manual adjustment of <option>-l</option> should only be needed if you are aware of WAL segment files that are not currently present in <filename>pg_wal</filename>, such as entries in an offline archive; or if the contents of <filename>pg_wal</filename> have been lost entirely. pg_resetwal自体はpg_wal内のファイルを参照し、最後の既存のファイル名より大きな値をデフォルトの-l設定として選択します。 したがって、手作業による-lの調整は、オフラインアーカイブ内の項目などpg_walに現存しないWALセグメントファイルがあることに気づいた場合、または、pg_walの内容が完全に失われている場合にのみ必要とされます。

-m mxid,mxid
--multixact-ids=mxid,mxid

Manually set the next and oldest multitransaction ID. 次のマルチトランザクションIDと最古のマルチトランザクションIDを手作業で設定します。

A safe value for the next multitransaction ID (first part) can be determined by looking for the numerically largest file name in the directory <filename>pg_multixact/offsets</filename> under the data directory, adding one, and then multiplying by 65536 (0x10000). Conversely, a safe value for the oldest multitransaction ID (second part of <option>-m</option>) can be determined by looking for the numerically smallest file name in the same directory and multiplying by 65536. The file names are in hexadecimal, so the easiest way to do this is to specify the option value in hexadecimal and append four zeroes. 次のマルチトランザクションIDとして安全な値(1番目の部分)は、データディレクトリの下のpg_multixact/offsetsディレクトリの中で数値的に最大のファイル名を探し、1を加えてから65536(0x10000)を掛けることで決定できます。 逆に、最古のマルチトランザクションIDとして安全な値(-mの2番目の部分)は、同じディレクトリの中で数値的に最小のファイル名を探し、65536を掛けることで決定できます。 ファイル名は16進ですので、このための最も簡単なやり方は、オプション値を16進で指定し、ゼロを4つ追加することです。

-o oid
--next-oid=oid

Manually set the next OID. 次のOIDを手作業で設定します。

There is no comparably easy way to determine a next OID that's beyond the largest one in the database, but fortunately it is not critical to get the next-OID setting right. データベース内のOIDの最大値よりも大きな次のOIDを決定するには、上記のような簡単な方法はありません。 しかし、幸いにも、次のOIDの設定を正しく取得することは、それほど重要ではありません。

-O mxoff
--multixact-offset=mxoff

Manually set the next multitransaction offset. 次のマルチトランザクションオフセットを手作業で設定します。

A safe value can be determined by looking for the numerically largest file name in the directory <filename>pg_multixact/members</filename> under the data directory, adding one, and then multiplying by 52352 (0xCC80). The file names are in hexadecimal. There is no simple recipe such as the ones for other options of appending zeroes. 安全な値は、データディレクトリの下のpg_multixact/membersディレクトリの中で数値的に最も大きなファイル名を探し、1を加えてから、52352(0xCC80)を掛けることで決定できます。 ファイル名は16進数です。 他のオプションのような0をつけるだけの簡単な計算方法はありません。

--wal-segsize=wal_segment_size

Set the new WAL segment size, in megabytes. The value must be set to a power of 2 between 1 and 1024 (megabytes). See the same option of <xref linkend="app-initdb"/> for more information. 新たなWALセグメントサイズをメガバイトで設定します。 値には1から1024(メガバイト)の2の冪乗を設定しなければなりません。 詳しくはinitdbの同じオプションを参照してください。

注記

While <command>pg_resetwal</command> will set the WAL starting address beyond the latest existing WAL segment file, some segment size changes can cause previous WAL file names to be reused. It is recommended to use <option>-l</option> together with this option to manually set the WAL starting address if WAL file name overlap will cause problems with your archiving strategy. pg_resetwalが存在する最も新しいWALセグメントファイルを超えたWAL開始位置を設定するとき、一部のセグメントサイズ変更は前のWALファイル名の再使用をひき起こす可能性があります。 あなたのアーカイブ戦略でWALファイル名のオーバーラップが問題を起こす場合には、このオプションと共にWAL開始位置を手動で設定する-lも使うことを推奨します。

-u xid
--oldest-transaction-id=xid

Manually set the oldest unfrozen transaction ID. 最も古い凍結されていないトランザクションIDを手作業で設定します。

A safe value can be determined by looking for the numerically smallest file name in the directory <filename>pg_xact</filename> under the data directory and then multiplying by 1048576 (0x100000). Note that the file names are in hexadecimal. It is usually easiest to specify the option value in hexadecimal too. For example, if <filename>0007</filename> is the smallest entry in <filename>pg_xact</filename>, <literal>-u 0x700000</literal> will work (five trailing zeroes provide the proper multiplier). 安全な値は、データディレクトリの下のpg_xactディレクトリの中で数値的に最も小さなファイル名を探し、1048576(0x100000)を掛けることで決定できます。 ファイル名は16進数であることに注意してください。 通常は、オプションの値も16進数で指定するのが最も簡単でしょう。 例えば、0007pg_xactで最も小さなエントリであれば、-u 0x700000とすれば良いです(後ろにゼロを5つ付けると、正しく掛け算をしたことになります)。

-x xid
--next-transaction-id=xid

Manually set the next transaction ID. 次のトランザクションIDを手作業で設定します。

A safe value can be determined by looking for the numerically largest file name in the directory <filename>pg_xact</filename> under the data directory, adding one, and then multiplying by 1048576 (0x100000). Note that the file names are in hexadecimal. It is usually easiest to specify the option value in hexadecimal too. For example, if <filename>0011</filename> is the largest entry in <filename>pg_xact</filename>, <literal>-x 0x1200000</literal> will work (five trailing zeroes provide the proper multiplier). 安全な値は、データディレクトリの下のpg_xactディレクトリの中で数値的に最も大きなファイル名を探し、1を加えてから、1048576(0x100000)を掛けることで決定できます。 ファイル名は16進数であることに注意して下さい。 通常は、オプションの値も16進数で指定するのが最も簡単でしょう。 例えば、0011pg_xactで最も大きなエントリであれば、-x 0x1200000とすれば良いです(後ろにゼロを5つ付けると、正しく掛け算をしたことになります)。

環境

<title>Environment</title>
PG_COLOR

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

注釈

<title>Notes</title>

This command must not be used when the server is running. <command>pg_resetwal</command> will refuse to start up if it finds a server lock file in the data directory. If the server crashed then a lock file might have been left behind; in that case you can remove the lock file to allow <command>pg_resetwal</command> to run. But before you do so, make doubly certain that there is no server process still alive. このコマンドは、サーバの稼働中に使用してはいけません。 pg_resetwalは、データディレクトリにサーバのロックファイルがあると、実行されません。 サーバがクラッシュした場合、ロックファイルがそのまま残される場合があります。 その場合は、ロックファイルを削除すればpg_resetwalを実行することができます。 しかし、そのようなことをする前に、まだ稼働中のサーバプロセスが一切ないことを慎重に確認してください。

<command>pg_resetwal</command> works only with servers of the same major version. pg_resetwalは同一のメジャーバージョンのサーバに対してのみ動作します。

関連項目

<title>See Also</title> pg_controldata