On Sun, May 23, 2021 at 2:19 PM Dilip Kumar <dilipbal...@gmail.com> wrote: > > On Sat, May 22, 2021 at 8:33 PM Robert Haas <robertmh...@gmail.com> wrote:
I have created a tap test based on Robert's test.sh script. It reproduces the issue. I am new with perl so this still needs some cleanup/improvement, but at least it shows the idea. -- Regards, Dilip Kumar EnterpriseDB: http://www.enterprisedb.com
From c797ac980eb774c6ca7400b4b90d76164717acc7 Mon Sep 17 00:00:00 2001 From: Dilip Kumar <dilipkumar@localhost.localdomain> Date: Sun, 23 May 2021 21:27:58 +0530 Subject: [PATCH] Test for new standby not following promoted standby --- src/test/recovery/t/025_timeline_issue.pl | 85 +++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/test/recovery/t/025_timeline_issue.pl diff --git a/src/test/recovery/t/025_timeline_issue.pl b/src/test/recovery/t/025_timeline_issue.pl new file mode 100644 index 0000000..3ea3720 --- /dev/null +++ b/src/test/recovery/t/025_timeline_issue.pl @@ -0,0 +1,85 @@ + +# Copyright (c) 2021, PostgreSQL Global Development Group + +# Minimal test testing streaming replication +use Cwd; +use strict; +use warnings; +use PostgresNode; +use TestLib; +use Test::More tests => 1; + +# Prepare a alternative archive command to skip WAL files +my $script = "#!/usr/bin/perl \n +use File::Copy; \n +my (\$source, \$target) = \@ARGV; \n +if (\$source =~ /history/) \n +{ \n + copy(\$source, \$target); \n +}"; + +open my $fh, '>', "skip_cp"; +print {$fh} $script; +chmod 0777, "skip_cp"; +close $fh; + +my $cwd = getcwd(); + +# Initialize primary node +my $node_primary = get_new_node('primary'); +# A specific role is created to perform some tests related to replication, +# and it needs proper authentication configuration. +$node_primary->init(allows_streaming => 1, has_archiving => 1); +my $archivedir_primary = $node_primary->archive_dir; +$node_primary->append_conf( + 'postgresql.conf', qq( +archive_command = '"$cwd/skip_cp" "%p" "$archivedir_primary/%f"' +)); +$node_primary->start; +my $backup_name = 'my_backup'; + +# Take backup +$node_primary->backup($backup_name); + +# Create streaming standby linking to primary +my $node_standby_1 = get_new_node('standby_1'); +$node_standby_1->init_from_backup($node_primary, $backup_name, + allows_streaming => 1, has_streaming => 1, has_archiving => 1); +$node_standby_1->start; + +# Take backup of standby 1 +# NB: Use -Xnone so that pg_wal is empty. +$node_standby_1->backup($backup_name, backup_options => ['-Xnone']); + +# Create cascading standby but don't start it yet. +# NB: Must set up both streaming and archiving. +my $node_cascade = get_new_node('cascade'); +$node_cascade->init_from_backup($node_standby_1, $backup_name, + has_streaming => 1); +$node_cascade->append_conf( + 'postgresql.conf', qq( +restore_command = 'cp "$archivedir_primary/%f" "%p"' +log_line_prefix = '%m [%p:%b] %q%a ' +)); + +# Promote the standby. +$node_standby_1->psql('postgres', 'SELECT pg_promote()'); + +# Create some content on primary and check its presence in standby 1 +$node_standby_1->safe_psql('postgres', + "CREATE TABLE tab_int AS SELECT 1 AS a"); + +# Start cascade node +$node_cascade->start; + +# Wait for standbys to catch up +$node_standby_1->wait_for_catchup($node_cascade, 'replay', + $node_standby_1->lsn('replay')); + +# clean up +$node_primary->teardown_node; +$node_standby_1->teardown_node; +$node_cascade->teardown_node; + +unlink "skip_cp"; +exit(0); \ No newline at end of file -- 1.8.3.1