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

49.6. ロジカルデコーディングの出力プラグイン #

<title>Logical Decoding Output Plugins</title>

An example output plugin can be found in the <link linkend="test-decoding"> <filename>contrib/test_decoding</filename> </link> subdirectory of the PostgreSQL source tree. PostgreSQLのソースコードのサブディレクトリ contrib/test_decoding にサンプル出力プラグインがあります。

49.6.1. 初期化関数 #

<title>Initialization Function</title>

An output plugin is loaded by dynamically loading a shared library with the output plugin's name as the library base name. The normal library search path is used to locate the library. To provide the required output plugin callbacks and to indicate that the library is actually an output plugin it needs to provide a function named <function>_PG_output_plugin_init</function>. This function is passed a struct that needs to be filled with the callback function pointers for individual actions. 出力プラグインは、出力プラグインの名前をライブラリのベース名として持つ共有ライブラリを動的にロードすることによってロードされます。 必要な出力プラグインコールバックを提供し、そのライブラリが実際に出力プラグインであることを示すために、_PG_output_plugin_initという名前の関数を作成しなければなりません。 この関数には、各々のアクションに対応するコールバック関数へのポインタを持つ構造体が渡されます。

typedef struct OutputPluginCallbacks
{
    LogicalDecodeStartupCB startup_cb;
    LogicalDecodeBeginCB begin_cb;
    LogicalDecodeChangeCB change_cb;
    LogicalDecodeTruncateCB truncate_cb;
    LogicalDecodeCommitCB commit_cb;
    LogicalDecodeMessageCB message_cb;
    LogicalDecodeFilterByOriginCB filter_by_origin_cb;
    LogicalDecodeShutdownCB shutdown_cb;
    LogicalDecodeFilterPrepareCB filter_prepare_cb;
    LogicalDecodeBeginPrepareCB begin_prepare_cb;
    LogicalDecodePrepareCB prepare_cb;
    LogicalDecodeCommitPreparedCB commit_prepared_cb;
    LogicalDecodeRollbackPreparedCB rollback_prepared_cb;
    LogicalDecodeStreamStartCB stream_start_cb;
    LogicalDecodeStreamStopCB stream_stop_cb;
    LogicalDecodeStreamAbortCB stream_abort_cb;
    LogicalDecodeStreamPrepareCB stream_prepare_cb;
    LogicalDecodeStreamCommitCB stream_commit_cb;
    LogicalDecodeStreamChangeCB stream_change_cb;
    LogicalDecodeStreamMessageCB stream_message_cb;
    LogicalDecodeStreamTruncateCB stream_truncate_cb;
} OutputPluginCallbacks;

typedef void (*LogicalOutputPluginInit) (struct OutputPluginCallbacks *cb);

The <function>begin_cb</function>, <function>change_cb</function> and <function>commit_cb</function> callbacks are required, while <function>startup_cb</function>, <function>truncate_cb</function>, <function>message_cb</function>, <function>filter_by_origin_cb</function>, and <function>shutdown_cb</function> are optional. If <function>truncate_cb</function> is not set but a <command>TRUNCATE</command> is to be decoded, the action will be ignored. 《マッチ度[]》コールバック関数のbegin_cbchange_cb、および、commit_cbは必須ですが、startup_cbfilter_by_origin_cbtruncate_cb、および、shutdown_cbは必須ではありません。 truncate_cbが設定されていないけれども、TRUNCATEがデコードされることになった場合、この動作は無視されます。 《機械翻訳》begin_cbchange_cbのコールバックは必須ですが、startup_cbtruncate_cbmessage_cbfilter_by_origin_cbshutdown_cbはオプションです。 truncate_cbが設定されていないが、TRUNCATEをデコードする場合、アクションは無視されます。

An output plugin may also define functions to support streaming of large, in-progress transactions. The <function>stream_start_cb</function>, <function>stream_stop_cb</function>, <function>stream_abort_cb</function>, <function>stream_commit_cb</function>, and <function>stream_change_cb</function> are required, while <function>stream_message_cb</function> and <function>stream_truncate_cb</function> are optional. The <function>stream_prepare_cb</function> is also required if the output plugin also support two-phase commits. 《マッチ度[71.157495]》出力プラグインは、大きな継続中(in-progress)トランザクションのストリーミングをサポートする関数を定義することもできます。 stream_start_cbstream_stop_cbstream_abort_cbstream_commit_cbstream_change_cbstream_prepare_cbは必須ですが、stream_message_cbstream_truncate_cbは必須ではありません。 《機械翻訳》出力プラグインは、大きな進行中のトランザクションのストリーミングをサポートする関数も定義できます。 stream_start_cbstream_stop_cbstream_abort_cbstream_commit_cbstream_change_cbは必須ですが、stream_message_cbstream_truncate_cbはオプションです。 出力プラグインが2フェーズコミットもサポートする場合は、stream_prepare_cbも必要です。

