sub new
{
my $class = shift;
+ my $name = shift;
my $pghost = shift;
my $pgport = shift;
my $testname = basename($0);
_port => $pgport,
_host => $pghost,
_basedir => TestLib::tempdir,
- _applname => "node_$pgport",
- _logfile => "$TestLib::log_path/${testname}_node_${pgport}.log" };
+ _name => $name,
+ _logfile => "$TestLib::log_path/${testname}_${name}.log" };
bless $self, $class;
$self->dump_info;
return $self->{_basedir};
}
-sub applname
+sub name
{
my ($self) = @_;
- return $self->{_applname};
+ return $self->{_name};
}
sub logfile
sub dump_info
{
my ($self) = @_;
+ print "Name: " . $self->name . "\n";
print "Data directory: " . $self->data_dir . "\n";
print "Backup directory: " . $self->backup_dir . "\n";
print "Archive directory: " . $self->archive_dir . "\n";
print "Connection string: " . $self->connstr . "\n";
- print "Application name: " . $self->applname . "\n";
print "Log file: " . $self->logfile . "\n";
}
TestLib::system_or_bail($ENV{PG_REGRESS}, '--config-auth', $pgdata);
open my $conf, ">>$pgdata/postgresql.conf";
- print $conf "\n# Added by PostgresNode.pm)\n";
+ print $conf "\n# Added by PostgresNode.pm\n";
print $conf "fsync = off\n";
print $conf "log_statement = all\n";
print $conf "port = $port\n";
my ($self, $backup_name) = @_;
my $backup_path = $self->backup_dir . '/' . $backup_name;
my $port = $self->port;
+ my $name = $self->name;
- print "# Taking backup $backup_name from node with port $port\n";
+ print "# Taking backup $backup_name from node \"$name\"\n";
TestLib::system_or_bail("pg_basebackup -D $backup_path -p $port -x");
print "# Backup finished\n";
}
my ($self, $root_node, $backup_name) = @_;
my $backup_path = $root_node->backup_dir . '/' . $backup_name;
my $port = $self->port;
- my $root_port = $root_node->port;
+ my $node_name = $self->name;
+ my $root_name = $root_node->name;
print
-"Initializing node $port from backup \"$backup_name\" of node $root_port\n";
- die "Backup $backup_path does not exist" unless -d $backup_path;
+"# Initializing node \"$node_name\" from backup \"$backup_name\" of node \"$root_name\"\n";
+ die "Backup \"$backup_name\" does not exist at $backup_path"
+ unless -d $backup_path;
mkdir $self->backup_dir;
mkdir $self->archive_dir;
my ($self) = @_;
my $port = $self->port;
my $pgdata = $self->data_dir;
- print("### Starting test server in $pgdata\n");
+ my $name = $self->name;
+ print("### Starting node \"$name\"\n");
my $ret = TestLib::system_log('pg_ctl', '-w', '-D', $self->data_dir, '-l',
$self->logfile, 'start');
}
$self->_update_pid;
-
}
sub stop
my ($self, $mode) = @_;
my $port = $self->port;
my $pgdata = $self->data_dir;
+ my $name = $self->name;
$mode = 'fast' if (!defined($mode));
- print "### Stopping node in $pgdata with port $port using mode $mode\n";
+ print "### Stopping node \"$name\" using mode $mode\n";
TestLib::system_log('pg_ctl', '-D', $pgdata, '-m', $mode, 'stop');
$self->{_pid} = undef;
$self->_update_pid;
my $port = $self->port;
my $pgdata = $self->data_dir;
my $logfile = $self->logfile;
+ my $name = $self->name;
+ print "### Restarting node \"$name\"\n";
TestLib::system_log('pg_ctl', '-D', $pgdata, '-w', '-l', $logfile,
'restart');
$self->_update_pid;
sub _update_pid
{
my $self = shift;
+ my $name = $self->name;
# If we can open the PID file, read its first line and that's the PID we
# want. If the file cannot be opened, presumably the server is not
if (open my $pidfile, $self->data_dir . "/postmaster.pid")
{
chomp($self->{_pid} = <$pidfile>);
- print "# Postmaster PID is $self->{_pid}\n";
+ print "# Postmaster PID for node \"$name\" is $self->{_pid}\n";
close $pidfile;
return;
}
# for another node even when this one is not active.
sub get_new_node
{
+ my $name = shift;
my $found = 0;
my $port = $last_port_assigned;
print "# Found free port $port\n";
# Lock port number found by creating a new node
- my $node = new PostgresNode($test_pghost, $port);
+ my $node = new PostgresNode($name, $test_pghost, $port);
# Add node to list of nodes
push(@all_nodes, $node);
sub DESTROY
{
my $self = shift;
+ my $name = $self->name;
return if not defined $self->{_pid};
- print "# signalling QUIT to $self->{_pid}\n";
+ print "### Signalling QUIT to $self->{_pid} for node \"$name\"\n";
TestLib::system_log('pg_ctl', 'kill', 'QUIT', $self->{_pid});
}
my ($self, $dbname, $sql) = @_;
my ($stdout, $stderr);
- print("# Running SQL command: $sql\n");
+ my $name = $self->name;
+ print("### Running SQL command on node \"$name\": $sql\n");
IPC::Run::run [ 'psql', '-XAtq', '-d', $self->connstr($dbname), '-f',
'-' ], '<', \$sql, '>', \$stdout, '2>', \$stderr