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

F.37. pg_walinspect — 低レベルのWAL検査 #

<title>pg_walinspect &mdash; low-level WAL inspection</title>

The <filename>pg_walinspect</filename> module provides SQL functions that allow you to inspect the contents of write-ahead log of a running <productname>PostgreSQL</productname> database cluster at a low level, which is useful for debugging, analytical, reporting or educational purposes. It is similar to <xref linkend="pgwaldump"/>, but accessible through SQL rather than a separate utility. pg_walinspectモジュールは、実行中のPostgreSQLデータベースクラスタの先行書き込みログの内容を低レベルで検査することを可能にするSQL関数を提供します。 これはデバッグ、分析、報告、教育目的に有用です。 pg_waldumpと似ていますが、独立したユーティリティではなくSQLを通してアクセスできます。

All the functions of this module will provide the WAL information using the server's current timeline ID. このモジュールのすべての関数は、サーバの現在のタイムラインIDを使用してWAL情報を提供します。

注記

The <filename>pg_walinspect</filename> functions are often called using an LSN argument that specifies the location at which a known WAL record of interest <emphasis>begins</emphasis>. However, some functions, such as <function><link linkend="pg-logical-emit-message">pg_logical_emit_message</link></function>, return the LSN <emphasis>after</emphasis> the record that was just inserted. pg_walinspect関数は、しばしば、関心のある既知のWALレコードの開始位置を指定するLSN引数を使用して呼び出されます。 しかし、pg_logical_emit_messageのようないくつかの関数は、挿入されたレコードののLSNを返します。

ヒント

All of the <filename>pg_walinspect</filename> functions that show information about records that fall within a certain LSN range are permissive about accepting <replaceable>end_lsn</replaceable> arguments that are after the server's current LSN. Using an <replaceable>end_lsn</replaceable> <quote>from the future</quote> will not raise an error. あるLSN範囲内にあるレコードに関する情報を表示するpg_walinspect関数はすべて、サーバの現在のLSNより後のend_lsn引数を受け入れることに対して寛容です。 未来のend_lsnを使用することはエラーを引き起こしません。

It may be convenient to provide the value <literal>FFFFFFFF/FFFFFFFF</literal> (the maximum valid <type>pg_lsn</type> value) as an <replaceable>end_lsn</replaceable> argument. This is equivalent to providing an <replaceable>end_lsn</replaceable> argument matching the server's current LSN. FFFFFFFF/FFFFFFFF(最大有効pg_lsn値)をend_lsn引数として指定すると便利です。 これは、サーバの現在のLSNに一致するend_lsn引数を指定することと同じです。

By default, use of these functions is restricted to superusers and members of the <literal>pg_read_server_files</literal> role. Access may be granted by superusers to others using <command>GRANT</command>. デフォルトでは、これらの関数の使用はスーパーユーザとpg_read_server_filesロールのメンバに制限されています。 スーパーユーザはGRANTを使用して他のユーザにアクセスを許可できます。

F.37.1. 一般的な関数 #

<title>General Functions</title>
pg_get_wal_record_info(in_lsn pg_lsn) returns record #

Gets WAL record information about a record that is located at or after the <replaceable>in_lsn</replaceable> argument. For example: in_lsn引数以降のレコードに関するWALレコード情報を取得します。 例を示します。

postgres=# SELECT * FROM pg_get_wal_record_info('0/E419E28');
-[ RECORD 1 ]----+-------------------------------------------------
start_lsn        | 0/E419E28
end_lsn          | 0/E419E68
prev_lsn         | 0/E419D78
xid              | 0
resource_manager | Heap2
record_type      | VACUUM
record_length    | 58
main_data_length | 2
fpi_length       | 0
description      | nunused: 5, unused: [1, 2, 3, 4, 5]
block_ref        | blkref #0: rel 1663/16385/1249 fork main blk 364

If <replaceable>in_lsn</replaceable> isn't at the start of a WAL record, information about the next valid WAL record is shown instead. If there is no next valid WAL record, the function raises an error. in_lsnがWALレコードの先頭にない場合、次の有効なWALレコードに関する情報が代わりに表示されます。 次の有効なWALレコードがない場合、関数はエラーを発生します。

