+/* pub # */ CREATE PUBLICATION pub1 FOR TABLE t1;
+/* pub # */ CREATE PUBLICATION pub2 FOR TABLE t2 WITH (publish = 'truncate');
+/* pub # */ CREATE PUBLICATION pub3a FOR TABLE t3 WITH (publish = 'truncate');
+/* pub # */ CREATE PUBLICATION pub3b FOR TABLE t3 WHERE (e > 5);
+]]>
Create subscriptions for the publications. The subscription
sub3 subscribes to both pub3a and
pub3b . All 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
-test_sub=# CREATE SUBSCRIPTION sub3
-test_sub-# CONNECTION 'host=localhost dbname=test_pub application_name=sub3'
-test_sub-# PUBLICATION pub3a, pub3b;
-CREATE SUBSCRIPTION
+/* sub # */ CREATE SUBSCRIPTION sub1
+/* sub - */ CONNECTION 'host=localhost dbname=test_pub application_name=sub1'
+/* sub - */ PUBLICATION pub1;
+/* sub # */ CREATE SUBSCRIPTION sub2
+/* sub - */ CONNECTION 'host=localhost dbname=test_pub application_name=sub2'
+/* sub - */ PUBLICATION pub2;
+/* sub # */ CREATE SUBSCRIPTION sub3
+/* sub - */ CONNECTION 'host=localhost dbname=test_pub application_name=sub3'
+/* sub - */ PUBLICATION pub3a, pub3b;
Observe that initial table data is copied, regardless of the
publish operation of the publication.
-test_sub=# SELECT * FROM t1;
+/* sub # */ SELECT * FROM t1;
a | b
---+-------
1 | one
3 | three
(3 rows)
-test_sub=# SELECT * FROM t2;
+/* sub # */ SELECT * FROM t2;
c | d
---+---
1 | A
it means the copied table t3 contains all rows even when
they do not match the row filter of publication pub3b .
-test_sub=# SELECT * FROM t3;
+/* sub # */ SELECT * FROM t3;
e | f
---+-----
1 | i
Insert more data to the tables at the publisher side.
-test_pub=# INSERT INTO t1 VALUES (4, 'four'), (5, 'five'), (6, 'six');
-INSERT 0 3
-test_pub=# INSERT INTO t2 VALUES (4, 'D'), (5, 'E'), (6, 'F');
-INSERT 0 3
-test_pub=# INSERT INTO t3 VALUES (4, 'iv'), (5, 'v'), (6, 'vi');
-INSERT 0 3
+/* pub # */ INSERT INTO t1 VALUES (4, 'four'), (5, 'five'), (6, 'six');
+/* pub # */ INSERT INTO t2 VALUES (4, 'D'), (5, 'E'), (6, 'F');
+/* pub # */ INSERT INTO t3 VALUES (4, 'iv'), (5, 'v'), (6, 'vi');
Now the publisher side data looks like:
-test_pub=# SELECT * FROM t1;
+/* pub # */ SELECT * FROM t1;
a | b
---+-------
1 | one
6 | six
(6 rows)
-test_pub=# SELECT * FROM t2;
+/* pub # */ SELECT * FROM t2;
c | d
---+---
1 | A
6 | F
(6 rows)
-test_pub=# SELECT * FROM t3;
+/* pub # */ SELECT * FROM t3;
e | f
---+-----
1 | i
only replicate data that matches the row filter of pub3b .
Now the subscriber side data looks like:
-test_sub=# SELECT * FROM t1;
+/* sub # */ SELECT * FROM t1;
a | b
---+-------
1 | one
6 | six
(6 rows)
-test_sub=# SELECT * FROM t2;
+/* sub # */ SELECT * FROM t2;
c | d
---+---
1 | A
3 | C
(3 rows)
-test_sub=# SELECT * FROM t3;
+/* sub # */ SELECT * FROM t3;
e | f
---+-----
1 | i
First, create a publication for the examples to use.
-test_pub=# CREATE PUBLICATION pub1 FOR ALL TABLES;
-CREATE PUBLICATION
+/* pub # */ CREATE PUBLICATION pub1 FOR ALL TABLES;
Example 1: Where the subscription says connect = false
Create the subscription.
-test_sub=# CREATE SUBSCRIPTION sub1
-test_sub-# CONNECTION 'host=localhost dbname=test_pub'
-test_sub-# PUBLICATION pub1
-test_sub-# WITH (connect=false);
+/* sub # */ CREATE SUBSCRIPTION sub1
+/* sub - */ CONNECTION 'host=localhost dbname=test_pub'
+/* sub - */ PUBLICATION pub1
+/* sub - */ WITH (connect=false);
WARNING: subscription was created, but is not connected
HINT: To initiate replication, you must manually create the replication slot, enable the subscription, and refresh the subscription.
-CREATE SUBSCRIPTION
specified during CREATE SUBSCRIPTION , the name of the
slot to create is same as the subscription name, e.g. "sub1".
-test_pub=# SELECT * FROM pg_create_logical_replication_slot('sub1', 'pgoutput');
+/* pub # */ SELECT * FROM pg_create_logical_replication_slot('sub1', 'pgoutput');
slot_name | lsn
-----------+-----------
sub1 | 0/19404D0
On the subscriber, complete the activation of the subscription. After
this the tables of pub1 will start replicating.
-test_sub=# ALTER SUBSCRIPTION sub1 ENABLE;
-ALTER SUBSCRIPTION
-test_sub=# ALTER SUBSCRIPTION sub1 REFRESH PUBLICATION;
-ALTER SUBSCRIPTION
+/* sub # */ ALTER SUBSCRIPTION sub1 ENABLE;
+/* sub # */ ALTER SUBSCRIPTION sub1 REFRESH PUBLICATION;
Create the subscription.
-test_sub=# CREATE SUBSCRIPTION sub1
-test_sub-# CONNECTION 'host=localhost dbname=test_pub'
-test_sub-# PUBLICATION pub1
-test_sub-# WITH (connect=false, slot_name='myslot');
+/* sub # */ CREATE SUBSCRIPTION sub1
+/* sub - */ CONNECTION 'host=localhost dbname=test_pub'
+/* sub - */ PUBLICATION pub1
+/* sub - */ WITH (connect=false, slot_name='myslot');
WARNING: subscription was created, but is not connected
HINT: To initiate replication, you must manually create the replication slot, enable the subscription, and refresh the subscription.
-CREATE SUBSCRIPTION
On the publisher, manually create a slot using the same name that was
specified during CREATE SUBSCRIPTION , e.g. "myslot".
-test_pub=# SELECT * FROM pg_create_logical_replication_slot('myslot', 'pgoutput');
+/* pub # */ SELECT * FROM pg_create_logical_replication_slot('myslot', 'pgoutput');
slot_name | lsn
-----------+-----------
myslot | 0/19059A0
On the subscriber, the remaining subscription activation steps are the
same as before.
-test_sub=# ALTER SUBSCRIPTION sub1 ENABLE;
-ALTER SUBSCRIPTION
-test_sub=# ALTER SUBSCRIPTION sub1 REFRESH PUBLICATION;
-ALTER SUBSCRIPTION
+/* sub # */ ALTER SUBSCRIPTION sub1 ENABLE;
+/* sub # */ ALTER SUBSCRIPTION sub1 REFRESH PUBLICATION;
enabled = false , and
create_slot = false are also needed.
-test_sub=# CREATE SUBSCRIPTION sub1
-test_sub-# CONNECTION 'host=localhost dbname=test_pub'
-test_sub-# PUBLICATION pub1
-test_sub-# WITH (slot_name=NONE, enabled=false, create_slot=false);
-CREATE SUBSCRIPTION
+/* sub # */ CREATE SUBSCRIPTION sub1
+/* sub - */ CONNECTION 'host=localhost dbname=test_pub'
+/* sub - */ PUBLICATION pub1
+/* sub - */ WITH (slot_name=NONE, enabled=false, create_slot=false);
On the publisher, manually create a slot using any name, e.g. "myslot".
-test_pub=# SELECT * FROM pg_create_logical_replication_slot('myslot', 'pgoutput');
+/* pub # */ SELECT * FROM pg_create_logical_replication_slot('myslot', 'pgoutput');
slot_name | lsn
-----------+-----------
myslot | 0/1905930
On the subscriber, associate the subscription with the slot name just
created.
-test_sub=# ALTER SUBSCRIPTION sub1 SET (slot_name='myslot');
-ALTER SUBSCRIPTION
+/* sub # */ ALTER SUBSCRIPTION sub1 SET (slot_name='myslot');
The remaining subscription activation steps are same as before.
-test_sub=# ALTER SUBSCRIPTION sub1 ENABLE;
-ALTER SUBSCRIPTION
-test_sub=# ALTER SUBSCRIPTION sub1 REFRESH PUBLICATION;
-ALTER SUBSCRIPTION
+/* sub # */ ALTER SUBSCRIPTION sub1 ENABLE;
+/* sub # */ ALTER SUBSCRIPTION sub1 REFRESH PUBLICATION;
will return the relevant replication slots associated with the
failover-enabled subscriptions.
-test_sub=# SELECT
+/* sub # */ SELECT
array_agg(quote_literal(s.subslotname)) AS slots
FROM pg_subscription s
WHERE s.subfailover AND
as they will either be dropped or re-created on the new primary server in those
cases.
-test_sub=# SELECT
+/* sub # */ SELECT
array_agg(quote_literal(slot_name)) AS slots
FROM
(
Check that the logical replication slots identified above exist on
the standby server and are ready for failover.
-test_standby=# SELECT slot_name, (synced AND NOT temporary AND NOT conflicting) AS failover_ready
+/* standby # */ SELECT slot_name, (synced AND NOT temporary AND NOT conflicting) AS failover_ready
FROM pg_replication_slots
WHERE slot_name IN
('sub1','sub2','sub3', 'pg_16394_sync_16385_7394666715149055164');
Create some tables to be used in the following examples.
-test_pub=# CREATE TABLE t1(a int, b int, c text, PRIMARY KEY(a,c));
-CREATE TABLE
-test_pub=# CREATE TABLE t2(d int, e int, f int, PRIMARY KEY(d));
-CREATE TABLE
-test_pub=# CREATE TABLE t3(g int, h int, i int, PRIMARY KEY(g));
-CREATE TABLE
+/* pub # */ CREATE TABLE t1(a int, b int, c text, PRIMARY KEY(a,c));
+/* pub # */ CREATE TABLE t2(d int, e int, f int, PRIMARY KEY(d));
+/* pub # */ CREATE TABLE t3(g int, h int, i int, PRIMARY KEY(g));
p2 has two tables. Table t1 has no row
filter, and table t2 has a row filter. Publication
p3 has two tables, and both of them have a row filter.
-test_pub=# CREATE PUBLICATION p1 FOR TABLE t1 WHERE (a > 5 AND c = 'NSW');
-CREATE PUBLICATION
-test_pub=# CREATE PUBLICATION p2 FOR TABLE t1, t2 WHERE (e = 99);
-CREATE PUBLICATION
-test_pub=# CREATE PUBLICATION p3 FOR TABLE t2 WHERE (d = 10), t3 WHERE (g = 10);
-CREATE PUBLICATION
-
+
+/* pub # */ CREATE PUBLICATION p1 FOR TABLE t1 WHERE (a > 5 AND c = 'NSW');
+/* pub # */ CREATE PUBLICATION p2 FOR TABLE t1, t2 WHERE (e = 99);
+/* pub # */ CREATE PUBLICATION p3 FOR TABLE t2 WHERE (d = 10), t3 WHERE (g = 10);
+]]>
psql can be used to show the row filter expressions (if
defined) for each publication.
-test_pub=# \dRp+
- Publication p1
+/* pub # */ \dRp+
+ Publication p1
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
----------+------------+---------+---------+---------+-----------+----------
postgres | f | t | t | t | t | f
Tables:
- "public.t1" WHERE ((a > 5) AND (c = 'NSW'::text))
+ "public.t1" WHERE ((a > 5) AND (c = 'NSW'::text))
- Publication p2
+ Publication p2
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
----------+------------+---------+---------+---------+-----------+----------
postgres | f | t | t | t | t | f
Tables:
- "public.t1"
- "public.t2" WHERE (e = 99)
+ "public.t1"
+ "public.t2" WHERE (e = 99)
- Publication p3
+ Publication p3
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
----------+------------+---------+---------+---------+-----------+----------
postgres | f | t | t | t | t | f
Tables:
- "public.t2" WHERE (d = 10)
- "public.t3" WHERE (g = 10)
-
+ "public.t2" WHERE (d = 10)
+ "public.t3" WHERE (g = 10)
+]]>
psql can be used to show the row filter expressions (if
of two publications, but has a row filter only in p1 .
See that table t2 is a member of two publications, and
has a different row filter in each of them.
-test_pub=# \d t1
+/* pub # */ \d t1
Table "public.t1"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
"p1" WHERE ((a > 5) AND (c = 'NSW'::text))
"p2"
-test_pub=# \d t2
+/* pub # */ \d t2
Table "public.t2"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
"p2" WHERE (e = 99)
"p3" WHERE (d = 10)
-test_pub=# \d t3
+/* pub # */ \d t3
Table "public.t3"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
"t3_pkey" PRIMARY KEY, btree (g)
Publications:
"p3" WHERE (g = 10)
-
+]]>
On the subscriber node, create a table t1 with the same
definition as the one on the publisher, and also create the subscription
s1 that subscribes to the publication p1 .
-test_sub=# CREATE TABLE t1(a int, b int, c text, PRIMARY KEY(a,c));
-CREATE TABLE
-test_sub=# CREATE SUBSCRIPTION s1
-test_sub-# CONNECTION 'host=localhost dbname=test_pub application_name=s1'
-test_sub-# PUBLICATION p1;
-CREATE SUBSCRIPTION
+/* sub # */ CREATE TABLE t1(a int, b int, c text, PRIMARY KEY(a,c));
+/* sub # */ CREATE SUBSCRIPTION s1
+/* sub - */ CONNECTION 'host=localhost dbname=test_pub application_name=s1'
+/* sub - */ PUBLICATION p1;
Insert some rows. Only the rows satisfying the t1 WHERE
clause of publication p1 are replicated.
-test_pub=# INSERT INTO t1 VALUES (2, 102, 'NSW');
-INSERT 0 1
-test_pub=# INSERT INTO t1 VALUES (3, 103, 'QLD');
-INSERT 0 1
-test_pub=# INSERT INTO t1 VALUES (4, 104, 'VIC');
-INSERT 0 1
-test_pub=# INSERT INTO t1 VALUES (5, 105, 'ACT');
-INSERT 0 1
-test_pub=# INSERT INTO t1 VALUES (6, 106, 'NSW');
-INSERT 0 1
-test_pub=# INSERT INTO t1 VALUES (7, 107, 'NT');
-INSERT 0 1
-test_pub=# INSERT INTO t1 VALUES (8, 108, 'QLD');
-INSERT 0 1
-test_pub=# INSERT INTO t1 VALUES (9, 109, 'NSW');
-INSERT 0 1
-
-test_pub=# SELECT * FROM t1;
+/* pub # */ INSERT INTO t1 VALUES (2, 102, 'NSW');
+/* pub # */ INSERT INTO t1 VALUES (3, 103, 'QLD');
+/* pub # */ INSERT INTO t1 VALUES (4, 104, 'VIC');
+/* pub # */ INSERT INTO t1 VALUES (5, 105, 'ACT');
+/* pub # */ INSERT INTO t1 VALUES (6, 106, 'NSW');
+/* pub # */ INSERT INTO t1 VALUES (7, 107, 'NT');
+/* pub # */ INSERT INTO t1 VALUES (8, 108, 'QLD');
+/* pub # */ INSERT INTO t1 VALUES (9, 109, 'NSW');
+
+/* pub # */ SELECT * FROM t1;
a | b | c
---+-----+-----
2 | 102 | NSW
(8 rows)
-test_sub=# SELECT * FROM t1;
+/* sub # */ SELECT * FROM t1;
a | b | c
---+-----+-----
6 | 106 | NSW
p1 . The UPDATE replicates
the change as normal.
-test_pub=# UPDATE t1 SET b = 999 WHERE a = 6;
-UPDATE 1
+/* pub # */ UPDATE t1 SET b = 999 WHERE a = 6;
-test_pub=# SELECT * FROM t1;
+/* pub # */ SELECT * FROM t1;
a | b | c
---+-----+-----
2 | 102 | NSW
(8 rows)
-test_sub=# SELECT * FROM t1;
+/* sub # */ SELECT * FROM t1;
a | b | c
---+-----+-----
9 | 109 | NSW
transformed into an INSERT and the change is replicated.
See the new row on the subscriber.
-test_pub=# UPDATE t1 SET a = 555 WHERE a = 2;
-UPDATE 1
+/* pub # */ UPDATE t1 SET a = 555 WHERE a = 2;
-test_pub=# SELECT * FROM t1;
+/* pub # */ SELECT * FROM t1;
a | b | c
-----+-----+-----
3 | 103 | QLD
(8 rows)
-test_sub=# SELECT * FROM t1;
+/* sub # */ SELECT * FROM t1;
a | b | c
-----+-----+-----
9 | 109 | NSW
transformed into a DELETE and the change is replicated.
See that the row is removed from the subscriber.
-test_pub=# UPDATE t1 SET c = 'VIC' WHERE a = 9;
-UPDATE 1
+/* pub # */ UPDATE t1 SET c = 'VIC' WHERE a = 9;
-test_pub=# SELECT * FROM t1;
+/* pub # */ SELECT * FROM t1;
a | b | c
-----+-----+-----
3 | 103 | QLD
(8 rows)
-test_sub=# SELECT * FROM t1;
+/* sub # */ SELECT * FROM t1;
a | b | c
-----+-----+-----
6 | 999 | NSW
Create a partitioned table on the publisher.
-test_pub=# CREATE TABLE parent(a int PRIMARY KEY) PARTITION BY RANGE(a);
-CREATE TABLE
-test_pub=# CREATE TABLE child PARTITION OF parent DEFAULT;
-CREATE TABLE
+/* pub # */ CREATE TABLE parent(a int PRIMARY KEY) PARTITION BY RANGE(a);
+/* pub # */ CREATE TABLE child PARTITION OF parent DEFAULT;
Create the same tables on the subscriber.
-test_sub=# CREATE TABLE parent(a int PRIMARY KEY) PARTITION BY RANGE(a);
-CREATE TABLE
-test_sub=# CREATE TABLE child PARTITION OF parent DEFAULT;
-CREATE TABLE
+/* sub # */ CREATE TABLE parent(a int PRIMARY KEY) PARTITION BY RANGE(a);
+/* sub # */ CREATE TABLE child PARTITION OF parent DEFAULT;
publication parameter publish_via_partition_root is set
as true. There are row filters defined on both the partitioned table
(parent ), and on the partition (child ).
-test_pub=# CREATE PUBLICATION p4 FOR TABLE parent WHERE (a < 5), child WHERE (a >= 5)
-test_pub-# WITH (publish_via_partition_root=true);
-CREATE PUBLICATION
-
-test_sub=# CREATE SUBSCRIPTION s4
-test_sub-# CONNECTION 'host=localhost dbname=test_pub application_name=s4'
-test_sub-# PUBLICATION p4;
-CREATE SUBSCRIPTION
+
+/* pub # */ CREATE PUBLICATION p4 FOR TABLE parent WHERE (a < 5), child WHERE (a >= 5)
+/* pub - */ WITH (publish_via_partition_root=true);
+]]>
+/* sub # */ CREATE SUBSCRIPTION s4
+/* sub - */ CONNECTION 'host=localhost dbname=test_pub application_name=s4'
+/* sub - */ PUBLICATION p4;
parent (because publish_via_partition_root
is true).
-test_pub=# INSERT INTO parent VALUES (2), (4), (6);
-INSERT 0 3
-test_pub=# INSERT INTO child VALUES (3), (5), (7);
-INSERT 0 3
+/* pub # */ INSERT INTO parent VALUES (2), (4), (6);
+/* pub # */ INSERT INTO child VALUES (3), (5), (7);
-test_pub=# SELECT * FROM parent ORDER BY a;
+/* pub # */ SELECT * FROM parent ORDER BY a;
a
---
2
(6 rows)
-test_sub=# SELECT * FROM parent ORDER BY a;
+/* sub # */ SELECT * FROM parent ORDER BY a;
a
---
2
Repeat the same test, but with a different value for publish_via_partition_root .
The publication parameter publish_via_partition_root is
set as false. A row filter is defined on the partition (child ).
+
+/* pub # */ DROP PUBLICATION p4;
+/* pub # */ CREATE PUBLICATION p4 FOR TABLE parent, child WHERE (a >= 5)
+/* pub - */ WITH (publish_via_partition_root=false);
+]]>
-test_pub=# DROP PUBLICATION p4;
-DROP PUBLICATION
-test_pub=# CREATE PUBLICATION p4 FOR TABLE parent, child WHERE (a >= 5)
-test_pub-# WITH (publish_via_partition_root=false);
-CREATE PUBLICATION
-
-test_sub=# ALTER SUBSCRIPTION s4 REFRESH PUBLICATION;
-ALTER SUBSCRIPTION
+/* sub # */ ALTER SUBSCRIPTION s4 REFRESH PUBLICATION;
row filter of child (because
publish_via_partition_root is false).
-test_pub=# TRUNCATE parent;
-TRUNCATE TABLE
-test_pub=# INSERT INTO parent VALUES (2), (4), (6);
-INSERT 0 3
-test_pub=# INSERT INTO child VALUES (3), (5), (7);
-INSERT 0 3
+/* pub # */ TRUNCATE parent;
+/* pub # */ INSERT INTO parent VALUES (2), (4), (6);
+/* pub # */ INSERT INTO child VALUES (3), (5), (7);
-test_pub=# SELECT * FROM parent ORDER BY a;
+/* pub # */ SELECT * FROM parent ORDER BY a;
a
---
2
(6 rows)
-test_sub=# SELECT * FROM child ORDER BY a;
+/* sub # */ SELECT * FROM child ORDER BY a;
a
---
5
Create a table t1 to be used in the following example.
-test_pub=# CREATE TABLE t1(id int, a text, b text, c text, d text, e text, PRIMARY KEY(id));
-CREATE TABLE
+/* pub # */ CREATE TABLE t1(id int, a text, b text, c text, d text, e text, PRIMARY KEY(id));
replicated. Notice that the order of column names in the column list does
not matter.
-test_pub=# CREATE PUBLICATION p1 FOR TABLE t1 (id, b, a, d);
-CREATE PUBLICATION
+/* pub # */ CREATE PUBLICATION p1 FOR TABLE t1 (id, b, a, d);
psql can be used to show the column lists (if defined)
for each publication.
-test_pub=# \dRp+
+/* pub # */ \dRp+
Publication p1
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
----------+------------+---------+---------+---------+-----------+----------
psql can be used to show the column lists (if defined)
for each table.
-test_pub=# \d t1
+/* pub # */ \d t1
Table "public.t1"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
s1 that subscribes to the publication
p1 .
-test_sub=# CREATE TABLE t1(id int, b text, a text, d text, PRIMARY KEY(id));
-CREATE TABLE
-test_sub=# CREATE SUBSCRIPTION s1
-test_sub-# CONNECTION 'host=localhost dbname=test_pub application_name=s1'
-test_sub-# PUBLICATION p1;
-CREATE SUBSCRIPTION
+/* sub # */ CREATE TABLE t1(id int, b text, a text, d text, PRIMARY KEY(id));
+/* sub # */ CREATE SUBSCRIPTION s1
+/* sub - */ CONNECTION 'host=localhost dbname=test_pub application_name=s1'
+/* sub - */ PUBLICATION p1;
On the publisher node, insert some rows to table t1 .
-test_pub=# INSERT INTO t1 VALUES(1, 'a-1', 'b-1', 'c-1', 'd-1', 'e-1');
-INSERT 0 1
-test_pub=# INSERT INTO t1 VALUES(2, 'a-2', 'b-2', 'c-2', 'd-2', 'e-2');
-INSERT 0 1
-test_pub=# INSERT INTO t1 VALUES(3, 'a-3', 'b-3', 'c-3', 'd-3', 'e-3');
-INSERT 0 1
-test_pub=# SELECT * FROM t1 ORDER BY id;
+/* pub # */ INSERT INTO t1 VALUES(1, 'a-1', 'b-1', 'c-1', 'd-1', 'e-1');
+/* pub # */ INSERT INTO t1 VALUES(2, 'a-2', 'b-2', 'c-2', 'd-2', 'e-2');
+/* pub # */ INSERT INTO t1 VALUES(3, 'a-3', 'b-3', 'c-3', 'd-3', 'e-3');
+/* pub # */ SELECT * FROM t1 ORDER BY id;
id | a | b | c | d | e
----+-----+-----+-----+-----+-----
1 | a-1 | b-1 | c-1 | d-1 | e-1
Only data from the column list of publication p1 is
replicated.
-test_sub=# SELECT * FROM t1 ORDER BY id;
+/* sub # */ SELECT * FROM t1 ORDER BY id;
id | b | a | d
----+-----+-----+-----
1 | b-1 | a-1 | d-1
For example, note below that subscriber table generated column value comes from the
subscriber column's calculation.
-test_pub=# CREATE TABLE tab_gen_to_gen (a int, b int GENERATED ALWAYS AS (a + 1) STORED);
-CREATE TABLE
-test_pub=# INSERT INTO tab_gen_to_gen VALUES (1),(2),(3);
-INSERT 0 3
-test_pub=# CREATE PUBLICATION pub1 FOR TABLE tab_gen_to_gen;
-CREATE PUBLICATION
-test_pub=# SELECT * FROM tab_gen_to_gen;
+/* pub # */ CREATE TABLE tab_gen_to_gen (a int, b int GENERATED ALWAYS AS (a + 1) STORED);
+/* pub # */ INSERT INTO tab_gen_to_gen VALUES (1),(2),(3);
+/* pub # */ CREATE PUBLICATION pub1 FOR TABLE tab_gen_to_gen;
+/* pub # */ SELECT * FROM tab_gen_to_gen;
a | b
---+---
1 | 2
3 | 4
(3 rows)
-test_sub=# CREATE TABLE tab_gen_to_gen (a int, b int GENERATED ALWAYS AS (a * 100) STORED);
-CREATE TABLE
-test_sub=# CREATE SUBSCRIPTION sub1 CONNECTION 'dbname=test_pub' PUBLICATION pub1;
-CREATE SUBSCRIPTION
-test_sub=# SELECT * from tab_gen_to_gen;
+/* sub # */ CREATE TABLE tab_gen_to_gen (a int, b int GENERATED ALWAYS AS (a * 100) STORED);
+/* sub # */ CREATE SUBSCRIPTION sub1 CONNECTION 'dbname=test_pub' PUBLICATION pub1;
+/* sub # */ SELECT * from tab_gen_to_gen;
a | b
---+----
1 | 100
ALTER SUBSCRIPTION ... DISABLE ,
e.g.:
-node2=# ALTER SUBSCRIPTION sub1_node1_node2 DISABLE;
-ALTER SUBSCRIPTION
+/* node2 # */ ALTER SUBSCRIPTION sub1_node1_node2 DISABLE;
and now, e.g.:
-node2=# CREATE TABLE distributors (did integer PRIMARY KEY, name varchar(40));
-CREATE TABLE
+/* node2 # */ CREATE TABLE distributors (did integer PRIMARY KEY, name varchar(40));
ALTER SUBSCRIPTION ... ENABLE ,
e.g.:
-node2=# ALTER SUBSCRIPTION sub1_node1_node2 ENABLE;
-ALTER SUBSCRIPTION
+/* node2 # */ ALTER SUBSCRIPTION sub1_node1_node2 ENABLE;
ALTER SUBSCRIPTION ... REFRESH PUBLICATION ,
e.g.:
-node2=# ALTER SUBSCRIPTION sub1_node1_node2 REFRESH PUBLICATION;
-ALTER SUBSCRIPTION
+/* node2 # */ ALTER SUBSCRIPTION sub1_node1_node2 REFRESH PUBLICATION;
ALTER SUBSCRIPTION ... DISABLE ,
e.g.:
-node2=# ALTER SUBSCRIPTION sub1_node1_node2 DISABLE;
-ALTER SUBSCRIPTION
+/* node2 # */ ALTER SUBSCRIPTION sub1_node1_node2 DISABLE;
ALTER SUBSCRIPTION ... DISABLE ,
e.g.:
-node3=# ALTER SUBSCRIPTION sub1_node2_node3 DISABLE;
-ALTER SUBSCRIPTION
+/* node3 # */ ALTER SUBSCRIPTION sub1_node2_node3 DISABLE;
and now, e.g.:
-node2=# CREATE TABLE distributors (did integer PRIMARY KEY, name varchar(40));
-CREATE TABLE
+/* node2 # */ CREATE TABLE distributors (did integer PRIMARY KEY, name varchar(40));
ALTER SUBSCRIPTION ... ENABLE ,
e.g.:
-node2=# ALTER SUBSCRIPTION sub1_node1_node2 ENABLE;
-ALTER SUBSCRIPTION
+/* node2 # */ ALTER SUBSCRIPTION sub1_node1_node2 ENABLE;
ALTER SUBSCRIPTION ... REFRESH PUBLICATION ,
e.g.:
-node2=# ALTER SUBSCRIPTION sub1_node1_node2 REFRESH PUBLICATION;
-ALTER SUBSCRIPTION
+/* node2 # */ ALTER SUBSCRIPTION sub1_node1_node2 REFRESH PUBLICATION;
and now,
e.g.:
-node3=# CREATE TABLE distributors (did integer PRIMARY KEY, name varchar(40));
-CREATE TABLE
+/* node3 # */ CREATE TABLE distributors (did integer PRIMARY KEY, name varchar(40));
ALTER SUBSCRIPTION ... ENABLE ,
e.g.:
-node3=# ALTER SUBSCRIPTION sub1_node2_node3 ENABLE;
-ALTER SUBSCRIPTION
+/* node3 # */ ALTER SUBSCRIPTION sub1_node2_node3 ENABLE;
ALTER SUBSCRIPTION ... REFRESH PUBLICATION ,
e.g.:
-node3=# ALTER SUBSCRIPTION sub1_node2_node3 REFRESH PUBLICATION;
-ALTER SUBSCRIPTION
+/* node3 # */ ALTER SUBSCRIPTION sub1_node2_node3 REFRESH PUBLICATION;
ALTER SUBSCRIPTION ... DISABLE ,
e.g.:
-node2=# ALTER SUBSCRIPTION sub1_node1_node2 DISABLE;
-ALTER SUBSCRIPTION
+/* node2 # */ ALTER SUBSCRIPTION sub1_node1_node2 DISABLE;
ALTER SUBSCRIPTION ... ENABLE ,
e.g.:
-node2=# ALTER SUBSCRIPTION sub1_node1_node2 ENABLE;
-ALTER SUBSCRIPTION
+/* node2 # */ ALTER SUBSCRIPTION sub1_node1_node2 ENABLE;
node2 between
and now, e.g.:
-node1=# CREATE TABLE distributors (did integer PRIMARY KEY, name varchar(40));
-CREATE TABLE
+/* node1 # */ CREATE TABLE distributors (did integer PRIMARY KEY, name varchar(40));
ALTER SUBSCRIPTION ... REFRESH PUBLICATION ,
e.g.:
-node1=# ALTER SUBSCRIPTION sub1_node2_node1 REFRESH PUBLICATION;
-ALTER SUBSCRIPTION
+/* node1 # */ ALTER SUBSCRIPTION sub1_node2_node1 REFRESH PUBLICATION;
ALTER SUBSCRIPTION ... DISABLE ,
e.g.:
-node1=# ALTER SUBSCRIPTION sub1_node2_node1 DISABLE;
-ALTER SUBSCRIPTION
+/* node1 # */ ALTER SUBSCRIPTION sub1_node2_node1 DISABLE;
ALTER SUBSCRIPTION ... ENABLE ,
e.g.:
-node1=# ALTER SUBSCRIPTION sub1_node2_node1 ENABLE;
-ALTER SUBSCRIPTION
+/* node1 # */ ALTER SUBSCRIPTION sub1_node2_node1 ENABLE;
the upgraded node1 between
and now, e.g.:
-node2=# CREATE TABLE distributors (did integer PRIMARY KEY, name varchar(40));
-CREATE TABLE
+/* node2 # */ CREATE TABLE distributors (did integer PRIMARY KEY, name varchar(40));
ALTER SUBSCRIPTION ... REFRESH PUBLICATION ,
e.g.:
-node2=# ALTER SUBSCRIPTION sub1_node1_node2 REFRESH PUBLICATION;
-ALTER SUBSCRIPTION
+/* node2 # */ ALTER SUBSCRIPTION sub1_node1_node2 REFRESH PUBLICATION;