|
1 | 1 |
|
2 | 2 | # Copyright (c) 2021-2025, PostgreSQL Global Development Group
|
3 | 3 |
|
4 |
| -# This test checks behaviour of ALTER SUBSCRIPTION ... ADD/DROP PUBLICATION |
| 4 | +# This test checks behaviour of ALTER SUBSCRIPTION ... ADD/DROP PUBLICATION and |
| 5 | +# ensures that creating a publication associated with a subscription at a later |
| 6 | +# point of time does not break logical replication. |
5 | 7 | use strict;
|
6 | 8 | use warnings FATAL => 'all';
|
7 | 9 | use PostgreSQL::Test::Cluster;
|
|
80 | 82 | "SELECT count(*), min(a), max(a) FROM tab_1");
|
81 | 83 | is($result, qq(20|1|10), 'check initial data is copied to subscriber');
|
82 | 84 |
|
| 85 | +# Ensure that setting a missing publication to the subscription does not |
| 86 | +# disrupt existing logical replication. Instead, it should log a warning |
| 87 | +# while allowing replication to continue. Additionally, verify that replication |
| 88 | +# resumes after the missing publication is created for the publication table. |
| 89 | + |
| 90 | +# Create table on publisher and subscriber |
| 91 | +$node_publisher->safe_psql('postgres', "CREATE TABLE tab_3 (a int)"); |
| 92 | +$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_3 (a int)"); |
| 93 | + |
| 94 | +# Set the subscription with a missing publication |
| 95 | +$node_subscriber->safe_psql('postgres', |
| 96 | + "ALTER SUBSCRIPTION tap_sub SET PUBLICATION tap_pub_3"); |
| 97 | + |
| 98 | +my $offset = -s $node_publisher->logfile; |
| 99 | + |
| 100 | +$node_publisher->safe_psql('postgres',"INSERT INTO tab_3 values(1)"); |
| 101 | + |
| 102 | +# Verify that a warning is logged. |
| 103 | +$node_publisher->wait_for_log( |
| 104 | + qr/WARNING: ( [A-Z0-9]+:)? skipped loading publication: tap_pub_3/, $offset); |
| 105 | + |
| 106 | +$node_publisher->safe_psql('postgres', |
| 107 | + "CREATE PUBLICATION tap_pub_3 FOR TABLE tab_3"); |
| 108 | + |
| 109 | +$node_subscriber->safe_psql('postgres', |
| 110 | + "ALTER SUBSCRIPTION tap_sub REFRESH PUBLICATION"); |
| 111 | + |
| 112 | +$node_subscriber->wait_for_subscription_sync($node_publisher, 'tap_sub'); |
| 113 | + |
| 114 | +$node_publisher->safe_psql('postgres', "INSERT INTO tab_3 values(2)"); |
| 115 | + |
| 116 | +$node_publisher->wait_for_catchup('tap_sub'); |
| 117 | + |
| 118 | +# Verify that the insert operation gets replicated to subscriber after |
| 119 | +# publication is created. |
| 120 | +$result = $node_subscriber->safe_psql('postgres', |
| 121 | + "SELECT * FROM tab_3"); |
| 122 | +is($result, qq(1 |
| 123 | +2), 'check that the incremental data is replicated after the publication is created'); |
| 124 | + |
83 | 125 | # shutdown
|
84 | 126 | $node_subscriber->stop('fast');
|
85 | 127 | $node_publisher->stop('fast');
|
|
0 commit comments