pg_get_wal_records_info(start_lsn pg_lsn, end_lsn pg_lsn) returns setof record #

Gets information of all the valid WAL records between <replaceable>start_lsn</replaceable> and <replaceable>end_lsn</replaceable>. Returns one row per WAL record. For example: start_lsnend_lsnの間のすべての有効なWALレコードの情報を取得します。 WALレコードごとに1つの行が返されます。 例を示します。

postgres=# SELECT * FROM pg_get_wal_records_info('0/1E913618', '0/1E913740') LIMIT 1;
-[ RECORD 1 ]----+--------------------------------------------------------------
start_lsn        | 0/1E913618
end_lsn          | 0/1E913650
prev_lsn         | 0/1E9135A0
xid              | 0
resource_manager | Standby
record_type      | RUNNING_XACTS
record_length    | 50
main_data_length | 24
fpi_length       | 0
description      | nextXid 33775 latestCompletedXid 33774 oldestRunningXid 33775
block_ref        |

The function raises an error if <replaceable>start_lsn</replaceable> is not available. start_lsnが利用できない場合、この関数はエラーを発生します。

pg_get_wal_block_info(start_lsn pg_lsn, end_lsn pg_lsn, show_data boolean DEFAULT true) returns setof record pg_get_wal_records_info_till_end_of_wal(start_lsn pg_lsn) returns setof record #

Gets information about each block reference from all the valid WAL records between <replaceable>start_lsn</replaceable> and <replaceable>end_lsn</replaceable> with one or more block references. Returns one row per block reference per WAL record. For example: start_lsnend_lsnの間のすべての有効なWALレコードから、1つ以上のブロック参照を持つすべてのブロック参照に関する情報を取得します。 WALレコードのブロック参照ごとに1行返します。 例を示します。

postgres=# SELECT * FROM pg_get_wal_block_info('0/1230278', '0/12302B8');
-[ RECORD 1 ]-----+-----------------------------------
start_lsn         | 0/1230278
end_lsn           | 0/12302B8
prev_lsn          | 0/122FD40
block_id          | 0
reltablespace     | 1663
reldatabase       | 1
relfilenode       | 2658
relforknumber     | 0
relblocknumber    | 11
xid               | 341
resource_manager  | Btree
record_type       | INSERT_LEAF
record_length     | 64
main_data_length  | 2
block_data_length | 16
block_fpi_length  | 0
block_fpi_info    |
description       | off: 46
block_data        | \x00002a00070010402630000070696400
block_fpi_data    |

This example involves a WAL record that only contains one block reference, but many WAL records contain several block references. Rows output by <function>pg_get_wal_block_info</function> are guaranteed to have a unique combination of <replaceable>start_lsn</replaceable> and <replaceable>block_id</replaceable> values. この例は、1つのブロック参照のみを含むWALレコードを含んでいますが、多くのWALレコードには複数のブロック参照が含まれています。 pg_get_wal_block_infoによって出力される行は、一意のstart_lsnblock_id値の組み合わせを持つことが保証されています。

Much of the information shown here matches the output that <function>pg_get_wal_records_info</function> would show, given the same arguments. However, <function>pg_get_wal_block_info</function> unnests the information from each WAL record into an expanded form by outputting one row per block reference, so certain details are tracked at the block reference level rather than at the whole-record level. This structure is useful with queries that track how individual blocks changed over time. Note that records with no block references (e.g., <literal>COMMIT</literal> WAL records) will have no rows returned, so <function>pg_get_wal_block_info</function> may actually return <emphasis>fewer</emphasis> rows than <function>pg_get_wal_records_info</function>. ここに示す情報の多くは、pg_get_wal_records_infoに同じ引数を与えた場合に出力される出力と一致します。 しかし、pg_get_wal_block_infoは、各WALレコードをブロック参照ごとに展開した形式で情報を展開するため、ブロック参照レベルでは全体のレコードよりも多くの行が出力されます。 この構造は、個々のブロックが時間の経過とともにどのように変化したかを追跡する問い合わせで役立ちます。 ブロック参照を持たないレコード(例えば、COMMITWALレコード)は行を返さないので、pg_get_wal_block_infoは実際にはpg_get_wal_records_infoよりも少ない行を返すかもしれません。