An output plugin may also define functions to support two-phase commits, which allows actions to be decoded on the <command>PREPARE TRANSACTION</command>. The <function>begin_prepare_cb</function>, <function>prepare_cb</function>, <function>commit_prepared_cb</function> and <function>rollback_prepared_cb</function> callbacks are required, while <function>filter_prepare_cb</function> is optional. The <function>stream_prepare_cb</function> is also required if the output plugin also supports the streaming of large in-progress transactions. 《マッチ度[65.129151]》出力プラグインは、PREPARE TRANSACTIONでアクションをデコードできるようにする2相コミットをサポートする関数を定義することもできます。 begin_prepare_cbprepare_cbstream_prepare_cbcommit_prepared_cbrollback_prepared_cbコールバックは必須ですが、filter_prepare_cbは必須ではありません。 《機械翻訳》出力プラグインは、2フェーズコミットをサポートする関数を定義することもできます。 これにより、PREPARE TRANSACTIONでアクションをデコードできます。 begin_prepare_cbprepare_cbcommit_prepared_cbrollback_prepared_cbコールバックが必須です。 また、filter_prepare_cbもオプションです。 出力プラグインが大きな進行中のトランザクションのストリーミングもサポートしている場合は、stream_prepare_cbも必須です。

49.6.2. 機能 #

<title>Capabilities</title>

To decode, format and output changes, output plugins can use most of the backend's normal infrastructure, including calling output functions. Read only access to relations is permitted as long as only relations are accessed that either have been created by <command>initdb</command> in the <literal>pg_catalog</literal> schema, or have been marked as user provided catalog tables using 更新データをデコード、整形、出力するために、出力関数を呼び出すことを含め、出力プラグインはバックエンドの通常のインフラストラクチャのほとんどを利用できます。 テーブルは、initdbで作られ、pg_catalogスキーマに含まれているか、以下のコマンドでユーザ定義のカタログテーブルであると印が付けられている限り、読み込み専用のアクセスが許可されます。

ALTER TABLE user_catalog_table SET (user_catalog_table = true);
CREATE TABLE another_catalog_table(data text) WITH (user_catalog_table = true);

Note that access to user catalog tables or regular system catalog tables in the output plugins has to be done via the <literal>systable_*</literal> scan APIs only. Access via the <literal>heap_*</literal> scan APIs will error out. Additionally, any actions leading to transaction ID assignment are prohibited. That, among others, includes writing to tables, performing DDL changes, and calling <literal>pg_current_xact_id()</literal>. 出力プラグイン内のユーザカタログテーブルまたは通常のシステムカタログテーブルへのアクセスは、systable_*スキャンAPIを介してのみ行う必要があることに注意してください。 heap_*スキャンAPIを介したアクセスはエラーになります。 さらに、トランザクションIDの割り当てにつながるアクションは禁止されています。 これには、テーブルへの書き込み、DDL変更の実行、pg_current_xact_id()の呼び出しなどが含まれます。

49.6.3. 出力モード #

<title>Output Modes</title>

Output plugin callbacks can pass data to the consumer in nearly arbitrary formats. For some use cases, like viewing the changes via SQL, returning data in a data type that can contain arbitrary data (e.g., <type>bytea</type>) is cumbersome. If the output plugin only outputs textual data in the server's encoding, it can declare that by setting <literal>OutputPluginOptions.output_type</literal> to <literal>OUTPUT_PLUGIN_TEXTUAL_OUTPUT</literal> instead of <literal>OUTPUT_PLUGIN_BINARY_OUTPUT</literal> in the <link linkend="logicaldecoding-output-plugin-startup">startup callback</link>. In that case, all the data has to be in the server's encoding so that a <type>text</type> datum can contain it. This is checked in assertion-enabled builds. 出力プラグインコールバックは、かなり自由な形式で消費者にデータを渡すことができます。 SQLで変更データを見るような場合、任意のかたちでデータを返すことのできるデータ型(たとえばbytea)は扱いにくいです。 出力プラグインがサーバエンコーディングのテキストデータのみを含むことにするには、起動コールバックで、OutputPluginOptions.output_typeOUTPUT_PLUGIN_BINARY_OUTPUTではなく、OUTPUT_PLUGIN_TEXTUAL_OUTPUTを設定することによって宣言できます。 この場合、textdatumが格納することができるように、すべてのデータはサーバエンコーディングでエンコードされていなければなりません。

49.6.4. 出力プラグインコールバック #

<title>Output Plugin Callbacks</title>

An output plugin gets notified about changes that are happening via various callbacks it needs to provide. 出力プラグインには、必要に応じて発生した更新に関する通知が様々なコールバックを通じて送られます。

