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>29.1. Publication</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.html" title="Chapter 29. Logical Replication" /><link rel="next" href="logical-replication-subscription.html" title="29.2. Subscription" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">29.1. Publication</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="logical-replication.html" title="Chapter 29. Logical Replication">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="logical-replication.html" title="Chapter 29. Logical Replication">Up</a></td><th width="60%" align="center">Chapter 29. Logical Replication</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="logical-replication-subscription.html" title="29.2. Subscription">Next</a></td></tr></table><hr /></div><div class="sect1" id="LOGICAL-REPLICATION-PUBLICATION"><div class="titlepage"><div><div><h2 class="title" style="clear: both">29.1. Publication <a href="#LOGICAL-REPLICATION-PUBLICATION" class="id_link">#</a></h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="logical-replication-publication.html#LOGICAL-REPLICATION-PUBLICATION-REPLICA-IDENTITY">29.1.1. Replica Identity</a></span></dt></dl></div><p>
3 A <em class="firstterm">publication</em> can be defined on any physical
4 replication primary. The node where a publication is defined is referred to
5 as <em class="firstterm">publisher</em>. A publication is a set of changes
6 generated from a table or a group of tables, and might also be described as
7 a change set or replication set. Each publication exists in only one database.
9 Publications are different from schemas and do not affect how the table is
10 accessed. Each table can be added to multiple publications if needed.
11 Publications may currently only contain tables and all tables in schema.
12 Objects must be added explicitly, except when a publication is created for
13 <code class="literal">ALL TABLES</code>.
15 Publications can choose to limit the changes they produce to
16 any combination of <code class="command">INSERT</code>, <code class="command">UPDATE</code>,
17 <code class="command">DELETE</code>, and <code class="command">TRUNCATE</code>, similar to how triggers are fired by
18 particular event types. By default, all operation types are replicated.
19 These publication specifications apply only for DML operations; they do not affect the initial
20 data synchronization copy. (Row filters have no effect for
21 <code class="command">TRUNCATE</code>. See <a class="xref" href="logical-replication-row-filter.html" title="29.4. Row Filters">Section 29.4</a>).
23 Every publication can have multiple subscribers.
25 A publication is created using the <a class="link" href="sql-createpublication.html" title="CREATE PUBLICATION"><code class="command">CREATE PUBLICATION</code></a>
26 command and may later be altered or dropped using corresponding commands.
28 The individual tables can be added and removed dynamically using
29 <a class="link" href="sql-alterpublication.html" title="ALTER PUBLICATION"><code class="command">ALTER PUBLICATION</code></a>. Both the <code class="literal">ADD
30 TABLE</code> and <code class="literal">DROP TABLE</code> operations are
31 transactional, so the table will start or stop replicating at the correct
32 snapshot once the transaction has committed.
33 </p><div class="sect2" id="LOGICAL-REPLICATION-PUBLICATION-REPLICA-IDENTITY"><div class="titlepage"><div><div><h3 class="title">29.1.1. Replica Identity <a href="#LOGICAL-REPLICATION-PUBLICATION-REPLICA-IDENTITY" class="id_link">#</a></h3></div></div></div><p>
34 A published table must have a <em class="firstterm">replica identity</em>
35 configured in order to be able to replicate <code class="command">UPDATE</code>
36 and <code class="command">DELETE</code> operations, so that appropriate rows to
37 update or delete can be identified on the subscriber side.
39 By default, this is the primary key, if there is one. Another unique index
40 (with certain additional requirements) can also be set to be the replica
41 identity. If the table does not have any suitable key, then it can be set
42 to replica identity <code class="literal">FULL</code>, which means the entire row
43 becomes the key. When replica identity <code class="literal">FULL</code> is
44 specified, indexes can be used on the subscriber side for searching the
45 rows. Candidate indexes must be btree or hash, non-partial, and the
46 leftmost index field must be a column (not an expression) that references
47 the published table column. These restrictions on the non-unique index
48 properties adhere to some of the restrictions that are enforced for
49 primary keys. If there are no such suitable indexes, the search on the
50 subscriber side can be very inefficient, therefore replica identity
51 <code class="literal">FULL</code> should only be used as a fallback if no other
54 If a replica identity other than <code class="literal">FULL</code> is set on the
55 publisher side, a replica identity comprising the same or fewer columns
56 must also be set on the subscriber side.
58 Tables with a replica identity defined as <code class="literal">NOTHING</code>,
59 <code class="literal">DEFAULT</code> without a primary key, or <code class="literal">USING
60 INDEX</code> with a dropped index, cannot support
61 <code class="command">UPDATE</code> or <code class="command">DELETE</code> operations when
62 included in a publication replicating these actions. Attempting such
63 operations will result in an error on the publisher.
65 <code class="command">INSERT</code> operations can proceed regardless of any replica identity.
67 See <a class="link" href="sql-altertable.html#SQL-ALTERTABLE-REPLICA-IDENTITY"><code class="literal">ALTER TABLE...REPLICA IDENTITY</code></a>
68 for details on how to set the replica identity.
69 </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="logical-replication.html" title="Chapter 29. Logical Replication">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="logical-replication.html" title="Chapter 29. Logical Replication">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="logical-replication-subscription.html" title="29.2. Subscription">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 29. Logical Replication </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 29.2. Subscription</td></tr></table></div></body></html>