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
|
|
|
|
# to follow the master. Then the master is shut down and the standby is
|
|
|
|
# promoted, and finally pg_rewind is used to rewind the old master, using the
|
|
|
|
# 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:
|
|
|
|
#
|
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. setup_cluster - creates a PostgreSQL cluster that runs as the master
|
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
|
|
|
# 2. start_master - starts the master 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
|
2015-03-23 19:47:52 +02:00
|
|
|
# sets it up to follow the master.
|
|
|
|
#
|
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.
|
2015-03-23 19:47:52 +02:00
|
|
|
# The old master keeps running.
|
|
|
|
#
|
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
|
|
|
# 5. run_pg_rewind - stops the old master (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.
|
|
|
|
#
|
2015-03-23 19:47:52 +02:00
|
|
|
# The test script can use the helper functions master_psql and standby_psql
|
|
|
|
# to run psql against the master and standby servers, respectively. The
|
|
|
|
# test script can also use the $connstr_master and $connstr_standby global
|
|
|
|
# variables, which contain libpq connection strings for connecting to the
|
|
|
|
# master and standby servers. The data directories are also available
|
|
|
|
# in paths $test_master_datadir and $test_standby_datadir
|
|
|
|
|
2015-04-13 18:06:12 +03:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2015-08-11 08:58:58 -04:00
|
|
|
use Config;
|
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);
|
|
|
|
use PostgresNode;
|
|
|
|
use TestLib;
|
|
|
|
use Test::More;
|
2015-03-23 19:47:52 +02:00
|
|
|
|
|
|
|
our @EXPORT = qw(
|
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_master
|
|
|
|
$node_standby
|
2015-03-23 19:47:52 +02:00
|
|
|
|
|
|
|
master_psql
|
|
|
|
standby_psql
|
|
|
|
check_query
|
|
|
|
|
|
|
|
setup_cluster
|
2015-08-03 15:32:06 +03:00
|
|
|
start_master
|
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.
|
|
|
|
our $node_master;
|
|
|
|
our $node_standby;
|
2015-03-23 19:47:52 +02:00
|
|
|
|
|
|
|
sub master_psql
|
|
|
|
{
|
|
|
|
my $cmd = shift;
|
|
|
|
|
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',
|
|
|
|
$node_master->connstr('postgres'), '-c', "$cmd";
|
2015-03-23 19:47:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub standby_psql
|
|
|
|
{
|
|
|
|
my $cmd = shift;
|
|
|
|
|
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',
|
|
|
|
$node_standby->connstr('postgres'), '-c', "$cmd";
|
2015-03-23 19:47:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Run a query against the master, and check that the output matches what's
|
|
|
|
# expected
|
|
|
|
sub check_query
|
|
|
|
{
|
|
|
|
my ($query, $expected_stdout, $test_name) = @_;
|
|
|
|
my ($stdout, $stderr);
|
|
|
|
|
|
|
|
# we want just the output, no formatting
|
2015-05-23 21:35:49 -04:00
|
|
|
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',
|
|
|
|
$node_master->connstr('postgres'),
|
|
|
|
'-c', $query ],
|
2015-05-23 21:35:49 -04:00
|
|
|
'>', \$stdout, '2>', \$stderr;
|
|
|
|
|
2015-03-23 19:47:52 +02:00
|
|
|
# We don't use ok() for the exit code and stderr, because we want this
|
|
|
|
# check to be just a single test.
|
2015-05-23 21:35:49 -04:00
|
|
|
if (!$result)
|
|
|
|
{
|
|
|
|
fail("$test_name: psql exit code");
|
|
|
|
}
|
|
|
|
elsif ($stderr ne '')
|
|
|
|
{
|
2015-03-23 19:47:52 +02:00
|
|
|
diag $stderr;
|
2015-05-23 21:35:49 -04:00
|
|
|
fail("$test_name: psql no stderr");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-11 08:58:58 -04:00
|
|
|
$stdout =~ s/\r//g if $Config{osname} eq 'msys';
|
2015-05-23 21:35:49 -04:00
|
|
|
is($stdout, $expected_stdout, "$test_name: query result matches");
|
2015-03-23 19:47:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub setup_cluster
|
|
|
|
{
|
2017-09-05 12:22:33 -04:00
|
|
|
my $extra_name = shift;
|
2016-06-12 04:19:56 -04:00
|
|
|
|
2015-03-23 19:47:52 +02:00
|
|
|
# Initialize master, data checksums are mandatory
|
2017-09-05 12:22:33 -04:00
|
|
|
$node_master = get_new_node('master' . ($extra_name ? "_${extra_name}" : ''));
|
2016-02-26 13:24:22 -03:00
|
|
|
$node_master->init(allows_streaming => 1);
|
2015-08-03 15:32:06 +03:00
|
|
|
}
|
2015-03-23 19:47:52 +02:00
|
|
|
|
2015-08-03 15:32:06 +03:00
|
|
|
sub start_master
|
|
|
|
{
|
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_master->start;
|
2015-03-23 19:47:52 +02:00
|
|
|
|
|
|
|
#### Now run the test-specific parts to initialize the master before setting
|
|
|
|
# up standby
|
|
|
|
}
|
|
|
|
|
|
|
|
sub create_standby
|
|
|
|
{
|
2017-09-05 12:22:33 -04:00
|
|
|
my $extra_name = shift;
|
|
|
|
|
|
|
|
$node_standby = get_new_node('standby' . ($extra_name ? "_${extra_name}" : ''));
|
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_master->backup('my_backup');
|
|
|
|
$node_standby->init_from_backup($node_master, 'my_backup');
|
2016-08-04 14:44:23 -04:00
|
|
|
my $connstr_master = $node_master->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(
|
|
|
|
"recovery.conf", qq(
|
2015-04-22 14:28:37 +03:00
|
|
|
primary_conninfo='$connstr_master application_name=rewind_standby'
|
2015-03-23 19:47:52 +02:00
|
|
|
standby_mode=on
|
|
|
|
recovery_target_timeline='latest'
|
|
|
|
));
|
|
|
|
|
|
|
|
# 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.
|
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.
|
|
|
|
my $wal_received_query =
|
2017-05-11 11:49:59 -04:00
|
|
|
"SELECT pg_current_wal_lsn() = write_lsn FROM pg_stat_replication WHERE application_name = 'rewind_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_master->poll_query_until('postgres', $wal_received_query)
|
2015-09-07 19:01:00 -04:00
|
|
|
or die "Timed out while waiting for standby to receive and write WAL";
|
|
|
|
|
2017-08-07 17:42:47 -04:00
|
|
|
# Now promote standby and insert some new data on master, this will put
|
2016-10-19 12:00:00 -04:00
|
|
|
# the master 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
|
|
|
|
|
|
|
# Force a checkpoint after the promotion. pg_rewind looks at the control
|
2016-01-04 10:12:37 -05:00
|
|
|
# file to determine what timeline the server is on, and that isn't updated
|
2015-04-30 21:57:18 -07:00
|
|
|
# immediately at promotion, but only at the next checkpoint. When running
|
|
|
|
# pg_rewind in remote mode, it's possible that we complete the test steps
|
|
|
|
# after promotion so quickly that when pg_rewind runs, the standby has not
|
|
|
|
# performed a checkpoint after promotion yet.
|
|
|
|
standby_psql("checkpoint");
|
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;
|
|
|
|
my $master_pgdata = $node_master->data_dir;
|
|
|
|
my $standby_pgdata = $node_standby->data_dir;
|
|
|
|
my $standby_connstr = $node_standby->connstr('postgres');
|
|
|
|
my $tmp_folder = TestLib::tempdir;
|
2015-04-13 18:06:12 +03:00
|
|
|
|
2015-03-23 19:47:52 +02:00
|
|
|
# Stop the master 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_master->stop;
|
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.
|
|
|
|
|
|
|
|
# Keep a temporary postgresql.conf for master node or it would be
|
|
|
|
# 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(
|
|
|
|
"$master_pgdata/postgresql.conf",
|
|
|
|
"$tmp_folder/master-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
|
|
|
|
# Stop the master 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(
|
|
|
|
[ 'pg_rewind',
|
|
|
|
"--debug",
|
|
|
|
"--source-pgdata=$standby_pgdata",
|
|
|
|
"--target-pgdata=$master_pgdata" ],
|
|
|
|
'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
|
|
|
{
|
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 remote connection as source
|
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(
|
|
|
|
[ 'pg_rewind', "--debug",
|
|
|
|
"--source-server", $standby_connstr,
|
|
|
|
"--target-pgdata=$master_pgdata" ],
|
|
|
|
'pg_rewind remote');
|
2015-05-23 21:35:49 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
2015-03-23 19:47:52 +02:00
|
|
|
# Cannot come here normally
|
|
|
|
die("Incorrect test mode specified");
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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(
|
|
|
|
"$tmp_folder/master-postgresql.conf.tmp",
|
|
|
|
"$master_pgdata/postgresql.conf");
|
2015-03-23 19:47:52 +02:00
|
|
|
|
|
|
|
# Plug-in rewound node to the now-promoted standby node
|
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 $port_standby = $node_standby->port;
|
|
|
|
$node_master->append_conf(
|
|
|
|
'recovery.conf', qq(
|
2015-03-23 19:47:52 +02:00
|
|
|
primary_conninfo='port=$port_standby'
|
|
|
|
standby_mode=on
|
|
|
|
recovery_target_timeline='latest'
|
|
|
|
));
|
|
|
|
|
|
|
|
# Restart the master to check that rewind went correctly
|
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_master->start;
|
2015-03-23 19:47:52 +02:00
|
|
|
|
|
|
|
#### Now run the test-specific parts to check the result
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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
|
|
|
{
|
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_master->teardown_node if defined $node_master;
|
|
|
|
$node_standby->teardown_node if defined $node_standby;
|
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;
|