Concurrent transactions are decoded in commit order, and only changes belonging to a specific transaction are decoded between the <literal>begin</literal> and <literal>commit</literal> callbacks. Transactions that were rolled back explicitly or implicitly never get decoded. Successful savepoints are folded into the transaction containing them in the order they were executed within that transaction. A transaction that is prepared for a two-phase commit using <command>PREPARE TRANSACTION</command> will also be decoded if the output plugin callbacks needed for decoding them are provided. It is possible that the current prepared transaction which is being decoded is aborted concurrently via a <command>ROLLBACK PREPARED</command> command. In that case, the logical decoding of this transaction will be aborted too. All the changes of such a transaction are skipped once the abort is detected and the <function>prepare_cb</function> callback is invoked. Thus even in case of a concurrent abort, enough information is provided to the output plugin for it to properly deal with <command>ROLLBACK PREPARED</command> once that is decoded. 同時に実行されたトランザクションは、コミットした順番にデコードされます。 指定したトランザクションに含まれる更新だけがbegincommitの間のコールバックによってデコードされます。 明示的あるいは暗黙的にロールバックされたトランザクションは、決してデコードされません。 成功したセーブポイントは、実行された順番にセーブポイントが実行されたトランザクションの中に折り込まれます。 PREPARE TRANSACTIONを使用して2相コミット用に準備されたトランザクションも、デコードに必要な出力プラグインコールバックが提供されていればデコードされます。 ROLLBACK PREPAREDコマンドを使用して、現在準備されているトランザクションが同時にアボートされる可能性があります。 その場合、このトランザクションのロジカルデコーディングもアボートされます。 そのようなトランザクションのすべての変更は、アボートが検出され、prepare_cbコールバックが呼び出されるとスキップされます。 このように、同時にアボートされた場合でも、デコードされたROLLBACK PREPAREDを適切に処理するために十分な情報が出力プラグインに提供されます。

注記

Only transactions that have already safely been flushed to disk will be decoded. That can lead to a <command>COMMIT</command> not immediately being decoded in a directly following <literal>pg_logical_slot_get_changes()</literal> when <varname>synchronous_commit</varname> is set to <literal>off</literal>. ディスクに安全にフラッシュされたトランザクションだけがデコードされます。 そのため、synchronous_commitoffの場合には、直後に呼び出されたpg_logical_slot_get_changes()がそのCOMMITをデコードしないことがあります。

49.6.4.1. 開始コールバック #

<title>Startup Callback</title>

The optional <function>startup_cb</function> callback is called whenever a replication slot is created or asked to stream changes, independent of the number of changes that are ready to be put out. ストリームに投入可能な更新の数に関係なく、レプリケーションスロットが作られるか、ストリームの変更がリクエストされた場合にオプションのstartup_cbコールバック呼び出されます。

typedef void (*LogicalDecodeStartupCB) (struct LogicalDecodingContext *ctx,
                                        OutputPluginOptions *options,
                                        bool is_init);

The <literal>is_init</literal> parameter will be true when the replication slot is being created and false otherwise. <parameter>options</parameter> points to a struct of options that output plugins can set: is_init パラメータは、レプリケーションスロットが作られる際にはtrue、それ以外ではfalseになります。 optionsは、出力プラグインが書き込む以下の構造体を指します。

typedef struct OutputPluginOptions
{
    OutputPluginOutputType output_type;
    bool        receive_rewrites;
} OutputPluginOptions;

<literal>output_type</literal> has to either be set to <literal>OUTPUT_PLUGIN_TEXTUAL_OUTPUT</literal> or <literal>OUTPUT_PLUGIN_BINARY_OUTPUT</literal>. See also <xref linkend="logicaldecoding-output-mode"/>. If <literal>receive_rewrites</literal> is true, the output plugin will also be called for changes made by heap rewrites during certain DDL operations. These are of interest to plugins that handle DDL replication, but they require special handling. output_typeOUTPUT_PLUGIN_TEXTUAL_OUTPUTOUTPUT_PLUGIN_BINARY_OUTPUTのどちらかです。 49.6.3も参照してください。 receive_rewritesが真なら、何らかDDL操作時のヒープ書き換えで生じた変更に対して、出力プラグインも呼ばれます。 これはDDLレプリケーションを処理するプラグインを対象としていますが、これらは特別な処理を必要とします。

The startup callback should validate the options present in <literal>ctx-&gt;output_plugin_options</literal>. If the output plugin needs to have a state, it can use <literal>ctx-&gt;output_plugin_private</literal> to store it. 開始コールバックでは、ctx->output_plugin_optionsで指定されるオプションを検証しましょう。 出力プラグインが状態を持つ必要がある場合には、ctx->output_plugin_privateを利用できます。

49.6.4.2. 終了コールバック #

<title>Shutdown Callback</title>

