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

第65章 汎用WALレコード

<title>Generic WAL Records</title>

Although all built-in WAL-logged modules have their own types of WAL records, there is also a generic WAL record type, which describes changes to pages in a generic way. This is useful for extensions that provide custom access methods. 組み込みのWALにログを書き込むすべてのモジュールは、それぞれに独自の型のWALレコードがありますが、ページへの変更を汎用的な方法で記述する汎用WALレコード型もあります。 これは、カスタムアクセスメソッドを提供する拡張に役立ちます。

In comparison with <link linkend="custom-rmgr">Custom WAL Resource Managers</link>, Generic WAL is simpler for an extension to implement and does not require the extension library to be loaded in order to apply the records. カスタムWALリソースマネージャと比較すると、汎用WALは拡張の実装が簡単であり、レコードを適用するために拡張ライブラリをロードする必要がありません。

注記

Generic WAL records are ignored during <link linkend="logicaldecoding">Logical Decoding</link>. If logical decoding is required for your extension, consider a Custom WAL Resource Manager. 汎用WALレコードはロジカルデコーディング時に無視されます。 拡張にロジカルデコーディングが必要な場合は、カスタムWALリソースマネージャを検討してください。

The API for constructing generic WAL records is defined in <filename>access/generic_xlog.h</filename> and implemented in <filename>access/transam/generic_xlog.c</filename>. 汎用WALレコードを構築するためのAPIはaccess/generic_xlog.hに定義されており、access/transam/generic_xlog.cで実装されています。

To perform a WAL-logged data update using the generic WAL record facility, follow these steps: 汎用WALレコードの機能を使ってWAL書き込みを伴うデータ更新を行うには、以下の手順に従ってください。

  1. <function>state = GenericXLogStart(relation)</function> &mdash; start construction of a generic WAL record for the given relation. state = GenericXLogStart(relation) により、指定のリレーションについての汎用WALレコードの構築を開始します。

  2. <function>page = GenericXLogRegisterBuffer(state, buffer, flags)</function> &mdash; register a buffer to be modified within the current generic WAL record. This function returns a pointer to a temporary copy of the buffer's page, where modifications should be made. (Do not modify the buffer's contents directly.) The third argument is a bit mask of flags applicable to the operation. Currently the only such flag is <literal>GENERIC_XLOG_FULL_IMAGE</literal>, which indicates that a full-page image rather than a delta update should be included in the WAL record. Typically this flag would be set if the page is new or has been rewritten completely. <function>GenericXLogRegisterBuffer</function> can be repeated if the WAL-logged action needs to modify multiple pages. page = GenericXLogRegisterBuffer(state, buffer, flags) により、現在の汎用WALレコード内で更新されるバッファを登録します。 この関数はバッファページの一時コピーへのポインタを返すので、更新はそれに対して行ってください。 (バッファの内容は直接更新しないでください。) 3番目の引数は、操作についてのフラグのビットマスクです。 現在のところ、使用できるフラグはGENERIC_XLOG_FULL_IMAGEのみで、これはWALレコードには変更の差分ではなく、ページ全体のイメージが含まれることを示します。 典型的には、このフラグはページが新しいか、あるいは完全に書き換えられるときにセットされます。 WAL書き込み対象の動作が複数のページを更新する必要がある場合は、GenericXLogRegisterBufferを繰り返すことができます。

  3. Apply modifications to the page images obtained in the previous step. 前の手順で取得したページのイメージに更新を適用する。

  4. <function>GenericXLogFinish(state)</function> &mdash; apply the changes to the buffers and emit the generic WAL record. GenericXLogFinish(state)により、バッファの変更を適用し、汎用WALレコードを送出する。

WAL record construction can be canceled between any of the above steps by calling <function>GenericXLogAbort(state)</function>. This will discard all changes to the page image copies. WALレコードの構築は、上記の手順内の間のどこででも、GenericXLogAbort(state)を呼び出すことで中止できます。 これによりページイメージのコピーに対する変更はすべて廃棄されます。

Please note the following points when using the generic WAL record facility: 汎用WALレコードの機能を使うときは、以下の点に注意してください。