pg_rewind: test new --write-recovery-conf functionality
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 30 Sep 2019 17:04:00 +0000 (14:04 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 30 Sep 2019 17:04:00 +0000 (14:04 -0300)
Author: Alexey Kondratov
Reviewed-by: Paul Guo
Discussion: https://postgr.es/m/2f726102-3f1e-bf16-061e-501919473ace@postgrespro.ru

src/bin/pg_rewind/t/001_basic.pl
src/bin/pg_rewind/t/002_databases.pl
src/bin/pg_rewind/t/003_extrafiles.pl
src/bin/pg_rewind/t/004_pg_xlog_symlink.pl
src/bin/pg_rewind/t/RewindTest.pm

index 115192170e56819ad777053f65c0f45d227d8c17..c3293e93df7c32839162683eef1d04785199fd71 100644 (file)
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 use TestLib;
-use Test::More tests => 10;
+use Test::More tests => 11;
 
 use FindBin;
 use lib $FindBin::RealBin;
index f1eb4fe1d2b60cffc9fa0f700fd0d43b59f7f2a8..1db534c0dc0cc70e18583b486e272d856d6ab7cf 100644 (file)
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 use TestLib;
-use Test::More tests => 6;
+use Test::More tests => 7;
 
 use FindBin;
 use lib $FindBin::RealBin;
index c4040bd5620d5eabb2eceaef9157a5fc64ec2032..f4710440fc3a153bac97647ff4f08da68dab9fe9 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 use TestLib;
-use Test::More tests => 4;
+use Test::More tests => 5;
 
 use File::Find;
 
index ed1ddb6b60cb4ca19819ca3a321166432b667bfc..639eeb9c910c44e2fb07639243a6039037d77995 100644 (file)
@@ -14,7 +14,7 @@ if ($windows_os)
 }
 else
 {
-   plan tests => 4;
+   plan tests => 5;
 }
 
 use FindBin;
index 68b6004e9461a62fc9e7a40de3170e45d8db0005..c540722420e1710fef70425b2ff0f50462b8997d 100644 (file)
@@ -149,7 +149,7 @@ sub start_master
 
    # Create custom role which is used to run pg_rewind, and adjust its
    # permissions to the minimum necessary.
-   $node_master->psql(
+   $node_master->safe_psql(
        'postgres', "
        CREATE ROLE rewind_user LOGIN;
        GRANT EXECUTE ON function pg_catalog.pg_ls_dir(text, boolean, boolean)
@@ -266,9 +266,19 @@ sub run_pg_rewind
            [
                'pg_rewind',                      "--debug",
                "--source-server",                $standby_connstr,
-               "--target-pgdata=$master_pgdata", "--no-sync"
+               "--target-pgdata=$master_pgdata", "-R",
+               "--no-sync"
            ],
            'pg_rewind remote');
+
+       # Check that standby.signal has been created.
+       ok(-e "$master_pgdata/standby.signal");
+
+       # Now, when pg_rewind apparently succeeded with minimal permissions,
+       # add REPLICATION privilege.  So we could test that new standby
+       # is able to connect to the new master with generated config.
+       $node_standby->safe_psql('postgres',
+           "ALTER ROLE rewind_user WITH REPLICATION;");
    }
    else
    {
@@ -289,13 +299,15 @@ sub run_pg_rewind
        "unable to set permissions for $master_pgdata/postgresql.conf");
 
    # Plug-in rewound node to the now-promoted standby node
-   my $port_standby = $node_standby->port;
-   $node_master->append_conf(
-       'postgresql.conf', qq(
-primary_conninfo='port=$port_standby'
-));
+   if ($test_mode ne "remote")
+   {
+       my $port_standby = $node_standby->port;
+       $node_master->append_conf(
+           'postgresql.conf', qq(
+primary_conninfo='port=$port_standby'));
 
-   $node_master->set_standby_mode();
+       $node_master->set_standby_mode();
+   }
 
    # Restart the master to check that rewind went correctly
    $node_master->start;