The <structfield>reltablespace</structfield>, <structfield>reldatabase</structfield>, and <structfield>relfilenode</structfield> parameters reference <link linkend="catalog-pg-tablespace"><structname>pg_tablespace</structname></link>.<structfield>oid</structfield>, <link linkend="catalog-pg-database"><structname>pg_database</structname></link>.<structfield>oid</structfield>, and <link linkend="catalog-pg-class"><structname>pg_class</structname></link>.<structfield>relfilenode</structfield> respectively. The <structfield>relforknumber</structfield> field is the fork number within the relation for the block reference; see <filename>common/relpath.h</filename> for details. reltablespacereldatabaserelfilenodeパラメータは、pg_tablespace.oidpg_database.oidpg_class.oidpg_class.relfilenodeを参照します。 relforknumberは、ブロック参照のリレーション内のフォーク番号です。 詳細はcommon/relpath.hを参照してください。

ヒント

The <function>pg_filenode_relation</function> function (see <xref linkend="functions-admin-dblocation"/>) can help you to determine which relation was modified during original execution pg_filenode_relation関数(表 9.97を参照)は、元の実行中にどのリレーションが変更されたかを判断するのに役立ちます。

It is possible for clients to avoid the overhead of materializing block data. This may make function execution significantly faster. When <replaceable>show_data</replaceable> is set to <literal>false</literal>, <structfield>block_data</structfield> and <structfield>block_fpi_data</structfield> values are omitted (that is, the <structfield>block_data</structfield> and <structfield>block_fpi_data</structfield> <literal>OUT</literal> arguments are <literal>NULL</literal> for all rows returned). Obviously, this optimization is only feasible with queries where block data isn't truly required. クライアントは、ブロックデータの取り出しによるオーバーヘッドを回避することができます。 これにより、関数の実行が大幅に高速化されます。 show_datafalseに設定されている場合、block_datablock_fpi_dataの値は省略されます(つまり、返されたすべての行に対してblock_datablock_fpi_dataOUT引数はNULL)。 明らかに、この最適化はブロックデータが本当に必要でない問い合わせでのみ許されます。

The function raises an error if <replaceable>start_lsn</replaceable> is not available. start_lsnが利用できない場合、この関数はエラーを発生します。

pg_get_wal_stats(start_lsn pg_lsn, end_lsn pg_lsn, per_record boolean DEFAULT false) returns setof record #

Gets statistics of all the valid WAL records between <replaceable>start_lsn</replaceable> and <replaceable>end_lsn</replaceable>. By default, it returns one row per <replaceable>resource_manager</replaceable> type. When <replaceable>per_record</replaceable> is set to <literal>true</literal>, it returns one row per <replaceable>record_type</replaceable>. For example: start_lsnend_lsnの間のすべての有効なWALレコードの統計を取得します。 デフォルトでは、resource_manager型ごとに1つの行を返します。 per_recordtrueに設定されている場合、record_typeごとに1つの行を返します。 例を示します。

postgres=# SELECT * FROM pg_get_wal_stats('0/1E847D00', '0/1E84F500')
           WHERE count > 0 AND
                 "resource_manager/record_type" = 'Transaction'
           LIMIT 1;
-[ RECORD 1 ]----------------+-------------------
resource_manager/record_type | Transaction
count                        | 2
count_percentage             | 8
record_size                  | 875
record_size_percentage       | 41.23468426013195
fpi_size                     | 0
fpi_size_percentage          | 0
combined_size                | 875
combined_size_percentage     | 2.8634072910530795

The function raises an error if <replaceable>start_lsn</replaceable> is not available. start_lsnが利用できない場合、この関数はエラーを発生します。

F.37.2. 作者 #

<title>Author</title>

Bharath Rupireddy