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>55.5. Logical Streaming Replication Protocol</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="protocol-replication.html" title="55.4. Streaming Replication Protocol" /><link rel="next" href="protocol-message-types.html" title="55.6. Message Data Types" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">55.5. Logical Streaming Replication Protocol</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="protocol-replication.html" title="55.4. Streaming Replication Protocol">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="protocol.html" title="Chapter 55. Frontend/Backend Protocol">Up</a></td><th width="60%" align="center">Chapter 55. Frontend/Backend Protocol</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="protocol-message-types.html" title="55.6. Message Data Types">Next</a></td></tr></table><hr /></div><div class="sect1" id="PROTOCOL-LOGICAL-REPLICATION"><div class="titlepage"><div><div><h2 class="title" style="clear: both">55.5. Logical Streaming Replication Protocol <a href="#PROTOCOL-LOGICAL-REPLICATION" class="id_link">#</a></h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="protocol-logical-replication.html#PROTOCOL-LOGICAL-REPLICATION-PARAMS">55.5.1. Logical Streaming Replication Parameters</a></span></dt><dt><span class="sect2"><a href="protocol-logical-replication.html#PROTOCOL-LOGICAL-MESSAGES">55.5.2. Logical Replication Protocol Messages</a></span></dt><dt><span class="sect2"><a href="protocol-logical-replication.html#PROTOCOL-LOGICAL-MESSAGES-FLOW">55.5.3. Logical Replication Protocol Message Flow</a></span></dt></dl></div><p>3 This section describes the logical replication protocol, which is the message4 flow started by the <code class="literal">START_REPLICATION</code>5 <code class="literal">SLOT</code> <em class="replaceable"><code>slot_name</code></em>6 <code class="literal">LOGICAL</code> replication command.7 </p><p>8 The logical streaming replication protocol builds on the primitives of9 the physical streaming replication protocol.10 </p><p>11 <span class="productname">PostgreSQL</span> logical decoding supports output12 plugins. <code class="literal">pgoutput</code> is the standard one used for13 the built-in logical replication.14 </p><div class="sect2" id="PROTOCOL-LOGICAL-REPLICATION-PARAMS"><div class="titlepage"><div><div><h3 class="title">55.5.1. Logical Streaming Replication Parameters <a href="#PROTOCOL-LOGICAL-REPLICATION-PARAMS" class="id_link">#</a></h3></div></div></div><p>15 Using the <code class="literal">START_REPLICATION</code> command,16 <code class="literal">pgoutput</code> accepts the following options:17 18 </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">19 proto_version20 </span></dt><dd><p>21 Protocol version. Currently versions <code class="literal">1</code>, <code class="literal">2</code>,22 <code class="literal">3</code>, and <code class="literal">4</code> are supported. A valid23 version is required.24 </p><p>25 Version <code class="literal">2</code> is supported only for server version 1426 and above, and it allows streaming of large in-progress transactions.27 </p><p>28 Version <code class="literal">3</code> is supported only for server version 1529 and above, and it allows streaming of two-phase commits.30 </p><p>31 Version <code class="literal">4</code> is supported only for server version 1632 and above, and it allows streams of large in-progress transactions to33 be applied in parallel.34 </p></dd><dt><span class="term">35 publication_names36 </span></dt><dd><p>37 Comma separated list of publication names for which to subscribe38 (receive changes). The individual publication names are treated39 as standard objects names and can be quoted the same as needed.40 At least one publication name is required.41 </p></dd><dt><span class="term">42 binary43 </span></dt><dd><p>44 Boolean option to use binary transfer mode. Binary mode is faster45 than the text mode but slightly less robust.46 </p></dd><dt><span class="term">47 messages48 </span></dt><dd><p>49 Boolean option to enable sending the messages that are written50 by <code class="function">pg_logical_emit_message</code>.51 </p></dd><dt><span class="term">52 streaming53 </span></dt><dd><p>54 Boolean option to enable streaming of in-progress transactions.55 It accepts an additional value "parallel" to enable sending extra56 information with some messages to be used for parallelisation.57 Minimum protocol version 2 is required to turn it on. Minimum protocol58 version 4 is required for the "parallel" option.59 </p></dd><dt><span class="term">60 two_phase61 </span></dt><dd><p>62 Boolean option to enable two-phase transactions. Minimum protocol63 version 3 is required to turn it on.64 </p></dd><dt><span class="term">65 origin66 </span></dt><dd><p>67 Option to send changes by their origin. Possible values are "none"68 to only send the changes that have no origin associated, or "any"69 to send the changes regardless of their origin. This can be used70 to avoid loops (infinite replication of the same data) among71 replication nodes.72 </p></dd></dl></div><p>73 74 </p></div><div class="sect2" id="PROTOCOL-LOGICAL-MESSAGES"><div class="titlepage"><div><div><h3 class="title">55.5.2. Logical Replication Protocol Messages <a href="#PROTOCOL-LOGICAL-MESSAGES" class="id_link">#</a></h3></div></div></div><p>75 The individual protocol messages are discussed in the following76 subsections. Individual messages are described in77 <a class="xref" href="protocol-logicalrep-message-formats.html" title="55.9. Logical Replication Message Formats">Section 55.9</a>.78 </p><p>79 All top-level protocol messages begin with a message type byte.80 While represented in code as a character, this is a signed byte with no81 associated encoding.82 </p><p>83 Since the streaming replication protocol supplies a message length there84 is no need for top-level protocol messages to embed a length in their85 header.86 </p></div><div class="sect2" id="PROTOCOL-LOGICAL-MESSAGES-FLOW"><div class="titlepage"><div><div><h3 class="title">55.5.3. Logical Replication Protocol Message Flow <a href="#PROTOCOL-LOGICAL-MESSAGES-FLOW" class="id_link">#</a></h3></div></div></div><p>87 With the exception of the <code class="literal">START_REPLICATION</code> command and88 the replay progress messages, all information flows only from the backend89 to the frontend.90 </p><p>91 The logical replication protocol sends individual transactions one by one.92 This means that all messages between a pair of Begin and Commit messages93 belong to the same transaction. Similarly, all messages between a pair of94 Begin Prepare and Prepare messages belong to the same transaction.95 It also sends changes of large in-progress transactions between a pair of96 Stream Start and Stream Stop messages. The last stream of such a transaction97 contains a Stream Commit or Stream Abort message.98 </p><p>99 Every sent transaction contains zero or more DML messages (Insert,100 Update, Delete). In case of a cascaded setup it can also contain Origin101 messages. The origin message indicates that the transaction originated on102 different replication node. Since a replication node in the scope of logical103 replication protocol can be pretty much anything, the only identifier104 is the origin name. It's downstream's responsibility to handle this as105 needed (if needed). The Origin message is always sent before any DML106 messages in the transaction.107 </p><p>108 Every DML message contains a relation OID, identifying the publisher's109 relation that was acted on. Before the first DML message for a given110 relation OID, a Relation message will be sent, describing the schema of111 that relation. Subsequently, a new Relation message will be sent if112 the relation's definition has changed since the last Relation message113 was sent for it. (The protocol assumes that the client is capable of114 remembering this metadata for as many relations as needed.)115 </p><p>116 Relation messages identify column types by their OIDs. In the case117 of a built-in type, it is assumed that the client can look up that118 type OID locally, so no additional data is needed. For a non-built-in119 type OID, a Type message will be sent before the Relation message,120 to provide the type name associated with that OID. Thus, a client that121 needs to specifically identify the types of relation columns should122 cache the contents of Type messages, and first consult that cache to123 see if the type OID is defined there. If not, look up the type OID124 locally.125 </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="protocol-replication.html" title="55.4. Streaming Replication Protocol">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="protocol.html" title="Chapter 55. Frontend/Backend Protocol">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="protocol-message-types.html" title="55.6. Message Data Types">Next</a></td></tr><tr><td width="40%" align="left" valign="top">55.4. Streaming Replication Protocol </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"> 55.6. Message Data Types</td></tr></table></div></body></html>