Fix the intermittent buildfarm failures in 031_column_list.

The reason was that the ALTER SUBSCRIPTION .. SET PUBLICATION will lead to
the restarting of apply worker and after the restart, the apply worker
will use the existing slot and replication origin corresponding to the
subscription. Now, it is possible that before restart the origin has not
been updated and the WAL start location points to a location before where
PUBLICATION exists which can lead to the error "publication ... does not
exist".

Fix it by recreating the subscription as a newly created subscription will
start processing WAL from the recent WAL location and will see the
required publication.

This behavior has existed from the time logical replication was introduced
but is exposed by this test and we have started a discussion for a better
fix for this problem.

As per Buildfarm

Diagnosed-by: Amit Kapila
Author: Vignesh C
Discussion: https://postgr.es/m/3307255.1706911634@sss.pgh.pa.us
This commit is contained in:
Amit Kapila 2024-02-22 12:06:44 +05:30
parent fbc93b8b5f
commit b6df0798a5
1 changed files with 28 additions and 15 deletions

View File

@ -370,7 +370,8 @@ $node_subscriber->safe_psql(
$node_subscriber->safe_psql(
'postgres', qq(
ALTER SUBSCRIPTION sub1 SET PUBLICATION pub2, pub3
DROP SUBSCRIPTION sub1;
CREATE SUBSCRIPTION sub1 CONNECTION '$publisher_connstr' PUBLICATION pub2, pub3
));
$node_subscriber->wait_for_subscription_sync($node_publisher, 'sub1');
@ -411,7 +412,8 @@ $node_subscriber->safe_psql(
$node_subscriber->safe_psql(
'postgres', qq(
ALTER SUBSCRIPTION sub1 SET PUBLICATION pub4
DROP SUBSCRIPTION sub1;
CREATE SUBSCRIPTION sub1 CONNECTION '$publisher_connstr' PUBLICATION pub4
));
$node_subscriber->wait_for_subscription_sync;
@ -487,7 +489,8 @@ $node_subscriber->safe_psql(
$node_subscriber->safe_psql(
'postgres', qq(
ALTER SUBSCRIPTION sub1 SET PUBLICATION pub5
DROP SUBSCRIPTION sub1;
CREATE SUBSCRIPTION sub1 CONNECTION '$publisher_connstr' PUBLICATION pub5
));
$node_subscriber->wait_for_subscription_sync;
@ -601,10 +604,12 @@ $node_publisher->safe_psql(
ALTER PUBLICATION pub6 ADD TABLE test_part_a_2 (b);
));
# add the publication to our subscription, wait for sync to complete
# create the subscription for the above publication, wait for sync to
# complete
$node_subscriber->safe_psql(
'postgres', qq(
ALTER SUBSCRIPTION sub1 SET PUBLICATION pub6
DROP SUBSCRIPTION sub1;
CREATE SUBSCRIPTION sub1 CONNECTION '$publisher_connstr' PUBLICATION pub6
));
$node_subscriber->wait_for_subscription_sync;
@ -667,10 +672,12 @@ $node_publisher->safe_psql(
CREATE PUBLICATION pub7 FOR TABLE test_part_b (a, b) WITH (publish_via_partition_root = true);
));
# add the publication to our subscription, wait for sync to complete
# create the subscription for the above publication, wait for sync to
# complete
$node_subscriber->safe_psql(
'postgres', qq(
ALTER SUBSCRIPTION sub1 SET PUBLICATION pub7
DROP SUBSCRIPTION sub1;
CREATE SUBSCRIPTION sub1 CONNECTION '$publisher_connstr' PUBLICATION pub7
));
$node_subscriber->wait_for_subscription_sync;
@ -737,7 +744,8 @@ $node_publisher->safe_psql(
ALTER PUBLICATION pub8 ADD TABLE test_part_c_2 (a,b);
));
# add the publication to our subscription, wait for sync to complete
# create the subscription for the above publication, wait for sync to
# complete
$node_subscriber->safe_psql(
'postgres', qq(
DROP SUBSCRIPTION sub1;
@ -835,10 +843,12 @@ $node_publisher->safe_psql(
CREATE PUBLICATION pub9 FOR TABLE test_part_d (a) WITH (publish_via_partition_root = true);
));
# add the publication to our subscription, wait for sync to complete
# create the subscription for the above publication, wait for sync to
# complete
$node_subscriber->safe_psql(
'postgres', qq(
ALTER SUBSCRIPTION sub1 SET PUBLICATION pub9
DROP SUBSCRIPTION sub1;
CREATE SUBSCRIPTION sub1 CONNECTION '$publisher_connstr' PUBLICATION pub9
));
$node_subscriber->wait_for_subscription_sync;
@ -880,8 +890,8 @@ $node_publisher->safe_psql(
$node_subscriber->safe_psql(
'postgres', qq(
CREATE TABLE test_mix_2 (a int PRIMARY KEY, b int, c int);
ALTER SUBSCRIPTION sub1 SET PUBLICATION pub_mix_3, pub_mix_4;
ALTER SUBSCRIPTION sub1 REFRESH PUBLICATION;
DROP SUBSCRIPTION sub1;
CREATE SUBSCRIPTION sub1 CONNECTION '$publisher_connstr' PUBLICATION pub_mix_3, pub_mix_4;
));
$node_subscriber->wait_for_subscription_sync;
@ -1022,7 +1032,8 @@ $node_subscriber->safe_psql(
CREATE TABLE s1.t (a int, b int, c int) PARTITION BY RANGE (a);
CREATE TABLE t_1 PARTITION OF s1.t FOR VALUES FROM (1) TO (10);
ALTER SUBSCRIPTION sub1 SET PUBLICATION pub1, pub2;
DROP SUBSCRIPTION sub1;
CREATE SUBSCRIPTION sub1 CONNECTION '$publisher_connstr' PUBLICATION pub1, pub2;
));
$node_subscriber->wait_for_subscription_sync;
@ -1090,7 +1101,8 @@ $node_subscriber->safe_psql(
PARTITION BY RANGE (a);
CREATE TABLE t_2 PARTITION OF t_1 FOR VALUES FROM (1) TO (10);
ALTER SUBSCRIPTION sub1 SET PUBLICATION pub3;
DROP SUBSCRIPTION sub1;
CREATE SUBSCRIPTION sub1 CONNECTION '$publisher_connstr' PUBLICATION pub3;
));
$node_subscriber->wait_for_subscription_sync;
@ -1138,7 +1150,8 @@ $node_subscriber->safe_psql(
PARTITION BY RANGE (a);
CREATE TABLE t_2 PARTITION OF t_1 FOR VALUES FROM (1) TO (10);
ALTER SUBSCRIPTION sub1 SET PUBLICATION pub4;
DROP SUBSCRIPTION sub1;
CREATE SUBSCRIPTION sub1 CONNECTION '$publisher_connstr' PUBLICATION pub4;
));
$node_subscriber->wait_for_subscription_sync;