v19-0005-Add-testcase.patch
application/octet-stream
Filename: v19-0005-Add-testcase.patch
Type: application/octet-stream
Part: 6
Message:
RE: speed up a logical replica setup
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v19-0005
Subject: Add testcase
| File | + | − |
|---|---|---|
| src/bin/pg_basebackup/t/041_pg_createsubscriber_standby.pl | 47 | 6 |
From 634d649fa2d51a2f2c1a2eb0cad539ad88c8904f Mon Sep 17 00:00:00 2001
From: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Date: Thu, 8 Feb 2024 14:05:59 +0000
Subject: [PATCH v19 5/9] Add testcase
---
.../t/041_pg_createsubscriber_standby.pl | 53 ++++++++++++++++---
1 file changed, 47 insertions(+), 6 deletions(-)
diff --git a/src/bin/pg_basebackup/t/041_pg_createsubscriber_standby.pl b/src/bin/pg_basebackup/t/041_pg_createsubscriber_standby.pl
index 58f9d95f3b..d7567ef8e9 100644
--- a/src/bin/pg_basebackup/t/041_pg_createsubscriber_standby.pl
+++ b/src/bin/pg_basebackup/t/041_pg_createsubscriber_standby.pl
@@ -13,6 +13,7 @@ my $node_p;
my $node_f;
my $node_s;
my $result;
+my $slotname;
# Set up node P as primary
$node_p = PostgreSQL::Test::Cluster->new('node_p');
@@ -30,6 +31,7 @@ $node_f->start;
# - create databases
# - create test tables
# - insert a row
+# - create a physical relication slot
$node_p->safe_psql(
'postgres', q(
CREATE DATABASE pg1;
@@ -38,18 +40,19 @@ $node_p->safe_psql(
$node_p->safe_psql('pg1', 'CREATE TABLE tbl1 (a text)');
$node_p->safe_psql('pg1', "INSERT INTO tbl1 VALUES('first row')");
$node_p->safe_psql('pg2', 'CREATE TABLE tbl2 (a text)');
+$slotname = 'physical_slot';
+$node_p->safe_psql('pg2',
+ "SELECT pg_create_physical_replication_slot('$slotname')");
# Set up node S as standby linking to node P
$node_p->backup('backup_1');
$node_s = PostgreSQL::Test::Cluster->new('node_s');
$node_s->init_from_backup($node_p, 'backup_1', has_streaming => 1);
-$node_s->append_conf('postgresql.conf', 'log_min_messages = debug2');
+$node_s->append_conf('postgresql.conf', qq[
+log_min_messages = debug2
+primary_slot_name = '$slotname'
+]);
$node_s->set_standby_mode();
-$node_s->start;
-
-# Insert another row on node P and wait node S to catch up
-$node_p->safe_psql('pg1', "INSERT INTO tbl1 VALUES('second row')");
-$node_p->wait_for_replay_catchup($node_s);
# Run pg_createsubscriber on about-to-fail node F
command_fails(
@@ -63,6 +66,25 @@ command_fails(
],
'subscriber data directory is not a copy of the source database cluster');
+# Run pg_createsubscriber on the stopped node
+command_fails(
+ [
+ 'pg_createsubscriber', '--verbose',
+ '--dry-run', '--pgdata',
+ $node_s->data_dir, '--publisher-server',
+ $node_p->connstr('pg1'), '--subscriber-server',
+ $node_s->connstr('pg1'), '--database',
+ 'pg1', '--database',
+ 'pg2'
+ ],
+ 'target server must be running');
+
+$node_s->start;
+
+# Insert another row on node P and wait node S to catch up
+$node_p->safe_psql('pg1', "INSERT INTO tbl1 VALUES('second row')");
+$node_p->wait_for_replay_catchup($node_s);
+
# dry run mode on node S
command_ok(
[
@@ -80,6 +102,17 @@ command_ok(
is($node_s->safe_psql('postgres', 'SELECT pg_is_in_recovery()'),
't', 'standby is in recovery');
+# pg_createsubscriber can run without --databases option
+command_ok(
+ [
+ 'pg_createsubscriber', '--verbose',
+ '--dry-run', '--pgdata',
+ $node_s->data_dir, '--publisher-server',
+ $node_p->connstr('pg1'), '--subscriber-server',
+ $node_s->connstr('pg1')
+ ],
+ 'run pg_createsubscriber without --databases');
+
# Run pg_createsubscriber on node S
command_ok(
[
@@ -92,6 +125,14 @@ command_ok(
],
'run pg_createsubscriber on node S');
+ok(-d $node_s->data_dir . "/pg_createsubscriber_output.d",
+ "pg_createsubscriber_output.d/ removed after pg_createsubscriber success");
+
+# Confirm the physical slot has been removed
+$result = $node_p->safe_psql('pg1',
+ "SELECT count(*) FROM pg_replication_slots WHERE slot_name = '$slotname'");
+is ( $result, qq(0), 'the physical replication slot specifeid as primary_slot_name has been removed');
+
# Insert rows on P
$node_p->safe_psql('pg1', "INSERT INTO tbl1 VALUES('third row')");
$node_p->safe_psql('pg2', "INSERT INTO tbl2 VALUES('row 1')");
--
2.43.0