From 08001be72c54ce6f1bd4729546260b28821a46a1 Mon Sep 17 00:00:00 2001 From: Jeff Davis Date: Sat, 14 Mar 2026 12:50:45 -0700 Subject: [PATCH v22 2/6] ALTER SUBSCRIPTION ... SERVER test. Test ALTER SUBSCRIPTION ... SERVER and ALTER SUBSCRIPTION ... CONNECTION, including invalidation. Discussion: https://postgr.es/m/CAExHW5vV5znEvecX=ra2-v7UBj9-M6qvdDzuB78M-TxbYD1PEA@mail.gmail.com Suggested-by: Ashutosh Bapat --- contrib/postgres_fdw/t/010_subscription.pl | 38 ++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/contrib/postgres_fdw/t/010_subscription.pl b/contrib/postgres_fdw/t/010_subscription.pl index a04d64bb78c..50eac4c3bdb 100644 --- a/contrib/postgres_fdw/t/010_subscription.pl +++ b/contrib/postgres_fdw/t/010_subscription.pl @@ -49,7 +49,7 @@ $node_subscriber->safe_psql('postgres', $node_subscriber->wait_for_subscription_sync($node_publisher, 'tap_sub'); my $result = - $node_subscriber->safe_psql('postgres', "SELECT count(*) FROM tab_ins"); + $node_subscriber->safe_psql('postgres', "SELECT MAX(a) FROM tab_ins"); is($result, qq(1002), 'check that initial data was copied to subscriber'); $node_publisher->safe_psql('postgres', @@ -58,7 +58,41 @@ $node_publisher->safe_psql('postgres', $node_publisher->wait_for_catchup('tap_sub'); $result = - $node_subscriber->safe_psql('postgres', "SELECT count(*) FROM tab_ins"); + $node_subscriber->safe_psql('postgres', "SELECT MAX(a) FROM tab_ins"); is($result, qq(1050), 'check that inserted data was copied to subscriber'); +# change to CONNECTION and confirm invalidation +my $log_offset = -s $node_subscriber->logfile; +$node_subscriber->safe_psql('postgres', + "ALTER SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr'"); +$node_subscriber->wait_for_log( + qr/logical replication worker for subscription "tap_sub" will restart because of a parameter change/, + $log_offset); + +$node_publisher->safe_psql('postgres', + "INSERT INTO tab_ins SELECT a, a + 1 FROM generate_series(1051,1057) a"); + +$node_publisher->wait_for_catchup('tap_sub'); + +$result = + $node_subscriber->safe_psql('postgres', "SELECT MAX(a) FROM tab_ins"); +is($result, qq(1057), 'check subscription after ALTER SUBSCRIPTION ... CONNECTION'); + +# change back to SERVER and confirm invalidation +$log_offset = -s $node_subscriber->logfile; +$node_subscriber->safe_psql('postgres', + "ALTER SUBSCRIPTION tap_sub SERVER tap_server"); +$node_subscriber->wait_for_log( + qr/logical replication worker for subscription "tap_sub" will restart because of a parameter change/, + $log_offset); + +$node_publisher->safe_psql('postgres', + "INSERT INTO tab_ins SELECT a, a + 1 FROM generate_series(1058,1073) a"); + +$node_publisher->wait_for_catchup('tap_sub'); + +$result = + $node_subscriber->safe_psql('postgres', "SELECT MAX(a) FROM tab_ins"); +is($result, qq(1073), 'check subscription after ALTER SUBSCRIPTION ... SERVER'); + done_testing(); -- 2.43.0