mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-06 15:24:56 +08:00
Move some code from RewindTest into PostgresNode
Some code in the RewindTest test suite is more generally useful than just for that suite, so put it where other test suites can reach it. Some postgresql.conf parameters change their default values when a cluster is initialized with 'allows_streaming' than the previous behavior; most notably, autovacuum is no longer turned off. (Also, we no longer call pg_ctl promote with -w, but that flag doesn't actually do anything in promote so there's no behavior change.) Author: Michael Paquier
This commit is contained in:
parent
7bea19d0a9
commit
89ac7004da
@ -114,24 +114,9 @@ sub check_query
|
|||||||
|
|
||||||
sub setup_cluster
|
sub setup_cluster
|
||||||
{
|
{
|
||||||
|
|
||||||
# Initialize master, data checksums are mandatory
|
# Initialize master, data checksums are mandatory
|
||||||
$node_master = get_new_node('master');
|
$node_master = get_new_node('master');
|
||||||
$node_master->init;
|
$node_master->init(allows_streaming => 1);
|
||||||
|
|
||||||
# Custom parameters for master's postgresql.conf
|
|
||||||
$node_master->append_conf(
|
|
||||||
"postgresql.conf", qq(
|
|
||||||
wal_level = hot_standby
|
|
||||||
max_wal_senders = 2
|
|
||||||
wal_keep_segments = 20
|
|
||||||
max_wal_size = 200MB
|
|
||||||
shared_buffers = 1MB
|
|
||||||
wal_log_hints = on
|
|
||||||
hot_standby = on
|
|
||||||
autovacuum = off
|
|
||||||
max_connections = 10
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub start_master
|
sub start_master
|
||||||
@ -177,7 +162,7 @@ sub promote_standby
|
|||||||
# Now promote slave and insert some new data on master, this will put
|
# Now promote slave and insert some new data on master, this will put
|
||||||
# the master out-of-sync with the standby. Wait until the standby is
|
# the master out-of-sync with the standby. Wait until the standby is
|
||||||
# out of recovery mode, and is ready to accept read-write connections.
|
# out of recovery mode, and is ready to accept read-write connections.
|
||||||
system_or_bail('pg_ctl', '-w', '-D', $node_standby->data_dir, 'promote');
|
$node_standby->promote;
|
||||||
$node_standby->poll_query_until('postgres',
|
$node_standby->poll_query_until('postgres',
|
||||||
"SELECT NOT pg_is_in_recovery()")
|
"SELECT NOT pg_is_in_recovery()")
|
||||||
or die "Timed out while waiting for promotion of standby";
|
or die "Timed out while waiting for promotion of standby";
|
||||||
|
@ -47,7 +47,7 @@ allowing to start, stop, backup and initialize it with various options.
|
|||||||
The set of nodes managed by a given test is also managed by this module.
|
The set of nodes managed by a given test is also managed by this module.
|
||||||
|
|
||||||
In addition to node management, PostgresNode instances have some wrappers
|
In addition to node management, PostgresNode instances have some wrappers
|
||||||
around Test::More functions to run commands with an envronment set up to
|
around Test::More functions to run commands with an environment set up to
|
||||||
point to the instance.
|
point to the instance.
|
||||||
|
|
||||||
The IPC::Run module is required.
|
The IPC::Run module is required.
|
||||||
@ -66,7 +66,6 @@ use File::Basename;
|
|||||||
use File::Spec;
|
use File::Spec;
|
||||||
use File::Temp ();
|
use File::Temp ();
|
||||||
use IPC::Run;
|
use IPC::Run;
|
||||||
use PostgresNode;
|
|
||||||
use RecursiveCopy;
|
use RecursiveCopy;
|
||||||
use Test::More;
|
use Test::More;
|
||||||
use TestLib ();
|
use TestLib ();
|
||||||
@ -347,6 +346,9 @@ On Windows, we use SSPI authentication to ensure the same (by pg_regress
|
|||||||
pg_hba.conf is configured to allow replication connections. Pass the keyword
|
pg_hba.conf is configured to allow replication connections. Pass the keyword
|
||||||
parameter hba_permit_replication => 0 to disable this.
|
parameter hba_permit_replication => 0 to disable this.
|
||||||
|
|
||||||
|
postgresql.conf can be set up for replication by passing the keyword
|
||||||
|
parameter allows_streaming => 1. This is disabled by default.
|
||||||
|
|
||||||
The new node is set up in a fast but unsafe configuration where fsync is
|
The new node is set up in a fast but unsafe configuration where fsync is
|
||||||
disabled.
|
disabled.
|
||||||
|
|
||||||
@ -360,7 +362,8 @@ sub init
|
|||||||
my $host = $self->host;
|
my $host = $self->host;
|
||||||
|
|
||||||
$params{hba_permit_replication} = 1
|
$params{hba_permit_replication} = 1
|
||||||
if (!defined($params{hba_permit_replication}));
|
unless defined $params{hba_permit_replication};
|
||||||
|
$params{allows_streaming} = 0 unless defined $params{allows_streaming};
|
||||||
|
|
||||||
mkdir $self->backup_dir;
|
mkdir $self->backup_dir;
|
||||||
mkdir $self->archive_dir;
|
mkdir $self->archive_dir;
|
||||||
@ -373,6 +376,19 @@ sub init
|
|||||||
print $conf "fsync = off\n";
|
print $conf "fsync = off\n";
|
||||||
print $conf "log_statement = all\n";
|
print $conf "log_statement = all\n";
|
||||||
print $conf "port = $port\n";
|
print $conf "port = $port\n";
|
||||||
|
|
||||||
|
if ($params{allows_streaming})
|
||||||
|
{
|
||||||
|
print $conf "wal_level = hot_standby\n";
|
||||||
|
print $conf "max_wal_senders = 5\n";
|
||||||
|
print $conf "wal_keep_segments = 20\n";
|
||||||
|
print $conf "max_wal_size = 128MB\n";
|
||||||
|
print $conf "shared_buffers = 1MB\n";
|
||||||
|
print $conf "wal_log_hints = on\n";
|
||||||
|
print $conf "hot_standby = on\n";
|
||||||
|
print $conf "max_connections = 10\n";
|
||||||
|
}
|
||||||
|
|
||||||
if ($TestLib::windows_os)
|
if ($TestLib::windows_os)
|
||||||
{
|
{
|
||||||
print $conf "listen_addresses = '$host'\n";
|
print $conf "listen_addresses = '$host'\n";
|
||||||
@ -384,7 +400,7 @@ sub init
|
|||||||
}
|
}
|
||||||
close $conf;
|
close $conf;
|
||||||
|
|
||||||
$self->set_replication_conf if ($params{hba_permit_replication});
|
$self->set_replication_conf if $params{hba_permit_replication};
|
||||||
}
|
}
|
||||||
|
|
||||||
=pod
|
=pod
|
||||||
@ -446,6 +462,9 @@ Does not start the node after init.
|
|||||||
|
|
||||||
A recovery.conf is not created.
|
A recovery.conf is not created.
|
||||||
|
|
||||||
|
Streaming replication can be enabled on this node by passing the keyword
|
||||||
|
parameter has_streaming => 1. This is disabled by default.
|
||||||
|
|
||||||
The backup is copied, leaving the original unmodified. pg_hba.conf is
|
The backup is copied, leaving the original unmodified. pg_hba.conf is
|
||||||
unconditionally set to enable replication connections.
|
unconditionally set to enable replication connections.
|
||||||
|
|
||||||
@ -453,12 +472,13 @@ unconditionally set to enable replication connections.
|
|||||||
|
|
||||||
sub init_from_backup
|
sub init_from_backup
|
||||||
{
|
{
|
||||||
my ($self, $root_node, $backup_name) = @_;
|
my ($self, $root_node, $backup_name, %params) = @_;
|
||||||
my $backup_path = $root_node->backup_dir . '/' . $backup_name;
|
my $backup_path = $root_node->backup_dir . '/' . $backup_name;
|
||||||
my $port = $self->port;
|
my $port = $self->port;
|
||||||
my $node_name = $self->name;
|
my $node_name = $self->name;
|
||||||
my $root_name = $root_node->name;
|
my $root_name = $root_node->name;
|
||||||
|
|
||||||
|
$params{has_streaming} = 0 unless defined $params{has_streaming};
|
||||||
print
|
print
|
||||||
"# Initializing node \"$node_name\" from backup \"$backup_name\" of node \"$root_name\"\n";
|
"# Initializing node \"$node_name\" from backup \"$backup_name\" of node \"$root_name\"\n";
|
||||||
die "Backup \"$backup_name\" does not exist at $backup_path"
|
die "Backup \"$backup_name\" does not exist at $backup_path"
|
||||||
@ -479,6 +499,7 @@ sub init_from_backup
|
|||||||
port = $port
|
port = $port
|
||||||
));
|
));
|
||||||
$self->set_replication_conf;
|
$self->set_replication_conf;
|
||||||
|
$self->enable_streaming($root_node) if $params{has_streaming};
|
||||||
}
|
}
|
||||||
|
|
||||||
=pod
|
=pod
|
||||||
@ -525,7 +546,7 @@ sub stop
|
|||||||
my $port = $self->port;
|
my $port = $self->port;
|
||||||
my $pgdata = $self->data_dir;
|
my $pgdata = $self->data_dir;
|
||||||
my $name = $self->name;
|
my $name = $self->name;
|
||||||
$mode = 'fast' if (!defined($mode));
|
$mode = 'fast' unless defined $mode;
|
||||||
print "### Stopping node \"$name\" using mode $mode\n";
|
print "### Stopping node \"$name\" using mode $mode\n";
|
||||||
TestLib::system_log('pg_ctl', '-D', $pgdata, '-m', $mode, 'stop');
|
TestLib::system_log('pg_ctl', '-D', $pgdata, '-m', $mode, 'stop');
|
||||||
$self->{_pid} = undef;
|
$self->{_pid} = undef;
|
||||||
@ -536,7 +557,7 @@ sub stop
|
|||||||
|
|
||||||
=item $node->restart()
|
=item $node->restart()
|
||||||
|
|
||||||
wrapper for pg_ctl -w restart
|
Wrapper for pg_ctl -w restart
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
@ -553,6 +574,39 @@ sub restart
|
|||||||
$self->_update_pid;
|
$self->_update_pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
=pod
|
||||||
|
|
||||||
|
=item $node->promote()
|
||||||
|
|
||||||
|
Wrapper for pg_ctl promote
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub promote
|
||||||
|
{
|
||||||
|
my ($self) = @_;
|
||||||
|
my $port = $self->port;
|
||||||
|
my $pgdata = $self->data_dir;
|
||||||
|
my $logfile = $self->logfile;
|
||||||
|
my $name = $self->name;
|
||||||
|
print "### Promoting node \"$name\"\n";
|
||||||
|
TestLib::system_log('pg_ctl', '-D', $pgdata, '-l', $logfile,
|
||||||
|
'promote');
|
||||||
|
}
|
||||||
|
|
||||||
|
# Internal routine to enable streaming replication on a standby node.
|
||||||
|
sub enable_streaming
|
||||||
|
{
|
||||||
|
my ($self, $root_node) = @_;
|
||||||
|
my $root_connstr = $root_node->connstr;
|
||||||
|
my $name = $self->name;
|
||||||
|
|
||||||
|
print "### Enabling streaming replication for node \"$name\"\n";
|
||||||
|
$self->append_conf('recovery.conf', qq(
|
||||||
|
primary_conninfo='$root_connstr application_name=$name'
|
||||||
|
standby_mode=on
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
# Internal method
|
# Internal method
|
||||||
sub _update_pid
|
sub _update_pid
|
||||||
@ -632,7 +686,7 @@ sub DESTROY
|
|||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $name = $self->name;
|
my $name = $self->name;
|
||||||
return if not defined $self->{_pid};
|
return unless defined $self->{_pid};
|
||||||
print "### Signalling QUIT to $self->{_pid} for node \"$name\"\n";
|
print "### Signalling QUIT to $self->{_pid} for node \"$name\"\n";
|
||||||
TestLib::system_log('pg_ctl', 'kill', 'QUIT', $self->{_pid});
|
TestLib::system_log('pg_ctl', 'kill', 'QUIT', $self->{_pid});
|
||||||
}
|
}
|
||||||
@ -789,6 +843,7 @@ Run a command on the node, then verify that $expected_sql appears in the
|
|||||||
server log file.
|
server log file.
|
||||||
|
|
||||||
Reads the whole log file so be careful when working with large log outputs.
|
Reads the whole log file so be careful when working with large log outputs.
|
||||||
|
The log file is truncated prior to running the command, however.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user