codekingpro/portable-devtools
115k
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>49.10. Two-phase Commit Support for Logical Decoding</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="logicaldecoding-streaming.html" title="49.9. Streaming of Large Transactions for Logical Decoding" /><link rel="next" href="replication-origins.html" title="Chapter 50. Replication Progress Tracking" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">49.10. Two-phase Commit Support for Logical Decoding</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="logicaldecoding-streaming.html" title="49.9. Streaming of Large Transactions for Logical Decoding">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="logicaldecoding.html" title="Chapter 49. Logical Decoding">Up</a></td><th width="60%" align="center">Chapter 49. Logical Decoding</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="replication-origins.html" title="Chapter 50. Replication Progress Tracking">Next</a></td></tr></table><hr /></div><div class="sect1" id="LOGICALDECODING-TWO-PHASE-COMMITS"><div class="titlepage"><div><div><h2 class="title" style="clear: both">49.10. Two-phase Commit Support for Logical Decoding <a href="#LOGICALDECODING-TWO-PHASE-COMMITS" class="id_link">#</a></h2></div></div></div><p>3 With the basic output plugin callbacks (eg., <code class="function">begin_cb</code>,4 <code class="function">change_cb</code>, <code class="function">commit_cb</code> and5 <code class="function">message_cb</code>) two-phase commit commands like6 <code class="command">PREPARE TRANSACTION</code>, <code class="command">COMMIT PREPARED</code>7 and <code class="command">ROLLBACK PREPARED</code> are not decoded. While the8 <code class="command">PREPARE TRANSACTION</code> is ignored,9 <code class="command">COMMIT PREPARED</code> is decoded as a <code class="command">COMMIT</code>10 and <code class="command">ROLLBACK PREPARED</code> is decoded as a11 <code class="command">ROLLBACK</code>.12 </p><p>13 To support the streaming of two-phase commands, an output plugin needs to14 provide additional callbacks. There are multiple two-phase commit callbacks15 that are required, (<code class="function">begin_prepare_cb</code>,16 <code class="function">prepare_cb</code>, <code class="function">commit_prepared_cb</code>,17 <code class="function">rollback_prepared_cb</code> and18 <code class="function">stream_prepare_cb</code>) and an optional callback19 (<code class="function">filter_prepare_cb</code>).20 </p><p>21 If the output plugin callbacks for decoding two-phase commit commands are22 provided, then on <code class="command">PREPARE TRANSACTION</code>, the changes of23 that transaction are decoded, passed to the output plugin, and the24 <code class="function">prepare_cb</code> callback is invoked. This differs from the25 basic decoding setup where changes are only passed to the output plugin26 when a transaction is committed. The start of a prepared transaction is27 indicated by the <code class="function">begin_prepare_cb</code> callback.28 </p><p>29 When a prepared transaction is rolled back using the30 <code class="command">ROLLBACK PREPARED</code>, then the31 <code class="function">rollback_prepared_cb</code> callback is invoked and when the32 prepared transaction is committed using <code class="command">COMMIT PREPARED</code>,33 then the <code class="function">commit_prepared_cb</code> callback is invoked.34 </p><p>35 Optionally the output plugin can define filtering rules via36 <code class="function">filter_prepare_cb</code> to decode only specific transaction37 in two phases. This can be achieved by pattern matching on the38 <em class="parameter"><code>gid</code></em> or via lookups using the39 <em class="parameter"><code>xid</code></em>.40 </p><p>41 The users that want to decode prepared transactions need to be careful about42 below mentioned points:43 44 </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>45 If the prepared transaction has locked [user] catalog tables exclusively46 then decoding prepare can block till the main transaction is committed.47 </p></li><li class="listitem"><p>48 The logical replication solution that builds distributed two phase commit49 using this feature can deadlock if the prepared transaction has locked50 [user] catalog tables exclusively. To avoid this users must refrain from51 having locks on catalog tables (e.g. explicit <code class="command">LOCK</code> command)52 in such transactions.53 See <a class="xref" href="logicaldecoding-synchronous.html#LOGICALDECODING-SYNCHRONOUS-CAVEATS" title="49.8.2. Caveats">Section 49.8.2</a> for the details.54 </p></li></ul></div><p>55 </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="logicaldecoding-streaming.html" title="49.9. Streaming of Large Transactions for Logical Decoding">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="logicaldecoding.html" title="Chapter 49. Logical Decoding">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="replication-origins.html" title="Chapter 50. Replication Progress Tracking">Next</a></td></tr><tr><td width="40%" align="left" valign="top">49.9. Streaming of Large Transactions for Logical Decoding </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> Chapter 50. Replication Progress Tracking</td></tr></table></div></body></html>