The optional <function>shutdown_cb</function> callback is called whenever a formerly active replication slot is not used anymore and can be used to deallocate resources private to the output plugin. The slot isn't necessarily being dropped, streaming is just being stopped. 以前アクティブだったレプリケーションスロットが使われなくなったら、いつでもshutdown_cbコールバックが呼び出され、出力プラグインのプライベートリソースが解放されます。 スロットは削除される必要はありません。単にストリームが停止します。

typedef void (*LogicalDecodeShutdownCB) (struct LogicalDecodingContext *ctx);

49.6.4.3. トランザクション開始コールバック #

<title>Transaction Begin Callback</title>

The required <function>begin_cb</function> callback is called whenever a start of a committed transaction has been decoded. Aborted transactions and their contents never get decoded. 必須であるbegin_cbコールバックは、コミットしたトランザクションの開始がデコードされる際に必ず呼び出されます。 アボートしたトランザクションとその内容は決してデコードされません。

typedef void (*LogicalDecodeBeginCB) (struct LogicalDecodingContext *ctx,
                                      ReorderBufferTXN *txn);

The <parameter>txn</parameter> parameter contains meta information about the transaction, like the time stamp at which it has been committed and its XID. txn引数は、コミット時のタイムスタンプやトランザクションIDなどのトランザクションに関するメタ情報を含みます。

49.6.4.4. トランザクション終了コールバック #

<title>Transaction End Callback</title>

The required <function>commit_cb</function> callback is called whenever a transaction commit has been decoded. The <function>change_cb</function> callbacks for all modified rows will have been called before this, if there have been any modified rows. 必須であるcommit_cbコールバックは、トランザクションのコミットがデコードされる際に必ず呼び出されます。 行が更新された場合は、それぞれの行に対してchange_cbコールバックが、commit_cbの前に呼び出されます。

typedef void (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,
                                       ReorderBufferTXN *txn,
                                       XLogRecPtr commit_lsn);

49.6.4.5. 更新コールバック #

<title>Change Callback</title>

The required <function>change_cb</function> callback is called for every individual row modification inside a transaction, may it be an <command>INSERT</command>, <command>UPDATE</command>, or <command>DELETE</command>. Even if the original command modified several rows at once the callback will be called individually for each row. The <function>change_cb</function> callback may access system or user catalog tables to aid in the process of outputting the row modification details. In case of decoding a prepared (but yet uncommitted) transaction or decoding of an uncommitted transaction, this change callback might also error out due to simultaneous rollback of this very same transaction. In that case, the logical decoding of this aborted transaction is stopped gracefully. トランザクション内のINSERTUPDATEDELETEの更新に対して、必須コールバックであるchange_cbが呼び出されます。 元の更新コマンドが複数の行を一度に更新する場合は、それぞれの行に対してこのコールバックが呼び出されます。 change_cbコールバックは、システムまたはユーザカタログテーブルにアクセスして、行変更の詳細を出力する処理を支援することができます。 準備された(まだコミットされていない)トランザクションをデコードする場合、またはコミットされていないトランザクションをデコードする場合、この変更コールバックは、まったく同じトランザクションが同時にロールバックされるためにエラーになることもあります。 この場合、このアボートされたトランザクションのロジカルデコーディングは正常に停止されます。

typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
                                       ReorderBufferTXN *txn,
                                       Relation relation,
                                       ReorderBufferChange *change);

The <parameter>ctx</parameter> and <parameter>txn</parameter> parameters have the same contents as for the <function>begin_cb</function> and <function>commit_cb</function> callbacks, but additionally the relation descriptor <parameter>relation</parameter> points to the relation the row belongs to and a struct <parameter>change</parameter> describing the row modification are passed in. ctxtxnは、begin_cbcommit_cbコールバックでは同じ内容になります。 これに加えてrelationは行が属するリレーションを指定し、行の変更を記述するchangeパラメータが渡されます。

注記

Only changes in user defined tables that are not unlogged (see <xref linkend="sql-createtable-unlogged"/>) and not temporary (see <xref linkend="sql-createtable-temporary"/>) can be extracted using logical decoding. unloggedテーブル(UNLOGGED参照)と一時テーブル(TEMPORARYまたはTEMP参照)以外のユーザ定義テーブルだけが、ロジカルデコーディングを使って更新データを取得できます。

49.6.4.6. TRUNCATEコールバック #

<title>Truncate Callback</title>

The optional <function>truncate_cb</function> callback is called for a <command>TRUNCATE</command> command. 《マッチ度[]》truncate_cbコールバックは、TRUNCATEコマンドに対して呼ばれます。

typedef void (*LogicalDecodeTruncateCB) (struct LogicalDecodingContext *ctx,
                                         ReorderBufferTXN *txn,
                                         int nrelations,
                                         Relation relations[],
                                         ReorderBufferChange *change);

