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>31.7. Architecture</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="logical-replication-restrictions.html" title="31.6. Restrictions" /><link rel="next" href="logical-replication-monitoring.html" title="31.8. Monitoring" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">31.7. Architecture</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="logical-replication-restrictions.html" title="31.6. Restrictions">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="logical-replication.html" title="Chapter 31. Logical Replication">Up</a></td><th width="60%" align="center">Chapter 31. Logical Replication</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="logical-replication-monitoring.html" title="31.8. Monitoring">Next</a></td></tr></table><hr /></div><div class="sect1" id="LOGICAL-REPLICATION-ARCHITECTURE"><div class="titlepage"><div><div><h2 class="title" style="clear: both">31.7. Architecture <a href="#LOGICAL-REPLICATION-ARCHITECTURE" class="id_link">#</a></h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="logical-replication-architecture.html#LOGICAL-REPLICATION-SNAPSHOT">31.7.1. Initial Snapshot</a></span></dt></dl></div><p>3 Logical replication starts by copying a snapshot of the data on the4 publisher database. Once that is done, changes on the publisher are sent5 to the subscriber as they occur in real time. The subscriber applies data6 in the order in which commits were made on the publisher so that7 transactional consistency is guaranteed for the publications within any8 single subscription.9 </p><p>10 Logical replication is built with an architecture similar to physical11 streaming replication (see <a class="xref" href="warm-standby.html#STREAMING-REPLICATION" title="27.2.5. Streaming Replication">Section 27.2.5</a>). It is12 implemented by <code class="literal">walsender</code> and <code class="literal">apply</code>13 processes. The walsender process starts logical decoding (described14 in <a class="xref" href="logicaldecoding.html" title="Chapter 49. Logical Decoding">Chapter 49</a>) of the WAL and loads the standard15 logical decoding output plugin (<code class="literal">pgoutput</code>). The plugin16 transforms the changes read17 from WAL to the logical replication protocol18 (see <a class="xref" href="protocol-logical-replication.html" title="55.5. Logical Streaming Replication Protocol">Section 55.5</a>) and filters the data19 according to the publication specification. The data is then continuously20 transferred using the streaming replication protocol to the apply worker,21 which maps the data to local tables and applies the individual changes as22 they are received, in correct transactional order.23 </p><p>24 The apply process on the subscriber database always runs with25 <a class="link" href="runtime-config-client.html#GUC-SESSION-REPLICATION-ROLE"><code class="varname">session_replication_role</code></a>26 set to <code class="literal">replica</code>. This means that, by default,27 triggers and rules will not fire on a subscriber. Users can optionally choose to28 enable triggers and rules on a table using the29 <a class="link" href="sql-altertable.html" title="ALTER TABLE"><code class="command">ALTER TABLE</code></a> command30 and the <code class="literal">ENABLE TRIGGER</code> and <code class="literal">ENABLE RULE</code>31 clauses.32 </p><p>33 The logical replication apply process currently only fires row triggers,34 not statement triggers. The initial table synchronization, however, is35 implemented like a <code class="command">COPY</code> command and thus fires both row36 and statement triggers for <code class="command">INSERT</code>.37 </p><div class="sect2" id="LOGICAL-REPLICATION-SNAPSHOT"><div class="titlepage"><div><div><h3 class="title">31.7.1. Initial Snapshot <a href="#LOGICAL-REPLICATION-SNAPSHOT" class="id_link">#</a></h3></div></div></div><p>38 The initial data in existing subscribed tables are snapshotted and39 copied in a parallel instance of a special kind of apply process.40 This process will create its own replication slot and copy the existing41 data. As soon as the copy is finished the table contents will become42 visible to other backends. Once existing data is copied, the worker43 enters synchronization mode, which ensures that the table is brought44 up to a synchronized state with the main apply process by streaming45 any changes that happened during the initial data copy using standard46 logical replication. During this synchronization phase, the changes47 are applied and committed in the same order as they happened on the48 publisher. Once synchronization is done, control of the49 replication of the table is given back to the main apply process where50 replication continues as normal.51 </p><div class="note"><h3 class="title">Note</h3><p>52 The publication53 <a class="link" href="sql-createpublication.html#SQL-CREATEPUBLICATION-WITH-PUBLISH"><code class="literal">publish</code></a>54 parameter only affects what DML operations will be replicated. The55 initial data synchronization does not take this parameter into account56 when copying the existing table data.57 </p></div></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="logical-replication-restrictions.html" title="31.6. Restrictions">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="logical-replication.html" title="Chapter 31. Logical Replication">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="logical-replication-monitoring.html" title="31.8. Monitoring">Next</a></td></tr><tr><td width="40%" align="left" valign="top">31.6. Restrictions </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"> 31.8. Monitoring</td></tr></table></div></body></html>