From fc425a59b2f17427861033cb03df86b36b60db89 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Fri, 13 May 2022 18:18:27 +1000 Subject: [PATCH v1] PGDOCS tablesync ignores publish operation The tablesync ignores the publication 'publish' operations during the initial data copy. This is existing PG behaviour but it was not documented before. This patch documents the behaviour and gives some examples. --- doc/src/sgml/logical-replication.sgml | 90 ++++++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/doc/src/sgml/logical-replication.sgml b/doc/src/sgml/logical-replication.sgml index 145ea71..8dfc8f7 100644 --- a/doc/src/sgml/logical-replication.sgml +++ b/doc/src/sgml/logical-replication.sgml @@ -459,6 +459,9 @@ published with different WHERE clauses, rows that satisfy any of the expressions will be copied. See for details. + Note that during the initial data synchronizaton (unlike normal replication) + the publish operation of the publisher is ignored. See + for details. @@ -500,7 +503,8 @@ - + + @@ -1095,7 +1099,91 @@ CONTEXT: processing remote data for replication origin "pg_16395" during "INSER replication of the table is given back to the main apply process where replication continues as normal. + + + Publication publish operations ( + insert, update, delete, + ...) are ignored during the initial data copy. + + + + + + Example + + + Create some test tables on the publisher. + +test_pub=# CREATE TABLE t1(a int, b text, PRIMARY KEY(a)); +CREATE TABLE +test_pub=# CREATE TABLE t2(c int, d text, PRIMARY KEY(c)); +CREATE TABLE + + + + Create the same tables on the subscriber. + +test_sub=# CREATE TABLE t1(a int, b text, PRIMARY KEY(a)); +CREATE TABLE +test_sub=# CREATE TABLE t2(c int, d text, PRIMARY KEY(c)); +CREATE TABLE + + + + Insert data to the tables at the publisher side. + +test_pub=# INSERT INTO t1 VALUES (1, 'one'), (2, 'two'), (3, 'three'); +INSERT 0 3 +test_pub=# INSERT INTO t2 VALUES (1, 'A'), (2, 'B'), (3, 'C'); +INSERT 0 3 + + + + Create publications for the tables. The publication pub2 + limits the publish operations. + +test_pub=# CREATE PUBLICATION pub1 FOR TABLE t1; +CREATE PUBLICATION +test_pub=# CREATE PUBLICATION pub2 FOR TABLE t2 WITH (publish = 'truncate'); +CREATE PUBLICATION + + + + Create subscriptions to each of those publications. Subscriptions + will copy initial data by default. + +test_sub=# CREATE SUBSCRIPTION sub1 +test_sub-#CONNECTION 'host=localhost dbname=test_pub application_name=sub1' +test_sub-#PUBLICATION pub1; +CREATE SUBSCRIPTION +test_sub=# CREATE SUBSCRIPTION sub2 +test_sub-#CONNECTION 'host=localhost dbname=test_pub application_name=sub2' +test_sub-#PUBLICATION pub2; +CREATE SUBSCRIPTION + + + + Observe that initial table data is copied, regardless of the + publish operation of the publication. + +test_sub=# SELECT * FROM t1; + a | b +---+------- + 1 | one + 2 | two + 3 | three +(3 rows) + +test_sub=# SELECT * FROM t2; + c | d +---+--- + 1 | A + 2 | B + 3 | C +(3 rows) + + -- 1.8.3.1