The parameters are analogous to the <function>change_cb</function> callback. However, because <command>TRUNCATE</command> actions on tables connected by foreign keys need to be executed together, this callback receives an array of relations instead of just a single one. See the description of the <xref linkend="sql-truncate"/> statement for details. パラメータはchange_cbコールバックと似ています。 しかしながら、外部キーで結びついたテーブル群のTRUNCATE動作は一緒に実行される必要があるため、このコールバックは単一リレーションではなく、リレーションの配列を受け取ります。 詳しくはTRUNCATE文の説明を参照してください。

49.6.4.7. オリジンフィルターコールバック #

<title>Origin Filter Callback</title>

The optional <function>filter_by_origin_cb</function> callback is called to determine whether data that has been replayed from <parameter>origin_id</parameter> is of interest to the output plugin. オプションのfilter_by_origin_cbコールバックは、origin_idからリプレイされたデータがアウトプットプラグインの対象となるかどうかを判定するために呼び出されます。

typedef bool (*LogicalDecodeFilterByOriginCB) (struct LogicalDecodingContext *ctx,
                                               RepOriginId origin_id);

The <parameter>ctx</parameter> parameter has the same contents as for the other callbacks. No information but the origin is available. To signal that changes originating on the passed in node are irrelevant, return true, causing them to be filtered away; false otherwise. The other callbacks will not be called for transactions and changes that have been filtered away. ctxパラメータは、他のコールバックと同じ内容を持ちます。 オリジンの情報だけが得られます。 渡されたノードで発生した変更が無関係であることを伝えるには、trueを返します。 これにより、その変更は無視されることになります。 無視されたトランザクション変更に関わる他のコールバックは呼び出されません。

This is useful when implementing cascading or multidirectional replication solutions. Filtering by the origin allows to prevent replicating the same changes back and forth in such setups. While transactions and changes also carry information about the origin, filtering via this callback is noticeably more efficient. これは、カスケード、あるいは双方向レプリケーションソリューションを実装する際に有用です。 オリジンでフィルターすることにより、そのような構成で、同じ変更のレプリケーションが往復するのを防ぐことができます。 トランザクションや変更もオリジンに関する情報を持っていますが、このコールバックでフィルターするほうがずっと効率的です。

49.6.4.8. 汎用メッセージコールバック #

<title>Generic Message Callback</title>

The optional <function>message_cb</function> callback is called whenever a logical decoding message has been decoded. オプションのmessage_cbコールバックは、ロジカルデコーディングメッセージがデコードされる度に呼び出されます。

typedef void (*LogicalDecodeMessageCB) (struct LogicalDecodingContext *ctx,
                                        ReorderBufferTXN *txn,
                                        XLogRecPtr message_lsn,
                                        bool transactional,
                                        const char *prefix,
                                        Size message_size,
                                        const char *message);

The <parameter>txn</parameter> parameter contains meta information about the transaction, like the time stamp at which it has been committed and its XID. Note however that it can be NULL when the message is non-transactional and the XID was not assigned yet in the transaction which logged the message. The <parameter>lsn</parameter> has WAL location of the message. The <parameter>transactional</parameter> says if the message was sent as transactional or not. Similar to the change callback, in case of decoding a prepared (but yet uncommitted) transaction or decoding of an uncommitted transaction, this message callback might also error out due to simultaneous rollback of this very same transaction. In that case, the logical decoding of this aborted transaction is stopped gracefully. The <parameter>prefix</parameter> is arbitrary null-terminated prefix which can be used for identifying interesting messages for the current plugin. And finally the <parameter>message</parameter> parameter holds the actual message of <parameter>message_size</parameter> size. txnパラメータは、コミット時のタイムスタンプとXIDのような、トランザクションに関するメタ情報を含んでいます。 ただし、そのメッセージがトランザクション扱いではなく、メッセージをログしたトランザクションにXIDが割り当てられてない場合はNULLになることに注意してください。 lsnは、メッセージに対応するWALの位置です。 transactionalは、メッセージがトランザクションとして送られたものかどうかを表しています。 変更コールバックと同様に、準備された(まだコミットされていない)トランザクションをデコードする場合、またはコミットされていないトランザクションをデコードする場合、このメッセージコールバックも、まったく同じトランザクションの同時ロールバックのためにエラーになることがあります。 この場合、アボートされたトランザクションのロジカルデコーディングは正常に停止されます。 prefixはnull終端された任意の接頭辞で、現在のプラグインが興味のあるメッセージを特定するために利用できます。 最後に、messageパラメータは、大きさがmessage_sizeの、実際のメッセージを保持します。

Extra care should be taken to ensure that the prefix the output plugin considers interesting is unique. Using name of the extension or the output plugin itself is often a good choice. 出力プラグインが利用を考慮している接頭辞が一意になるように、特に注意を払ってください。 拡張の名前か、出力プラグインの名前を使うのが良い場合が多いです。

49.6.4.9. フィルタコールバックの準備 #

<title>Prepare Filter Callback</title>

