From: Jeff Davis Date: Wed, 18 Mar 2026 17:15:51 +0000 (-0700) Subject: ALTER SUBSCRIPTION ... SERVER test. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c5bf1185af0128a8415fc48155045fb16b51dee;p=thirdparty%2Fpostgresql.git ALTER SUBSCRIPTION ... SERVER test. Test ALTER SUBSCRIPTION ... SERVER and ALTER SUBSCRIPTION ... CONNECTION, including invalidation. Also run perltidy on the test file. Discussion: https://postgr.es/m/CAExHW5vV5znEvecX=ra2-v7UBj9-M6qvdDzuB78M-TxbYD1PEA@mail.gmail.com Suggested-by: Ashutosh Bapat --- diff --git a/contrib/postgres_fdw/t/010_subscription.pl b/contrib/postgres_fdw/t/010_subscription.pl index a04d64bb78c..163c788d209 100644 --- a/contrib/postgres_fdw/t/010_subscription.pl +++ b/contrib/postgres_fdw/t/010_subscription.pl @@ -21,15 +21,18 @@ $node_subscriber->start; # Create some preexisting content on publisher $node_publisher->safe_psql('postgres', - "CREATE TABLE tab_ins AS SELECT a, a + 1 as b FROM generate_series(1,1002) AS a"); + "CREATE TABLE tab_ins AS SELECT a, a + 1 as b FROM generate_series(1,1002) AS a" +); # Setup structure on subscriber $node_subscriber->safe_psql('postgres', "CREATE EXTENSION postgres_fdw"); -$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_ins (a int, b int)"); +$node_subscriber->safe_psql('postgres', + "CREATE TABLE tab_ins (a int, b int)"); # Setup logical replication my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres'; -$node_publisher->safe_psql('postgres', "CREATE PUBLICATION tap_pub FOR TABLE tab_ins"); +$node_publisher->safe_psql('postgres', + "CREATE PUBLICATION tap_pub FOR TABLE tab_ins"); my $publisher_host = $node_publisher->host; my $publisher_port = $node_publisher->port; @@ -38,8 +41,7 @@ $node_subscriber->safe_psql('postgres', ); $node_subscriber->safe_psql('postgres', - "CREATE USER MAPPING FOR PUBLIC SERVER tap_server" -); + "CREATE USER MAPPING FOR PUBLIC SERVER tap_server"); $node_subscriber->safe_psql('postgres', "CREATE SUBSCRIPTION tap_sub SERVER tap_server PUBLICATION tap_pub WITH (password_required=false)" @@ -49,7 +51,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 +60,43 @@ $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();