2021-05-07 10:56:14 -04:00
|
|
|
|
2023-01-02 15:00:37 -05:00
|
|
|
# Copyright (c) 2021-2023, PostgreSQL Global Development Group
|
2021-05-07 10:56:14 -04:00
|
|
|
|
2015-03-23 19:47:52 +02:00
|
|
|
package RewindTest;
|
|
|
|
|
|
|
|
# Test driver for pg_rewind. Each test consists of a cycle where a new cluster
|
|
|
|
# is first created with initdb, and a streaming replication standby is set up
|
2020-06-14 11:47:37 -07:00
|
|
|
# to follow the primary. Then the primary is shut down and the standby is
|
|
|
|
# promoted, and finally pg_rewind is used to rewind the old primary, using the
|
2015-03-23 19:47:52 +02:00
|
|
|
# standby as the source.
|
|
|
|
#
|
|
|
|
# To run a test, the test script (in t/ subdirectory) calls the functions
|
|
|
|
# in this module. These functions should be called in this sequence:
|
|
|
|
#
|
2020-06-14 11:47:37 -07:00
|
|
|
# 1. setup_cluster - creates a PostgreSQL cluster that runs as the primary
|
2015-03-23 19:47:52 +02:00
|
|
|
#
|
2020-06-14 11:47:37 -07:00
|
|
|
# 2. start_primary - starts the primary server
|
2015-03-23 19:47:52 +02:00
|
|
|
#
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
# 3. create_standby - runs pg_basebackup to initialize a standby server, and
|
2020-06-14 11:47:37 -07:00
|
|
|
# sets it up to follow the primary.
|
2015-03-23 19:47:52 +02:00
|
|
|
#
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
# 4. promote_standby - runs "pg_ctl promote" to promote the standby server.
|
2020-06-14 11:47:37 -07:00
|
|
|
# The old primary keeps running.
|
2015-03-23 19:47:52 +02:00
|
|
|
#
|
2020-06-14 11:47:37 -07:00
|
|
|
# 5. run_pg_rewind - stops the old primary (if it's still running) and runs
|
2015-03-23 19:47:52 +02:00
|
|
|
# pg_rewind to synchronize it with the now-promoted standby server.
|
|
|
|
#
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
# 6. clean_rewind_test - stops both servers used in the test, if they're
|
2015-04-15 19:54:38 +03:00
|
|
|
# still running.
|
|
|
|
#
|
2020-06-14 11:47:37 -07:00
|
|
|
# The test script can use the helper functions primary_psql and standby_psql
|
|
|
|
# to run psql against the primary and standby servers, respectively.
|
2015-03-23 19:47:52 +02:00
|
|
|
|
2015-04-13 18:06:12 +03:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2018-02-24 14:35:54 -05:00
|
|
|
use Carp;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
use Exporter 'import';
|
2015-03-23 19:47:52 +02:00
|
|
|
use File::Copy;
|
2015-08-05 16:21:54 -04:00
|
|
|
use File::Path qw(rmtree);
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
use IPC::Run qw(run);
|
2021-10-24 10:28:19 -04:00
|
|
|
use PostgreSQL::Test::Cluster;
|
|
|
|
use PostgreSQL::Test::RecursiveCopy;
|
|
|
|
use PostgreSQL::Test::Utils;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
use Test::More;
|
2015-03-23 19:47:52 +02:00
|
|
|
|
|
|
|
our @EXPORT = qw(
|
2020-06-14 11:47:37 -07:00
|
|
|
$node_primary
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
$node_standby
|
2015-03-23 19:47:52 +02:00
|
|
|
|
2020-06-14 11:47:37 -07:00
|
|
|
primary_psql
|
2015-03-23 19:47:52 +02:00
|
|
|
standby_psql
|
|
|
|
check_query
|
|
|
|
|
|
|
|
setup_cluster
|
2020-06-14 11:47:37 -07:00
|
|
|
start_primary
|
2015-03-23 19:47:52 +02:00
|
|
|
create_standby
|
|
|
|
promote_standby
|
|
|
|
run_pg_rewind
|
2015-04-15 19:54:38 +03:00
|
|
|
clean_rewind_test
|
2015-03-23 19:47:52 +02:00
|
|
|
);
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
# Our nodes.
|
2020-06-14 11:47:37 -07:00
|
|
|
our $node_primary;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
our $node_standby;
|
2015-03-23 19:47:52 +02:00
|
|
|
|
2020-06-14 11:47:37 -07:00
|
|
|
sub primary_psql
|
2015-03-23 19:47:52 +02:00
|
|
|
{
|
|
|
|
my $cmd = shift;
|
Fix pg_rewind when rewinding new database with tables included
This fixes an issue introduced by 266b6ac, which has added filters to
exclude file patterns on the target and source data directories to
reduce the number of files transferred. Filters get applied to both
the target and source data files, and include pg_internal.init which is
present for each database once relations are created on it. However, if
the target differed from the source with at least one new database with
relations, the rewind would fail due to the exclusion filters applied on
the target files, causing pg_internal.init to still be present on the
target database folder, while its contents should have been completely
removed so as there is nothing remaining inside at the time of the
folder deletion.
Applying exclusion filters on the source files is fine, because this way
the amount of data copied from the source to the target is reduced. And
actually, not applying the filters on the target is what pg_rewind
should do, because this causes such files to be automatically removed
during the rewind on the target. Exclusion filters apply to paths which
are removed or recreated automatically at startup, so removing all those
files on the target during the rewind is a win.
The existing set of TAP tests already stresses the rewind of databases,
but it did not include any tables on those newly-created databases.
Creating extra tables in this case is enough to reproduce the failure,
so the existing tests are extended to close the gap.
Reported-by: Mithun Cy
Author: Michael Paquier
Discussion: https://postgr.es/m/CADq3xVYt6_pO7ZzmjOqPgY9HWsL=kLd-_tNyMtdfjKqEALDyTA@mail.gmail.com
Backpatch-through: 11
2019-03-18 10:34:45 +09:00
|
|
|
my $dbname = shift || 'postgres';
|
2015-03-23 19:47:52 +02:00
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
system_or_bail 'psql', '-q', '--no-psqlrc', '-d',
|
2020-06-14 11:47:37 -07:00
|
|
|
$node_primary->connstr($dbname), '-c', "$cmd";
|
2018-05-27 09:08:42 -04:00
|
|
|
return;
|
2015-03-23 19:47:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub standby_psql
|
|
|
|
{
|
|
|
|
my $cmd = shift;
|
Fix pg_rewind when rewinding new database with tables included
This fixes an issue introduced by 266b6ac, which has added filters to
exclude file patterns on the target and source data directories to
reduce the number of files transferred. Filters get applied to both
the target and source data files, and include pg_internal.init which is
present for each database once relations are created on it. However, if
the target differed from the source with at least one new database with
relations, the rewind would fail due to the exclusion filters applied on
the target files, causing pg_internal.init to still be present on the
target database folder, while its contents should have been completely
removed so as there is nothing remaining inside at the time of the
folder deletion.
Applying exclusion filters on the source files is fine, because this way
the amount of data copied from the source to the target is reduced. And
actually, not applying the filters on the target is what pg_rewind
should do, because this causes such files to be automatically removed
during the rewind on the target. Exclusion filters apply to paths which
are removed or recreated automatically at startup, so removing all those
files on the target during the rewind is a win.
The existing set of TAP tests already stresses the rewind of databases,
but it did not include any tables on those newly-created databases.
Creating extra tables in this case is enough to reproduce the failure,
so the existing tests are extended to close the gap.
Reported-by: Mithun Cy
Author: Michael Paquier
Discussion: https://postgr.es/m/CADq3xVYt6_pO7ZzmjOqPgY9HWsL=kLd-_tNyMtdfjKqEALDyTA@mail.gmail.com
Backpatch-through: 11
2019-03-18 10:34:45 +09:00
|
|
|
my $dbname = shift || 'postgres';
|
2015-03-23 19:47:52 +02:00
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
system_or_bail 'psql', '-q', '--no-psqlrc', '-d',
|
Fix pg_rewind when rewinding new database with tables included
This fixes an issue introduced by 266b6ac, which has added filters to
exclude file patterns on the target and source data directories to
reduce the number of files transferred. Filters get applied to both
the target and source data files, and include pg_internal.init which is
present for each database once relations are created on it. However, if
the target differed from the source with at least one new database with
relations, the rewind would fail due to the exclusion filters applied on
the target files, causing pg_internal.init to still be present on the
target database folder, while its contents should have been completely
removed so as there is nothing remaining inside at the time of the
folder deletion.
Applying exclusion filters on the source files is fine, because this way
the amount of data copied from the source to the target is reduced. And
actually, not applying the filters on the target is what pg_rewind
should do, because this causes such files to be automatically removed
during the rewind on the target. Exclusion filters apply to paths which
are removed or recreated automatically at startup, so removing all those
files on the target during the rewind is a win.
The existing set of TAP tests already stresses the rewind of databases,
but it did not include any tables on those newly-created databases.
Creating extra tables in this case is enough to reproduce the failure,
so the existing tests are extended to close the gap.
Reported-by: Mithun Cy
Author: Michael Paquier
Discussion: https://postgr.es/m/CADq3xVYt6_pO7ZzmjOqPgY9HWsL=kLd-_tNyMtdfjKqEALDyTA@mail.gmail.com
Backpatch-through: 11
2019-03-18 10:34:45 +09:00
|
|
|
$node_standby->connstr($dbname), '-c', "$cmd";
|
2018-05-27 09:08:42 -04:00
|
|
|
return;
|
2015-03-23 19:47:52 +02:00
|
|
|
}
|
|
|
|
|
2020-06-14 11:47:37 -07:00
|
|
|
# Run a query against the primary, and check that the output matches what's
|
2015-03-23 19:47:52 +02:00
|
|
|
# expected
|
|
|
|
sub check_query
|
|
|
|
{
|
2018-05-22 14:25:01 -04:00
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1;
|
|
|
|
|
2015-03-23 19:47:52 +02:00
|
|
|
my ($query, $expected_stdout, $test_name) = @_;
|
|
|
|
my ($stdout, $stderr);
|
|
|
|
|
|
|
|
# we want just the output, no formatting
|
|
|
|
my $result = run [
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
'psql', '-q', '-A', '-t', '--no-psqlrc', '-d',
|
2020-06-14 11:47:37 -07:00
|
|
|
$node_primary->connstr('postgres'),
|
2018-05-09 10:14:46 -04:00
|
|
|
'-c', $query
|
|
|
|
],
|
2015-03-23 19:47:52 +02:00
|
|
|
'>', \$stdout, '2>', \$stderr;
|
2015-05-23 21:35:49 -04:00
|
|
|
|
2022-02-23 11:22:46 +01:00
|
|
|
is($result, 1, "$test_name: psql exit code");
|
|
|
|
is($stderr, '', "$test_name: psql no stderr");
|
|
|
|
is($stdout, $expected_stdout, "$test_name: query result matches");
|
|
|
|
|
2018-05-27 09:08:42 -04:00
|
|
|
return;
|
2015-03-23 19:47:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub setup_cluster
|
|
|
|
{
|
2018-04-07 17:45:39 -04:00
|
|
|
my $extra_name = shift; # Used to differentiate clusters
|
|
|
|
my $extra = shift; # Extra params for initdb
|
2016-06-12 04:19:56 -04:00
|
|
|
|
2020-06-14 11:47:37 -07:00
|
|
|
# Initialize primary, data checksums are mandatory
|
|
|
|
$node_primary =
|
2021-10-24 10:28:19 -04:00
|
|
|
PostgreSQL::Test::Cluster->new(
|
|
|
|
'primary' . ($extra_name ? "_${extra_name}" : ''));
|
2019-04-14 18:47:51 +09:00
|
|
|
|
|
|
|
# Set up pg_hba.conf and pg_ident.conf for the role running
|
|
|
|
# pg_rewind. This role is used for all the tests, and has
|
|
|
|
# minimal permissions enough to rewind from an online source.
|
2020-06-14 11:47:37 -07:00
|
|
|
$node_primary->init(
|
2019-04-14 18:47:51 +09:00
|
|
|
allows_streaming => 1,
|
|
|
|
extra => $extra,
|
|
|
|
auth_extra => [ '--create-role', 'rewind_user' ]);
|
2018-04-25 14:00:19 -04:00
|
|
|
|
2020-07-20 13:30:18 +09:00
|
|
|
# Set wal_keep_size to prevent WAL segment recycling after enforced
|
2017-11-02 12:38:59 -04:00
|
|
|
# checkpoints in the tests.
|
2020-06-14 11:47:37 -07:00
|
|
|
$node_primary->append_conf(
|
2017-11-02 12:38:59 -04:00
|
|
|
'postgresql.conf', qq(
|
2020-07-20 13:30:18 +09:00
|
|
|
wal_keep_size = 320MB
|
2023-07-30 15:26:25 +09:00
|
|
|
allow_in_place_tablespaces = on
|
2017-11-02 12:38:59 -04:00
|
|
|
));
|
2018-05-27 09:08:42 -04:00
|
|
|
return;
|
2015-08-03 15:32:06 +03:00
|
|
|
}
|
2015-03-23 19:47:52 +02:00
|
|
|
|
2020-06-14 11:47:37 -07:00
|
|
|
sub start_primary
|
2015-08-03 15:32:06 +03:00
|
|
|
{
|
2020-06-14 11:47:37 -07:00
|
|
|
$node_primary->start;
|
2015-03-23 19:47:52 +02:00
|
|
|
|
2019-04-14 18:47:51 +09:00
|
|
|
# Create custom role which is used to run pg_rewind, and adjust its
|
|
|
|
# permissions to the minimum necessary.
|
2020-06-14 11:47:37 -07:00
|
|
|
$node_primary->safe_psql(
|
2019-04-14 18:47:51 +09:00
|
|
|
'postgres', "
|
|
|
|
CREATE ROLE rewind_user LOGIN;
|
|
|
|
GRANT EXECUTE ON function pg_catalog.pg_ls_dir(text, boolean, boolean)
|
|
|
|
TO rewind_user;
|
|
|
|
GRANT EXECUTE ON function pg_catalog.pg_stat_file(text, boolean)
|
|
|
|
TO rewind_user;
|
|
|
|
GRANT EXECUTE ON function pg_catalog.pg_read_binary_file(text)
|
|
|
|
TO rewind_user;
|
|
|
|
GRANT EXECUTE ON function pg_catalog.pg_read_binary_file(text, bigint, bigint, boolean)
|
|
|
|
TO rewind_user;");
|
|
|
|
|
2020-06-14 11:47:37 -07:00
|
|
|
#### Now run the test-specific parts to initialize the primary before setting
|
2015-03-23 19:47:52 +02:00
|
|
|
# up standby
|
2018-05-27 09:08:42 -04:00
|
|
|
|
|
|
|
return;
|
2015-03-23 19:47:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub create_standby
|
|
|
|
{
|
2017-09-05 12:22:33 -04:00
|
|
|
my $extra_name = shift;
|
|
|
|
|
|
|
|
$node_standby =
|
2021-10-24 10:28:19 -04:00
|
|
|
PostgreSQL::Test::Cluster->new(
|
|
|
|
'standby' . ($extra_name ? "_${extra_name}" : ''));
|
2020-06-14 11:47:37 -07:00
|
|
|
$node_primary->backup('my_backup');
|
|
|
|
$node_standby->init_from_backup($node_primary, 'my_backup');
|
|
|
|
my $connstr_primary = $node_primary->connstr();
|
2015-05-23 21:35:49 -04:00
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
$node_standby->append_conf(
|
2018-11-25 16:31:16 +01:00
|
|
|
"postgresql.conf", qq(
|
2020-06-14 11:47:37 -07:00
|
|
|
primary_conninfo='$connstr_primary'
|
2015-03-23 19:47:52 +02:00
|
|
|
));
|
|
|
|
|
2018-11-25 16:31:16 +01:00
|
|
|
$node_standby->set_standby_mode();
|
|
|
|
|
2015-03-23 19:47:52 +02:00
|
|
|
# Start standby
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
$node_standby->start;
|
2015-03-23 19:47:52 +02:00
|
|
|
|
2015-09-07 19:01:00 -04:00
|
|
|
# The standby may have WAL to apply before it matches the primary. That
|
|
|
|
# is fine, because no test examines the standby before promotion.
|
2018-05-27 09:08:42 -04:00
|
|
|
|
|
|
|
return;
|
2015-03-23 19:47:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub promote_standby
|
|
|
|
{
|
|
|
|
#### Now run the test-specific parts to run after standby has been started
|
|
|
|
# up standby
|
|
|
|
|
2015-09-07 19:01:00 -04:00
|
|
|
# Wait for the standby to receive and write all WAL.
|
2020-06-14 11:47:37 -07:00
|
|
|
$node_primary->wait_for_catchup($node_standby, 'write');
|
2015-09-07 19:01:00 -04:00
|
|
|
|
2020-06-14 11:47:37 -07:00
|
|
|
# Now promote standby and insert some new data on primary, this will put
|
|
|
|
# the primary out-of-sync with the standby.
|
2016-02-26 13:24:22 -03:00
|
|
|
$node_standby->promote;
|
2015-04-30 21:57:18 -07:00
|
|
|
|
2018-05-27 09:08:42 -04:00
|
|
|
return;
|
2015-03-23 19:47:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub run_pg_rewind
|
|
|
|
{
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
my $test_mode = shift;
|
2020-06-14 11:47:37 -07:00
|
|
|
my $primary_pgdata = $node_primary->data_dir;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
my $standby_pgdata = $node_standby->data_dir;
|
|
|
|
my $standby_connstr = $node_standby->connstr('postgres');
|
2021-10-24 10:28:19 -04:00
|
|
|
my $tmp_folder = PostgreSQL::Test::Utils::tempdir;
|
2015-04-13 18:06:12 +03:00
|
|
|
|
2019-04-14 18:47:51 +09:00
|
|
|
# Append the rewind-specific role to the connection string.
|
|
|
|
$standby_connstr = "$standby_connstr user=rewind_user";
|
|
|
|
|
2020-04-01 10:57:03 +09:00
|
|
|
if ($test_mode eq 'archive')
|
|
|
|
{
|
|
|
|
# pg_rewind is tested with --restore-target-wal by moving all
|
|
|
|
# WAL files to a secondary location. Note that this leads to
|
|
|
|
# a failure in ensureCleanShutdown(), forcing to the use of
|
|
|
|
# --no-ensure-shutdown in this mode as the initial set of WAL
|
|
|
|
# files needed to ensure a clean restart is gone. This could
|
|
|
|
# be improved by keeping around only a minimum set of WAL
|
|
|
|
# segments but that would just make the test more costly,
|
|
|
|
# without improving the coverage. Hence, instead, stop
|
|
|
|
# gracefully the primary here.
|
2020-06-14 11:47:37 -07:00
|
|
|
$node_primary->stop;
|
2020-04-01 10:57:03 +09:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-14 11:47:37 -07:00
|
|
|
# Stop the primary and be ready to perform the rewind. The cluster
|
2020-04-01 10:57:03 +09:00
|
|
|
# needs recovery to finish once, and pg_rewind makes sure that it
|
|
|
|
# happens automatically.
|
2020-06-14 11:47:37 -07:00
|
|
|
$node_primary->stop('immediate');
|
2020-04-01 10:57:03 +09:00
|
|
|
}
|
2015-03-23 19:47:52 +02:00
|
|
|
|
|
|
|
# At this point, the rewind processing is ready to run.
|
|
|
|
# We now have a very simple scenario with a few diverged WAL record.
|
|
|
|
# The real testing begins really now with a bifurcation of the possible
|
|
|
|
# scenarios that pg_rewind supports.
|
|
|
|
|
2020-06-14 11:47:37 -07:00
|
|
|
# Keep a temporary postgresql.conf for primary node or it would be
|
2015-03-23 19:47:52 +02:00
|
|
|
# overwritten during the rewind.
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
copy(
|
2020-06-14 11:47:37 -07:00
|
|
|
"$primary_pgdata/postgresql.conf",
|
|
|
|
"$tmp_folder/primary-postgresql.conf.tmp");
|
2015-05-23 21:35:49 -04:00
|
|
|
|
2015-03-23 19:47:52 +02:00
|
|
|
# Now run pg_rewind
|
2015-04-13 18:06:12 +03:00
|
|
|
if ($test_mode eq "local")
|
2015-03-23 19:47:52 +02:00
|
|
|
{
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
|
2015-03-23 19:47:52 +02:00
|
|
|
# Do rewind using a local pgdata as source
|
2020-06-14 11:47:37 -07:00
|
|
|
# Stop the primary and be ready to perform the rewind
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
$node_standby->stop;
|
|
|
|
command_ok(
|
2018-05-09 10:14:46 -04:00
|
|
|
[
|
|
|
|
'pg_rewind',
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
"--debug",
|
|
|
|
"--source-pgdata=$standby_pgdata",
|
2020-06-14 11:47:37 -07:00
|
|
|
"--target-pgdata=$primary_pgdata",
|
2022-04-07 08:51:49 +09:00
|
|
|
"--no-sync",
|
|
|
|
"--config-file",
|
|
|
|
"$tmp_folder/primary-postgresql.conf.tmp"
|
2018-05-09 10:14:46 -04:00
|
|
|
],
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
'pg_rewind local');
|
2015-03-23 19:47:52 +02:00
|
|
|
}
|
2015-04-13 18:06:12 +03:00
|
|
|
elsif ($test_mode eq "remote")
|
2015-03-23 19:47:52 +02:00
|
|
|
{
|
2019-10-07 09:07:22 +09:00
|
|
|
# Do rewind using a remote connection as source, generating
|
|
|
|
# recovery configuration automatically.
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
command_ok(
|
2018-05-09 10:14:46 -04:00
|
|
|
[
|
|
|
|
'pg_rewind', "--debug",
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
"--source-server", $standby_connstr,
|
2020-06-14 11:47:37 -07:00
|
|
|
"--target-pgdata=$primary_pgdata", "--no-sync",
|
2022-04-07 08:51:49 +09:00
|
|
|
"--write-recovery-conf", "--config-file",
|
|
|
|
"$tmp_folder/primary-postgresql.conf.tmp"
|
2018-05-09 10:14:46 -04:00
|
|
|
],
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
'pg_rewind remote');
|
2019-09-30 14:04:00 -03:00
|
|
|
|
2019-10-07 09:07:22 +09:00
|
|
|
# Check that standby.signal is here as recovery configuration
|
|
|
|
# was requested.
|
2020-06-14 11:47:37 -07:00
|
|
|
ok( -e "$primary_pgdata/standby.signal",
|
2019-10-07 09:07:22 +09:00
|
|
|
'standby.signal created after pg_rewind');
|
2019-09-30 14:04:00 -03:00
|
|
|
|
|
|
|
# Now, when pg_rewind apparently succeeded with minimal permissions,
|
|
|
|
# add REPLICATION privilege. So we could test that new standby
|
2020-06-14 11:47:37 -07:00
|
|
|
# is able to connect to the new primary with generated config.
|
2019-09-30 14:04:00 -03:00
|
|
|
$node_standby->safe_psql('postgres',
|
|
|
|
"ALTER ROLE rewind_user WITH REPLICATION;");
|
2015-03-23 19:47:52 +02:00
|
|
|
}
|
2020-04-01 10:57:03 +09:00
|
|
|
elsif ($test_mode eq "archive")
|
|
|
|
{
|
|
|
|
|
|
|
|
# Do rewind using a local pgdata as source and specified
|
2020-06-14 11:47:37 -07:00
|
|
|
# directory with target WAL archive. The old primary has
|
2020-04-01 10:57:03 +09:00
|
|
|
# to be stopped at this point.
|
|
|
|
|
|
|
|
# Remove the existing archive directory and move all WAL
|
2020-06-14 11:47:37 -07:00
|
|
|
# segments from the old primary to the archives. These
|
2020-04-01 10:57:03 +09:00
|
|
|
# will be used by pg_rewind.
|
2020-06-14 11:47:37 -07:00
|
|
|
rmtree($node_primary->archive_dir);
|
2021-10-24 10:28:19 -04:00
|
|
|
PostgreSQL::Test::RecursiveCopy::copypath(
|
|
|
|
$node_primary->data_dir . "/pg_wal",
|
2020-06-14 11:47:37 -07:00
|
|
|
$node_primary->archive_dir);
|
2020-04-01 10:57:03 +09:00
|
|
|
|
|
|
|
# Fast way to remove entire directory content
|
2020-06-14 11:47:37 -07:00
|
|
|
rmtree($node_primary->data_dir . "/pg_wal");
|
|
|
|
mkdir($node_primary->data_dir . "/pg_wal");
|
2020-04-01 10:57:03 +09:00
|
|
|
|
|
|
|
# Make sure that directories have the right umask as this is
|
|
|
|
# required by a follow-up check on permissions, and better
|
|
|
|
# safe than sorry.
|
2020-06-14 11:47:37 -07:00
|
|
|
chmod(0700, $node_primary->archive_dir);
|
|
|
|
chmod(0700, $node_primary->data_dir . "/pg_wal");
|
2020-04-01 10:57:03 +09:00
|
|
|
|
|
|
|
# Add appropriate restore_command to the target cluster
|
2020-06-14 11:47:37 -07:00
|
|
|
$node_primary->enable_restoring($node_primary, 0);
|
2020-04-01 10:57:03 +09:00
|
|
|
|
2020-06-14 11:47:37 -07:00
|
|
|
# Stop the new primary and be ready to perform the rewind.
|
2020-04-01 10:57:03 +09:00
|
|
|
$node_standby->stop;
|
|
|
|
|
|
|
|
# Note the use of --no-ensure-shutdown here. WAL files are
|
|
|
|
# gone in this mode and the primary has been stopped
|
2022-04-07 08:51:49 +09:00
|
|
|
# gracefully already. --config-file reuses the original
|
|
|
|
# postgresql.conf as restore_command has been enabled above.
|
2020-04-01 10:57:03 +09:00
|
|
|
command_ok(
|
|
|
|
[
|
|
|
|
'pg_rewind',
|
|
|
|
"--debug",
|
|
|
|
"--source-pgdata=$standby_pgdata",
|
2020-06-14 11:47:37 -07:00
|
|
|
"--target-pgdata=$primary_pgdata",
|
2020-04-01 10:57:03 +09:00
|
|
|
"--no-sync",
|
|
|
|
"--no-ensure-shutdown",
|
2022-04-07 08:51:49 +09:00
|
|
|
"--restore-target-wal",
|
|
|
|
"--config-file",
|
|
|
|
"$primary_pgdata/postgresql.conf"
|
2020-04-01 10:57:03 +09:00
|
|
|
],
|
|
|
|
'pg_rewind archive');
|
|
|
|
}
|
2015-03-23 19:47:52 +02:00
|
|
|
else
|
|
|
|
{
|
2015-05-23 21:35:49 -04:00
|
|
|
|
2015-03-23 19:47:52 +02:00
|
|
|
# Cannot come here normally
|
2018-02-24 14:35:54 -05:00
|
|
|
croak("Incorrect test mode specified");
|
2015-03-23 19:47:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Now move back postgresql.conf with old settings
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
move(
|
2020-06-14 11:47:37 -07:00
|
|
|
"$tmp_folder/primary-postgresql.conf.tmp",
|
|
|
|
"$primary_pgdata/postgresql.conf");
|
2015-03-23 19:47:52 +02:00
|
|
|
|
2018-04-07 17:45:39 -04:00
|
|
|
chmod(
|
2020-06-14 11:47:37 -07:00
|
|
|
$node_primary->group_access() ? 0640 : 0600,
|
|
|
|
"$primary_pgdata/postgresql.conf")
|
2018-04-07 17:45:39 -04:00
|
|
|
or BAIL_OUT(
|
2020-06-14 11:47:37 -07:00
|
|
|
"unable to set permissions for $primary_pgdata/postgresql.conf");
|
2018-04-07 17:45:39 -04:00
|
|
|
|
2015-03-23 19:47:52 +02:00
|
|
|
# Plug-in rewound node to the now-promoted standby node
|
2019-09-30 14:04:00 -03:00
|
|
|
if ($test_mode ne "remote")
|
|
|
|
{
|
|
|
|
my $port_standby = $node_standby->port;
|
2020-06-14 11:47:37 -07:00
|
|
|
$node_primary->append_conf(
|
2019-09-30 14:04:00 -03:00
|
|
|
'postgresql.conf', qq(
|
|
|
|
primary_conninfo='port=$port_standby'));
|
2015-03-23 19:47:52 +02:00
|
|
|
|
2020-06-14 11:47:37 -07:00
|
|
|
$node_primary->set_standby_mode();
|
2019-09-30 14:04:00 -03:00
|
|
|
}
|
2018-11-25 16:31:16 +01:00
|
|
|
|
2020-06-14 11:47:37 -07:00
|
|
|
# Restart the primary to check that rewind went correctly
|
|
|
|
$node_primary->start;
|
2015-03-23 19:47:52 +02:00
|
|
|
|
|
|
|
#### Now run the test-specific parts to check the result
|
2018-05-27 09:08:42 -04:00
|
|
|
|
|
|
|
return;
|
2015-03-23 19:47:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Clean up after the test. Stop both servers, if they're still running.
|
2015-04-15 19:54:38 +03:00
|
|
|
sub clean_rewind_test
|
2015-03-23 19:47:52 +02:00
|
|
|
{
|
2020-06-14 11:47:37 -07:00
|
|
|
$node_primary->teardown_node if defined $node_primary;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
$node_standby->teardown_node if defined $node_standby;
|
2018-05-27 09:08:42 -04:00
|
|
|
return;
|
2015-04-15 19:54:38 +03:00
|
|
|
}
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 18:46:16 -03:00
|
|
|
1;
|