The optional <function>filter_prepare_cb</function> callback is called to determine whether data that is part of the current two-phase commit transaction should be considered for decoding at this prepare stage or later as a regular one-phase transaction at <command>COMMIT PREPARED</command> time. To signal that decoding should be skipped, return <literal>true</literal>; <literal>false</literal> otherwise. When the callback is not defined, <literal>false</literal> is assumed (i.e. no filtering, all transactions using two-phase commit are decoded in two phases as well). オプションのfilter_prepare_cbコールバックは、現在の2相コミットトランザクションの一部であるデータを、この準備段階でデコードするか、またはCOMMIT PREPARED時に通常の1相トランザクションとしてデコードするかを決定するために呼び出されます。 デコードをスキップするように合図するには、trueを返します。 そうでなければfalseを返します。 コールバックが定義されていない場合、falseが想定されます(すなわち、フィルタリングなしで、2相コミットを使用するすべてのトランザクションも同様に2相でデコードされます)。

typedef bool (*LogicalDecodeFilterPrepareCB) (struct LogicalDecodingContext *ctx,
                                              TransactionId xid,
                                              const char *gid);

The <parameter>ctx</parameter> parameter has the same contents as for the other callbacks. The parameters <parameter>xid</parameter> and <parameter>gid</parameter> provide two different ways to identify the transaction. The later <command>COMMIT PREPARED</command> or <command>ROLLBACK PREPARED</command> carries both identifiers, providing an output plugin the choice of what to use. ctxパラメータは他のコールバックと同じ内容です。 パラメータxidgidは、トランザクションを識別するための2つの異なる方法を提供します。 後のCOMMIT PREPAREDまたはROLLBACK PREPAREDは両方の識別子を持ち、出力プラグインに何を使用するかの選択を提供します。

The callback may be invoked multiple times per transaction to decode and must provide the same static answer for a given pair of <parameter>xid</parameter> and <parameter>gid</parameter> every time it is called. このコールバックは、デコードするトランザクションごとに複数回呼び出すことができ、呼び出されるたびにxidgidの与えられたペアに対して同じ静的な答えを提供しなければなりません。

49.6.4.10. トランザクション開始準備コールバック #

<title>Transaction Begin Prepare Callback</title>

The required <function>begin_prepare_cb</function> callback is called whenever the start of a prepared transaction has been decoded. The <parameter>gid</parameter> field, which is part of the <parameter>txn</parameter> parameter, can be used in this callback to check if the plugin has already received this <command>PREPARE</command> in which case it can either error out or skip the remaining changes of the transaction. 必須であるbegin_prepare_cbコールバックは、準備されたトランザクションの開始がデコードされるたびに呼び出されます。 txnパラメータの一部であるgidフィールドをこのコールバックで使用して、プラグインがこのPREPAREを既に受信しているかどうかをチェックできます。 この場合、エラーになるか、トランザクションの残りの変更をスキップできます。

typedef void (*LogicalDecodeBeginPrepareCB) (struct LogicalDecodingContext *ctx,
                                             ReorderBufferTXN *txn);

49.6.4.11. トランザクション準備コールバック #

<title>Transaction Prepare Callback</title>

The required <function>prepare_cb</function> callback is called whenever a transaction which is prepared for two-phase commit has been decoded. The <function>change_cb</function> callback for all modified rows will have been called before this, if there have been any modified rows. The <parameter>gid</parameter> field, which is part of the <parameter>txn</parameter> parameter, can be used in this callback. 必須であるprepare_cbコールバックは、2相コミット用に準備されたトランザクションがデコードされるたびに呼び出されます。 修正された行がある場合、すべての修正された行に対するchange_cbコールバックはこの前に呼び出されています。 txnパラメータの一部であるgidフィールドは、このコールバックで使用できます。

typedef void (*LogicalDecodePrepareCB) (struct LogicalDecodingContext *ctx,
                                        ReorderBufferTXN *txn,
                                        XLogRecPtr prepare_lsn);

49.6.4.12. トランザクションコミット準備コールバック #

<title>Transaction Commit Prepared Callback</title>

The required <function>commit_prepared_cb</function> callback is called whenever a transaction <command>COMMIT PREPARED</command> has been decoded. The <parameter>gid</parameter> field, which is part of the <parameter>txn</parameter> parameter, can be used in this callback. 必須であるcommit_prepared_cbコールバックは、トランザクションCOMMIT PREPAREDがデコードされるたびに呼び出されます。 txnパラメータの一部であるgidフィールドは、このコールバックで使用できます。

typedef void (*LogicalDecodeCommitPreparedCB) (struct LogicalDecodingContext *ctx,
                                               ReorderBufferTXN *txn,
                                               XLogRecPtr commit_lsn);

49.6.4.13. トランザクションロールバック準備コールバック #

<title>Transaction Rollback Prepared Callback</title>

