mirror of
https://github.com/postgres/postgres.git
synced 2026-04-22 22:59:54 -04:00
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 <ashutosh.bapat.oss@gmail.com>
This commit is contained in:
parent
8df3c7a85e
commit
1c5bf1185a
1 changed files with 45 additions and 7 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in a new issue