## Checks how long in seconds since the last checkpoint on a WAL slave
## Supports: Nagios, MRTG
## Warning and critical are seconds
- ## Requires $ENV{PGATA} or --datadir
+ ## Requires $ENV{PGDATA} or --datadir
my ($warning, $critical) = validate_range
({
= $ENV{PGCONTROLDATA} ? $ENV{PGCONTROLDATA}
: $ENV{PGBINDIR} ? "$ENV{PGBINDIR}/pg_controldata"
: 'pg_controldata';
- $COM = "$pgc $dir";
+ $COM = qq{$pgc "$dir"};
eval {
$res = qx{$COM 2>&1};
};
my $host = $cp->get_host();
$t=qq{$S fails when called against a non datadir datadir};
-like ($cp->run("-c 10 --datadir=$host"), qr{ERROR:.+could not read the given data directory}, $t);
+like ($cp->run(qq{-c 10 --datadir="$host"}), qr{ERROR:.+could not read the given data directory}, $t);
$t=qq{$S works when called for a recent checkpoint};
my $dbh = $cp->get_dbh();
$dbh->do('CHECKPOINT');
$dbh->commit();
$host =~ s/socket$//;
-like ($cp->run("-w 20 --datadir=$host"), qr{POSTGRES_CHECKPOINT OK}, $t);
+like ($cp->run(qq{-w 20 --datadir="$host"}), qr{POSTGRES_CHECKPOINT OK}, $t);
$t=qq{$S returns a warning when checkpoint older than warning option};
sleep 2;
-like ($cp->run("-w 1 --datadir=$host"), qr{WARNING:}, $t);
+like ($cp->run(qq{-w 1 --datadir="$host"}), qr{WARNING:}, $t);
$t=qq{$S returns a critical when checkpoint older than critical option};
-like ($cp->run("-c 1 --datadir=$host"), qr{CRITICAL:}, $t);
+like ($cp->run(qq{-c 1 --datadir="$host"}), qr{CRITICAL:}, $t);
$t=qq{$S returns the correct number of seconds};
-like ($cp->run("-c 1 --datadir=$host"), qr{was \d seconds ago}, $t);
+like ($cp->run(qq{-c 1 --datadir="$host"}), qr{was \d seconds ago}, $t);
$t=qq{$S returns the expected output for MRTG};
-like ($cp->run("-c 1 --output=MRTG --datadir=$host"), qr{^\d\n0\n\nLast checkpoint was \d seconds ago}, $t);
+like ($cp->run(qq{-c 1 --output=MRTG --datadir="$host"}), qr{^\d\n0\n\nLast checkpoint was \d seconds ago}, $t);
$t=qq{$S returns the expected output for MRTG};
-like ($cp->run("-c 199 --output=MRTG --datadir=$host"), qr{^\d\n0\n\nLast checkpoint was \d seconds ago}, $t);
+like ($cp->run(qq{-c 199 --output=MRTG --datadir="$host"}), qr{^\d\n0\n\nLast checkpoint was \d seconds ago}, $t);
exit;
my $self = shift;
my $dbdir = $self->{dbdir} or die;
- my $pidfile = "$dbdir/data/postmaster.pid";
+ my $pidfile = "$dbdir/data space/postmaster.pid";
return if ! -e $pidfile;
open my $fh, '<', $pidfile or die qq{Could not open "$pidfile": $!\n};
<$fh> =~ /^(\d+)/ or die qq{File "$pidfile" did not start with a number!\n};
: $ENV{PGBINDIR} ? "$ENV{PGBINDIR}/initdb"
: 'initdb';
- $com = qq{LC_ALL=en LANG=C $initdb --locale=C -E UTF8 -D $dbdir/data 2>&1};
+ $com = qq{LC_ALL=en LANG=C $initdb --locale=C -E UTF8 -D "$dbdir/data space" 2>&1};
eval {
$info = qx{$com};
};
}
## Modify the postgresql.conf
- my $cfile = "$dbdir/data/postgresql.conf";
+ my $cfile = "$dbdir/data space/postgresql.conf";
open my $cfh, '>>', $cfile or die qq{Could not open "$cfile": $!\n};
print $cfh qq{\n\n## check_postgres.pl testing parameters\n};
print $cfh qq{listen_addresses = ''\n};
print $cfh "\n";
close $cfh or die qq{Could not close "$cfile": $!\n};
- mkdir "$dbdir/data/socket";
+ mkdir "$dbdir/data space/socket";
}
## See if the database is already running.
my $needs_startup = 0;
- my $pidfile = "$dbdir/data/postmaster.pid";
+ my $pidfile = "$dbdir/data space/postmaster.pid";
if (! -e $pidfile) {
$needs_startup = 1;
}
: $ENV{PGBINDIR} ? "$ENV{PGBINDIR}/pg_ctl"
: 'pg_ctl';
- $com = qq{LC_ALL=en LANG=C $pg_ctl -o '-k socket' -l $logfile -D "$dbdir/data" start};
+ $com = qq{LC_ALL=en LANG=C $pg_ctl -o '-k socket' -l $logfile -D "$dbdir/data space" start};
eval {
$info = qx{$com};
};
} ## end of needs startup
my $here = cwd();
- my $dbhost = $self->{dbhost} = "$here/$dbdir/data/socket";
+ my $dbhost = $self->{dbhost} = "$here/$dbdir/data space/socket";
$dbhost =~ s/^ /\\ /;
$dbhost =~ s/([^\\]) /$1\\ /g;
$self->{dbname} ||= 'postgres';