The required <function>rollback_prepared_cb</function> callback is called whenever a transaction <command>ROLLBACK PREPARED</command> has been decoded. The <parameter>gid</parameter> field, which is part of the <parameter>txn</parameter> parameter, can be used in this callback. The parameters <parameter>prepare_end_lsn</parameter> and <parameter>prepare_time</parameter> can be used to check if the plugin has received this <command>PREPARE TRANSACTION</command> in which case it can apply the rollback, otherwise, it can skip the rollback operation. The <parameter>gid</parameter> alone is not sufficient because the downstream node can have a prepared transaction with same identifier. 必須であるrollback_prepared_cbコールバックは、トランザクションROLLBACK PREPAREDがデコードされるたびに呼び出されます。 txnパラメータの一部であるgidフィールドは、このコールバックで使用できます。 パラメータprepare_end_lsnprepare_timeは、プラグインがこのPREPARE TRANSACTIONを受信したかどうかをチェックするために使用できます。 この場合、プラグインはロールバックを適用できます。 そうでない場合は、ロールバック操作をスキップできます。 gidだけでは十分ではありません。 なぜなら、下流ノードは同じ識別子を持つ準備されたトランザクションを持つことができるからです。

typedef void (*LogicalDecodeRollbackPreparedCB) (struct LogicalDecodingContext *ctx,
                                                 ReorderBufferTXN *txn,
                                                 XLogRecPtr prepare_end_lsn,
                                                 TimestampTz prepare_time);

49.6.4.14. ストリーム開始コールバック #

<title>Stream Start Callback</title>

The required <function>stream_start_cb</function> callback is called when opening a block of streamed changes from an in-progress transaction. 《機械翻訳》必要なLogicalDecodeStreamStartCBコールバックは、進行中のトランザクションからストリーム化された変更ブロックを開くときに呼び出されます。

typedef void (*LogicalDecodeStreamStartCB) (struct LogicalDecodingContext *ctx,
                                            ReorderBufferTXN *txn);

49.6.4.15. ストリーム停止コールバック #

<title>Stream Stop Callback</title>

The required <function>stream_stop_cb</function> callback is called when closing a block of streamed changes from an in-progress transaction. 《機械翻訳》必要なstream_stop_cbコールバックは、進行中のトランザクションからのストリーミング変更ブロックを閉じるときに呼び出されます。

typedef void (*LogicalDecodeStreamStopCB) (struct LogicalDecodingContext *ctx,
                                           ReorderBufferTXN *txn);

49.6.4.16. ストリームアボートコールバック #

<title>Stream Abort Callback</title>

The required <function>stream_abort_cb</function> callback is called to abort a previously streamed transaction. 《機械翻訳》必要なstream_abort_cbコールバックは、以前にストリームされたトランザクションを中止するために呼び出されます。

typedef void (*LogicalDecodeStreamAbortCB) (struct LogicalDecodingContext *ctx,
                                            ReorderBufferTXN *txn,
                                            XLogRecPtr abort_lsn);

49.6.4.17. ストリーム準備コールバック #

<title>Stream Prepare Callback</title>

The <function>stream_prepare_cb</function> callback is called to prepare a previously streamed transaction as part of a two-phase commit. This callback is required when the output plugin supports both the streaming of large in-progress transactions and two-phase commits. 《機械翻訳》stream_prepare_cbコールバックは、2フェーズコミットの一部としてストリーミングされているトランザクションを準備するために呼び出されます。 このコールバックは、出力プラグインが大きな進行中のトランザクションと2フェーズコミットの両方をストリーミングする場合に必要です。

typedef void (*LogicalDecodeStreamPrepareCB) (struct LogicalDecodingContext *ctx,
                                              ReorderBufferTXN *txn,
                                              XLogRecPtr prepare_lsn);

49.6.4.18. ストリームコミットコールバック #

<title>Stream Commit Callback</title>

The required <function>stream_commit_cb</function> callback is called to commit a previously streamed transaction. 《機械翻訳》必要なstream_commit_cbコールバックは、以前にストリーミングされたトランザクションをコミットするために呼び出されます。

typedef void (*LogicalDecodeStreamCommitCB) (struct LogicalDecodingContext *ctx,
                                             ReorderBufferTXN *txn,
                                             XLogRecPtr commit_lsn);

49.6.4.19. ストリーム変更コールバック #

<title>Stream Change Callback</title>

The required <function>stream_change_cb</function> callback is called when sending a change in a block of streamed changes (demarcated by <function>stream_start_cb</function> and <function>stream_stop_cb</function> calls). The actual changes are not displayed as the transaction can abort at a later point in time and we don't decode changes for aborted transactions. 《マッチ度[60.000000]》stream_change_cbコールバックは、ストリーム化された変更のブロック(stream_start_cbstream_stop_cb呼び出しで区切られます)で変更を送信するときに呼び出されます。 実際の変更は表示されません。 なぜなら、トランザクションは後の時点でアボートする可能性があり、アボートされたトランザクションの変更はデコードされないからです。 《機械翻訳》ストリーム化された変更のブロック内で変更が送信されるときに、必要なstream_change_cbコールバックが呼び出されます(stream_start_cbstream_stop_cbの呼び出しによって区切られます)。 実際の変更は後で表示される可能性があり、中止された変更の変更をデコードすることはできないため、トランザクションは中止されません。

