Postgresql 中文操作指南
49.10. Two-phase Commit Support for Logical Decoding #
使用基本的输出插件回调(例如 begin_cb、change_cb、commit_cb 和 message_cb),两个阶段提交命令(如 PREPARE TRANSACTION、COMMIT PREPARED 和 ROLLBACK PREPARED)不会被解码。虽然 PREPARE TRANSACTION 被忽略,但 COMMIT PREPARED 被解码为 COMMIT,而 ROLLBACK PREPARED 被解码为 ROLLBACK。
With the basic output plugin callbacks (eg., begin_cb, change_cb, commit_cb and message_cb) two-phase commit commands like PREPARE TRANSACTION, COMMIT PREPARED and ROLLBACK PREPARED are not decoded. While the PREPARE TRANSACTION is ignored, COMMIT PREPARED is decoded as a COMMIT and ROLLBACK PREPARED is decoded as a ROLLBACK.
为了支持流式处理两个阶段命令,输出插件需要提供附加回调。需要多个两个阶段提交回调(begin_prepare_cb、prepare_cb、commit_prepared_cb、rollback_prepared_cb 和 stream_prepare_cb)和一个可选回调(filter_prepare_cb)。
To support the streaming of two-phase commands, an output plugin needs to provide additional callbacks. There are multiple two-phase commit callbacks that are required, (begin_prepare_cb, prepare_cb, commit_prepared_cb, rollback_prepared_cb and stream_prepare_cb) and an optional callback (filter_prepare_cb).
如果提供了用于解码两个阶段提交命令的输出插件回调,那么在 PREPARE TRANSACTION 上,将解码该事务的更改,将其传递给输出插件,并调用 prepare_cb 回调。这与基本解码设置不同,在该设置中,只有在提交事务时才会将更改传递给输出插件。begin_prepare_cb 回调指示已准备好的事务的开始。
If the output plugin callbacks for decoding two-phase commit commands are provided, then on PREPARE TRANSACTION, the changes of that transaction are decoded, passed to the output plugin, and the prepare_cb callback is invoked. This differs from the basic decoding setup where changes are only passed to the output plugin when a transaction is committed. The start of a prepared transaction is indicated by the begin_prepare_cb callback.
当使用 ROLLBACK PREPARED 回滚已准备好的事务时,将调用 rollback_prepared_cb 回调;当使用 COMMIT PREPARED 提交已准备好的事务时,将调用 commit_prepared_cb 回调。
When a prepared transaction is rolled back using the ROLLBACK PREPARED, then the rollback_prepared_cb callback is invoked and when the prepared transaction is committed using COMMIT PREPARED, then the commit_prepared_cb callback is invoked.
输出插件可以可选地通过 filter_prepare_cb 定义过滤规则,以只解码两个阶段中的特定事务。这可以通过对 gid 上的模式进行匹配或通过使用 xid 进行查找来实现。
Optionally the output plugin can define filtering rules via filter_prepare_cb to decode only specific transaction in two phases. This can be achieved by pattern matching on the gid or via lookups using the xid.
想要解码已准备好的事务的用户需要注意以下几点:
The users that want to decode prepared transactions need to be careful about below mentioned points: