2 47.10. Two-phase Commit Support for Logical Decoding #
4 With the basic output plugin callbacks (eg., begin_cb, change_cb,
5 commit_cb and message_cb) two-phase commit commands like PREPARE
6 TRANSACTION, COMMIT PREPARED and ROLLBACK PREPARED are not decoded.
7 While the PREPARE TRANSACTION is ignored, COMMIT PREPARED is decoded as
8 a COMMIT and ROLLBACK PREPARED is decoded as a ROLLBACK.
10 To support the streaming of two-phase commands, an output plugin needs
11 to provide additional callbacks. There are multiple two-phase commit
12 callbacks that are required, (begin_prepare_cb, prepare_cb,
13 commit_prepared_cb, rollback_prepared_cb and stream_prepare_cb) and an
14 optional callback (filter_prepare_cb).
16 If the output plugin callbacks for decoding two-phase commit commands
17 are provided, then on PREPARE TRANSACTION, the changes of that
18 transaction are decoded, passed to the output plugin, and the
19 prepare_cb callback is invoked. This differs from the basic decoding
20 setup where changes are only passed to the output plugin when a
21 transaction is committed. The start of a prepared transaction is
22 indicated by the begin_prepare_cb callback.
24 When a prepared transaction is rolled back using the ROLLBACK PREPARED,
25 then the rollback_prepared_cb callback is invoked and when the prepared
26 transaction is committed using COMMIT PREPARED, then the
27 commit_prepared_cb callback is invoked.
29 Optionally the output plugin can define filtering rules via
30 filter_prepare_cb to decode only specific transaction in two phases.
31 This can be achieved by pattern matching on the gid or via lookups
34 The users that want to decode prepared transactions need to be careful
35 about below mentioned points:
36 * If the prepared transaction has locked [user] catalog tables
37 exclusively then decoding prepare can block till the main
38 transaction is committed.
39 * The logical replication solution that builds distributed two phase
40 commit using this feature can deadlock if the prepared transaction
41 has locked [user] catalog tables exclusively. To avoid this users
42 must refrain from having locks on catalog tables (e.g. explicit
43 LOCK command) in such transactions. See Section 47.8.2 for the