typedef void (*LogicalDecodeStreamChangeCB) (struct LogicalDecodingContext *ctx,
                                             ReorderBufferTXN *txn,
                                             Relation relation,
                                             ReorderBufferChange *change);

49.6.4.20. ストリームメッセージコールバック #

<title>Stream Message Callback</title>

The optional <function>stream_message_cb</function> callback is called when sending a generic message in a block of streamed changes (demarcated by <function>stream_start_cb</function> and <function>stream_stop_cb</function> calls). The message contents for transactional messages are not displayed as the transaction can abort at a later point in time and we don't decode changes for aborted transactions. 《マッチ度[57.603687]》stream_message_cbコールバックは、ストリーム化された変更のブロック(stream_start_cbstream_stop_cbコールで区切られた)で汎用メッセージを送信するときに呼び出されます。 トランザクションメッセージのメッセージ内容は表示されません。 なぜなら、トランザクションは後の時点でアボートする可能性があり、アボートされたトランザクションの変更はデコードされないからです。 《機械翻訳》オプションのstream_message_cbコールバックは、ブロックされた変更のストリームで一般的なメッセージを送信するときに呼び出されます(stream_start_cbstream_stop_cbの呼び出しによって区切られます)。 トランザクションメッセージのメッセージ内容は、後で中止される可能性があるため、トランザクションが中止されるときに表示されず、中止された変更のメッセージをデコードしません。

typedef void (*LogicalDecodeStreamMessageCB) (struct LogicalDecodingContext *ctx,
                                              ReorderBufferTXN *txn,
                                              XLogRecPtr message_lsn,
                                              bool transactional,
                                              const char *prefix,
                                              Size message_size,
                                              const char *message);

49.6.4.21. ストリームTRUNCATEコールバック #

<title>Stream Truncate Callback</title>

The optional <function>stream_truncate_cb</function> callback is called for a <command>TRUNCATE</command> command in a block of streamed changes (demarcated by <function>stream_start_cb</function> and <function>stream_stop_cb</function> calls). 《マッチ度[]》stream_truncate_cbコールバックは、ストリーム化された変更のブロック(stream_start_cbstream_stop_cb呼び出しで区切られます)内のTRUNCATEコマンドに対して呼び出されます。

typedef void (*LogicalDecodeStreamTruncateCB) (struct LogicalDecodingContext *ctx,
                                               ReorderBufferTXN *txn,
                                               int nrelations,
                                               Relation relations[],
                                               ReorderBufferChange *change);

The parameters are analogous to the <function>stream_change_cb</function> callback. However, because <command>TRUNCATE</command> actions on tables connected by foreign keys need to be executed together, this callback receives an array of relations instead of just a single one. See the description of the <xref linkend="sql-truncate"/> statement for details. パラメータはstream_change_cbコールバックに類似しています。 ただし、外部キーで接続されたテーブルに対するTRUNCATEアクションは一緒に実行する必要があるため、このコールバックは単一のリレーションではなくリレーションの配列を受け取ります。 詳細はTRUNCATE文の説明を参照してください。

49.6.5. 出力生成関数 #

<title>Functions for Producing Output</title>

To actually produce output, output plugins can write data to the <literal>StringInfo</literal> output buffer in <literal>ctx-&gt;out</literal> when inside the <function>begin_cb</function>, <function>commit_cb</function>, or <function>change_cb</function> callbacks. Before writing to the output buffer, <function>OutputPluginPrepareWrite(ctx, last_write)</function> has to be called, and after finishing writing to the buffer, <function>OutputPluginWrite(ctx, last_write)</function> has to be called to perform the write. The <parameter>last_write</parameter> indicates whether a particular write was the callback's last write. begin_cbcommit_cbchange_cbコールバックにおいて、出力プラグインは実際にデータ出力するためにctx->outStringInfo出力バッファに書き込みます。 出力バッファに書き込む前に、OutputPluginPrepareWrite(ctx, last_write)を呼び出します。 また、書き込みバッファにデータを書き終えたら、OutputPluginWrite(ctx, last_write)を呼び出してデータの書き込みを実施します。 last_write引数により、その書き込みがコールバックの最終的な書き込みであるかどうかを指定します。

The following example shows how to output data to the consumer of an output plugin: 以下の例では、出力プラグインにおいて消費者に向けてデータを出力する方法を示します。

OutputPluginPrepareWrite(ctx, true);
appendStringInfo(ctx->out, "BEGIN %u", txn->xid);
OutputPluginWrite(ctx, true);