]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
ALTER SUBSCRIPTION ... SERVER test.
authorJeff Davis <jdavis@postgresql.org>
Wed, 18 Mar 2026 17:15:51 +0000 (10:15 -0700)
committerJeff Davis <jdavis@postgresql.org>
Wed, 18 Mar 2026 17:15:51 +0000 (10:15 -0700)
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 <ashutosh.bapat.oss@gmail.com>
contrib/postgres_fdw/t/010_subscription.pl

index a04d64bb78ca2db405b0b0c7a071fe545429a669..163c788d209665998d4a060cb2548c6126645eeb 100644 (file)
@@ -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();