[check_postgres] [commit] More tweaks to support Postgres 8.0

check_postgres at bucardo.org check_postgres at bucardo.org
Thu Apr 30 21:38:12 UTC 2009


Committed by Greg Sabino Mullane <greg at endpoint.com>

More tweaks to support Postgres 8.0

---
 check_postgres.pl        |   40 ++++++++++++++++++++++++----------------
 t/02_backends.t          |   34 ++++++++++++++++++++++------------
 t/02_bloat.t             |    6 ++++--
 t/02_database_size.t     |   40 +++++++++++++++++++++++++++-------------
 t/02_disabled_triggers.t |   13 +++++++++++++
 t/02_prepared_txns.t     |   13 +++++++++++++
 t/02_query_time.t        |   10 ++++++++++
 t/02_relation_size.t     |   13 +++++++++++++
 t/02_replicate_row.t     |    8 +++++++-
 t/02_sequence.t          |   15 +++++++++++++++
 t/02_wal_files.t         |   26 ++++++++++++++++++++------
 t/CP_Testing.pm          |   40 ++++++++++++++++++++++++++--------------
 12 files changed, 194 insertions(+), 64 deletions(-)

diff --git a/check_postgres.pl b/check_postgres.pl
index 978cea7..8144315 100755
--- a/check_postgres.pl
+++ b/check_postgres.pl
@@ -990,21 +990,24 @@ our $checksumre = qr{^[a-f0-9]{32}$};
 
 ## If in test mode, verify that we can run each requested action
 our %testaction = (
-				  autovac_freeze   => 'VERSION: 8.2',
-				  last_vacuum      => 'ON: stats_row_level(<8.3) VERSION: 8.2',
-				  last_analyze     => 'ON: stats_row_level(<8.3) VERSION: 8.2',
-				  last_autovacuum  => 'ON: stats_row_level(<8.3) VERSION: 8.2',
-				  last_autoanalyze => 'ON: stats_row_level(<8.3) VERSION: 8.2',
-				  database_size    => 'VERSION: 8.1',
-				  relation_size    => 'VERSION: 8.1',
-				  table_size       => 'VERSION: 8.1',
-				  index_size       => 'VERSION: 8.1',
-				  query_time       => 'ON: stats_command_string(<8.3) VERSION: 8.0',
-				  txn_idle         => 'ON: stats_command_string(<8.3) VERSION: 8.0',
-				  txn_time         => 'VERSION: 8.3',
-				  wal_files        => 'VERSION: 8.1',
-				  fsm_pages        => 'VERSION: 8.2 MAX: 8.3',
-				  fsm_relations    => 'VERSION: 8.2 MAX: 8.3',
+				  autovac_freeze    => 'VERSION: 8.2',
+				  last_vacuum       => 'ON: stats_row_level(<8.3) VERSION: 8.2',
+				  last_analyze      => 'ON: stats_row_level(<8.3) VERSION: 8.2',
+				  last_autovacuum   => 'ON: stats_row_level(<8.3) VERSION: 8.2',
+				  last_autoanalyze  => 'ON: stats_row_level(<8.3) VERSION: 8.2',
+				  prepared_txns     => 'VERSION: 8.1',
+				  database_size     => 'VERSION: 8.1',
+				  disabled_triggers => 'VERSION: 8.1',
+				  relation_size     => 'VERSION: 8.1',
+				  sequence          => 'VERSION: 8.1',
+				  table_size        => 'VERSION: 8.1',
+				  index_size        => 'VERSION: 8.1',
+				  query_time        => 'ON: stats_command_string(<8.3) VERSION: 8.0',
+				  txn_idle          => 'ON: stats_command_string(<8.3) VERSION: 8.0',
+				  txn_time          => 'VERSION: 8.3',
+				  wal_files         => 'VERSION: 8.1',
+				  fsm_pages         => 'VERSION: 8.2 MAX: 8.3',
+				  fsm_relations     => 'VERSION: 8.2 MAX: 8.3',
 );
 if ($opt{test}) {
 	print msgn('testmode-start');
@@ -4458,13 +4461,18 @@ sub check_disabled_triggers {
 
 	$SQL = q{SELECT tgrelid::regclass, tgname, tgenabled FROM pg_trigger WHERE tgenabled IS NOT TRUE ORDER BY tgname};
 	my $SQL83 = q{SELECT tgrelid::regclass, tgname, tgenabled FROM pg_trigger WHERE tgenabled = 'D' ORDER BY tgname};
+	my $SQLOLD = q{SELECT 'FAIL'};
 
-	my $info = run_command($SQL, { version => [ ">8.2 $SQL83" ] } );
+	my $info = run_command($SQL, { version => [ ">8.2 $SQL83", "<8.1 $SQLOLD" ] } );
 
 	my $count = 0;
 	my $dislis = '';
 	for (@{$info->{db}}) {
 		$db = $_;
+
+		if ($db->{slurp} =~ /^\s*FAIL/) {
+			ndie msg('die-action-version', $action, '8.1', $db->{version});
+		}
 		while ($db->{slurp} =~ / (.+?)\s+\| (.+?)\s+\| (\w+)/gsm) {
 			my ($table,$trigger,$setting) = ($1,$2,$3);
 			$count++;
diff --git a/t/02_backends.t b/t/02_backends.t
index 609d8ab..3420a5f 100644
--- a/t/02_backends.t
+++ b/t/02_backends.t
@@ -41,7 +41,8 @@ like ($result, qr{^POSTGRES_BACKENDS OK: \(host:$host\)}, $t);
 
 $t=qq{$S returned correct connection count};
 SKIP: {
-	skip 'Cannot test backends completely with older version of Postgres', 3;
+
+	$goodver or skip 'Cannot test backends completely with older versions of Postgres', 3;
 
 	like ($result, qr{^POSTGRES_BACKENDS OK: \(host:$host\) 2 of 10 connections}, $t);
 
@@ -148,24 +149,33 @@ is ($cp->run('--output=MRTG'), qq{$num\n0\n\nDB=postgres Max connections=10\n},
 $t=qq{$S works when include forces no matches};
 like ($cp->run('--include=foobar'), qr{POSTGRES_BACKENDS OK: .+No connections}, $t);
 
-$t=qq{$S works when include has valid database};
-$num = $goodver ? 3 : 2;
-like ($cp->run('--include=postgres'), qr{POSTGRES_BACKENDS OK: .+$num of 10}, $t);
+SKIP: {
+
+	$goodver or skip 'Cannot test backends completely with older versions of Postgres', 1;
+
+	$t=qq{$S works when include has valid database};
+	like ($cp->run('--include=postgres'), qr{POSTGRES_BACKENDS OK: .+3 of 10}, $t);
+}
 
 $t=qq{$S works when exclude forces no matches};
 like ($cp->run('--exclude=postgres'), qr{POSTGRES_BACKENDS OK: .+No connections}, $t);
 
-$t=qq{$S works when exclude excludes nothing};
-like ($cp->run('--exclude=foobar'), qr{POSTGRES_BACKENDS OK: .+$num of 10}, $t);
+SKIP: {
+
+	$goodver or skip 'Cannot test backends completely with older versions of Postgres', 4;
 
-$t=qq{$S works when include and exclude make a match};
-like ($cp->run('--exclude=postgres --include=postgres'), qr{POSTGRES_BACKENDS OK: .+$num of 10}, $t);
+	$t=qq{$S works when exclude excludes nothing};
+	like ($cp->run('--exclude=foobar'), qr{POSTGRES_BACKENDS OK: .+3 of 10}, $t);
 
-$t=qq{$S works when include and exclude make a match};
-like ($cp->run('--include=postgres --exclude=postgres'), qr{POSTGRES_BACKENDS OK: .+$num of 10}, $t);
+	$t=qq{$S works when include and exclude make a match};
+	like ($cp->run('--exclude=postgres --include=postgres'), qr{POSTGRES_BACKENDS OK: .+3 of 10}, $t);
 
-$t=qq{$S returned correct performance data with include};
-like ($cp->run('--include=postgres'), qr{ \| time=(\d\.\d\d)  ardala=0 beedeebeedee=0 postgres=$num}, $t);
+	$t=qq{$S works when include and exclude make a match};
+	like ($cp->run('--include=postgres --exclude=postgres'), qr{POSTGRES_BACKENDS OK: .+3 of 10}, $t);
+
+	$t=qq{$S returned correct performance data with include};
+	like ($cp->run('--include=postgres'), qr{ \| time=(\d\.\d\d)  ardala=0 beedeebeedee=0 postgres=3}, $t);
+}
 
 $cp->drop_schema_if_exists();
 
diff --git a/t/02_bloat.t b/t/02_bloat.t
index 72b0299..1380797 100644
--- a/t/02_bloat.t
+++ b/t/02_bloat.t
@@ -29,6 +29,7 @@ like ($cp->run('-c=abc'), qr{must be a size or a percentage}, $t);
 
 $dbh->{AutoCommit} = 1;
 $dbh->do('VACUUM FULL');
+$dbh->{AutoCommit} = 0;
 
 $t=qq{$S returns ok for no bloat};
 like ($cp->run('-c=99GB'), qr{^$label OK: DB "postgres"}, $t);
@@ -38,10 +39,10 @@ like ($cp->run('-w=10MB'), qr{^$label OK: DB "postgres"}, $t);
 
 for my $size (qw/bytes kilobytes megabytes gigabytes terabytes exabytes petabytes zettabytes/) {
 	$t=qq{$S returns ok for no bloat with a unit of $size};
-	like ($cp->run("-w=100000$size"), qr{^$label OK: DB "postgres"}, $t);
+	like ($cp->run("-w=1000000$size"), qr{^$label OK: DB "postgres"}, $t);
 	my $short = substr($size, 0, 1);
 	$t=qq{$S returns ok for no bloat with a unit of $short};
-	like ($cp->run("-w=100000$short"), qr{^$label OK: DB "postgres"}, $t);
+	like ($cp->run("-w=1000000$short"), qr{^$label OK: DB "postgres"}, $t);
 }
 
 $t=qq{$S returns correct message if no tables due to exclusion};
@@ -55,6 +56,7 @@ $cp->drop_table_if_exists($tname);
 $dbh->do("CREATE TABLE $tname AS SELECT 123::int AS foo FROM generate_series(1,10000)");
 $dbh->do("UPDATE $tname SET foo = foo") for 1..1;
 $dbh->do('ANALYZE');
+$dbh->commit();
 
 $t=qq{$S returns warning for bloated table};
 like ($cp->run('-w 100000'), qr{^$label WARNING:.+$tname}, $t);
diff --git a/t/02_database_size.t b/t/02_database_size.t
index 9a6cf8d..ba348d8 100644
--- a/t/02_database_size.t
+++ b/t/02_database_size.t
@@ -17,26 +17,40 @@ my $cp = CP_Testing->new({default_action => 'database_size'});
 $dbh = $cp->test_database_handle();
 
 my $S = q{Action 'database_size'};
+my $label = 'POSTGRES_DATABASE_SIZE';
 
 $t=qq{$S returned expected text when no warning/critical size is provided};
 like ($cp->run(''), qr{^ERROR: Must provide a warning and/or critical size}, $t);
 
+my $ver = $dbh->{pg_server_version};
+if ($ver < 80100) {
+
+	$t=qq{$S gives an error when run against an old Postgres version};
+	like ($cp->run('--warning=99'), qr{ERROR.*server version must be >= 8.1}, $t);
+
+  SKIP: {
+		skip 'Cannot test database_size completely on Postgres 8.0 or lower', 47;
+	}
+
+	exit;
+}
+
 $cp->drop_all_tables();
 
 for my $type (qw/b bs k kb kbs m mb mbs g gb gbs t tb tbs p pb pbs e eb ebs z zb zbs/) {
 	my $opt = "-w 9999999$type";
 	$t=qq{$S returned expected text when warning level is specified in $type};
-	like ($cp->run($opt), qr{^POSTGRES_DATABASE_SIZE OK:}, $t);
+	like ($cp->run($opt), qr{^$label OK:}, $t);
 }
 
 $t=qq{$S returned expected text when warning level is specified in nothing};
-like ($cp->run('-w 1'), qr{^POSTGRES_DATABASE_SIZE WARNING:}, $t);
+like ($cp->run('-w 1'), qr{^$label WARNING:}, $t);
 
 $t=qq{$S returned expected text when critical level is specified};
-like ($cp->run('-c 10GB'), qr{^POSTGRES_DATABASE_SIZE OK:}, $t);
+like ($cp->run('-c 10GB'), qr{^$label OK:}, $t);
 
 $t=qq{$S returned expected text when warning level and critical level are specified};
-like ($cp->run('-w 10GB -c 20GB'), qr{^POSTGRES_DATABASE_SIZE OK:}, $t);
+like ($cp->run('-w 10GB -c 20GB'), qr{^$label OK:}, $t);
 
 $t=qq{$S fails when called with an invalid option};
 like ($cp->run('foobar=12'), qr{^\s*Usage:}, $t);
@@ -63,17 +77,17 @@ $user = $cp->get_user();
 $dbh->{AutoCommit} = 1;
 $dbh->do("CREATE DATABASE blargy WITH OWNER $user");
 $dbh->{AutoCommit} = 0;
-like ($cp->run("--includeuser $user -w 10g"), qr{^POSTGRES_DATABASE_SIZE OK:.+ blargy}, $t);
+like ($cp->run("--includeuser $user -w 10g"), qr{^$label OK:.+ blargy}, $t);
 $dbh->{AutoCommit} = 1;
 $dbh->do('DROP DATABASE blargy');
 $dbh->{AutoCommit} = 0;
 
 $t=qq{$S with includeuser option returns nothing};
-like ($cp->run('--includeuser mycatbeda -w 10g'), qr{^POSTGRES_DATABASE_SIZE OK:.+ }, $t);
+like ($cp->run('--includeuser mycatbeda -w 10g'), qr{^$label OK:.+ }, $t);
 
 $t=qq{$S has critical option trump the warning option};
-like ($cp->run('-w 1 -c 1'), qr{^POSTGRES_DATABASE_SIZE CRITICAL}, $t);
-like ($cp->run('--critical=1 --warning=0'), qr{^POSTGRES_DATABASE_SIZE CRITICAL}, $t);
+like ($cp->run('-w 1 -c 1'), qr{^$label CRITICAL}, $t);
+like ($cp->run('--critical=1 --warning=0'), qr{^$label CRITICAL}, $t);
 
 $t=qq{$S returns correct MRTG output when no rows found};
 like ($cp->run('--output=MRTG -w 10g --includeuser nosuchuser'), qr{^-1}, $t);
@@ -82,19 +96,19 @@ $t=qq{$S returns correct MRTG output when rows found};
 like ($cp->run('--output=MRTG -w 10g'), qr{\d+\n0\n\nDB: postgres\n}s, $t);
 
 $t=qq{$S works when include forces no matches};
-like ($cp->run('-w 1 --include blargy'), qr{^POSTGRES_DATABASE_SIZE UNKNOWN: .+No matching databases}, $t);
+like ($cp->run('-w 1 --include blargy'), qr{^$label UNKNOWN: .+No matching databases}, $t);
 
 $t=qq{$S works when include has valid database};
-like ($cp->run('-w 1 --include=postgres'), qr{POSTGRES_DATABASE_SIZE WARNING: .+postgres}, $t);
+like ($cp->run('-w 1 --include=postgres'), qr{$label WARNING: .+postgres}, $t);
 
 $t=qq{$S works when exclude excludes nothing};
-like ($cp->run('-w 10g --exclude=foobar'), qr{POSTGRES_DATABASE_SIZE OK: DB "postgres"}, $t);
+like ($cp->run('-w 10g --exclude=foobar'), qr{$label OK: DB "postgres"}, $t);
 
 $t=qq{$S works when include and exclude make a match};
-like ($cp->run('-w 5g --exclude=postgres --include=postgres'), qr{POSTGRES_DATABASE_SIZE OK: DB "postgres"}, $t);
+like ($cp->run('-w 5g --exclude=postgres --include=postgres'), qr{$label OK: DB "postgres"}, $t);
 
 $t=qq{$S works when exclude and include make a match};
-like ($cp->run('-w 5g --include=postgres --exclude=postgres'), qr{POSTGRES_DATABASE_SIZE OK: DB "postgres"}, $t);
+like ($cp->run('-w 5g --include=postgres --exclude=postgres'), qr{$label OK: DB "postgres"}, $t);
 
 $t=qq{$S returned correct performance data with include};
 like ($cp->run('-w 5g --include=postgres'), qr{ \| time=\d\.\d\d  postgres=\d+}, $t);
diff --git a/t/02_disabled_triggers.t b/t/02_disabled_triggers.t
index b163038..8d40afe 100644
--- a/t/02_disabled_triggers.t
+++ b/t/02_disabled_triggers.t
@@ -24,6 +24,19 @@ my $label = 'POSTGRES_DISABLED_TRIGGERS';
 
 my $S = q{Action 'disabled_triggers'};
 
+my $ver = $dbh->{pg_server_version};
+if ($ver < 80100) {
+
+	$t=qq{$S gives an error when run against an old Postgres version};
+	like ($cp->run('--warning=99'), qr{ERROR.*server version must be >= 8.1}, $t);
+
+  SKIP: {
+		skip 'Cannot test disabled_triggers completely on Postgres 8.0 or lower', 12;
+	}
+
+	exit;
+}
+
 $t = qq{$S self-identifies correctly};
 $result = $cp->run();
 like ($result, qr{^$label}, $t);
diff --git a/t/02_prepared_txns.t b/t/02_prepared_txns.t
index 72f3561..56a8b0f 100644
--- a/t/02_prepared_txns.t
+++ b/t/02_prepared_txns.t
@@ -22,6 +22,19 @@ my $label = 'POSTGRES_PREPARED_TXNS';
 $t=qq{$S fails when called with an invalid option};
 like ($cp->run('foobar=12'), qr{^\s*Usage:}, $t);
 
+my $ver = $dbh->{pg_server_version};
+if ($ver < 80100) {
+
+	$t=qq{$S gives an error when run against an old Postgres version};
+	like ($cp->run('--warning=99'), qr{ERROR.*server version must be >= 8.1}, $t);
+
+  SKIP: {
+		skip 'Cannot test prepared_transacions completely on Postgres 8.0 or lower', 8;
+	}
+
+	exit;
+}
+
 ## Clear any outstanding transactions
 $info = $dbh->selectall_arrayref('SELECT gid FROM pg_prepared_xacts');
 $dbh->{AutoCommit} = 1;
diff --git a/t/02_query_time.t b/t/02_query_time.t
index a851106..6cc1333 100644
--- a/t/02_query_time.t
+++ b/t/02_query_time.t
@@ -48,6 +48,16 @@ for ('-1 second',
    like ($cp->run(qq{-w "$_"}), qr/^ERROR: Value for 'warning' must be a valid time/, $t . " ($_)");
 }
 
+my $ver = $dbh->{pg_server_version};
+if ($ver < 80100) {
+
+  SKIP: {
+		skip 'Cannot test query_time on Postgres 8.0 or lower', 1;
+	}
+
+	exit;
+}
+
 my $child = fork();
 if ($child == 0) {
     my $kiddbh = $cp->test_database_handle();
diff --git a/t/02_relation_size.t b/t/02_relation_size.t
index add51b6..db8ccad 100644
--- a/t/02_relation_size.t
+++ b/t/02_relation_size.t
@@ -30,6 +30,19 @@ $t = qq{$S reports error when warning/critical invalid};
 is ($cp->run(q{-w -1}), qq{ERROR: Invalid size for 'warning' option\n}, $t);
 is ($cp->run(q{-c -1}), qq{ERROR: Invalid size for 'critical' option\n}, $t);
 
+my $ver = $dbh->{pg_server_version};
+if ($ver < 80100) {
+
+	$t=qq{$S gives an error when run against an old Postgres version};
+	like ($cp->run('--warning=99'), qr{ERROR.*server version must be >= 8.1}, $t);
+
+  SKIP: {
+		skip 'Cannot test relation_size completely on Postgres 8.0 or lower', 19;
+	}
+
+	exit;
+}
+
 $result = $cp->run(q{-w 1});
 
 $t = qq{$S self-identifies};
diff --git a/t/02_replicate_row.t b/t/02_replicate_row.t
index 05bb063..248e59d 100644
--- a/t/02_replicate_row.t
+++ b/t/02_replicate_row.t
@@ -24,7 +24,13 @@ if (! $cp->table_exists($dbh, 'reptest')) {
 if (! $cp->table_exists($dbh2, 'reptest')) {
 	$dbh2->do($SQL);
 }
-$SQL = q{TRUNCATE TABLE reptest; INSERT INTO reptest VALUES (1,'yin'), (2,'yang')};
+$SQL = q{TRUNCATE TABLE reptest};
+$dbh->do($SQL);
+$dbh2->do($SQL);
+$SQL = q{INSERT INTO reptest VALUES (1,'yin')};
+$dbh->do($SQL);
+$dbh2->do($SQL);
+$SQL = q{INSERT INTO reptest VALUES (2,'yang')};
 $dbh->do($SQL);
 $dbh2->do($SQL);
 
diff --git a/t/02_sequence.t b/t/02_sequence.t
index 6be4387..8f10f70 100644
--- a/t/02_sequence.t
+++ b/t/02_sequence.t
@@ -17,6 +17,7 @@ my $cp = CP_Testing->new( {default_action => 'sequence'} );
 $dbh = $cp->test_database_handle();
 
 my $S = q{Action 'sequence'};
+my $label = 'POSTGRES_SEQUENCE';
 
 $t=qq{$S fails when called with an invalid option};
 like ($cp->run('foobar=12'), qr{^\s*Usage:}, $t);
@@ -27,6 +28,20 @@ like ($cp->run('--warning=80'), qr{ERROR:.+must be a percentage}, $t);
 $t=qq{$S fails when called with an invalid option};
 like ($cp->run('--critical=80'), qr{ERROR:.+must be a percentage}, $t);
 
+my $ver = $dbh->{pg_server_version};
+if ($ver < 80100) {
+
+	$t=qq{$S gives an error when run against an old Postgres version};
+	like ($cp->run('--warning=1%'), qr{ERROR.*server version must be >= 8.1}, $t);
+
+  SKIP: {
+		skip 'Cannot test sequence completely on Postgres 8.0 or lower', 7;
+	}
+
+	exit;
+}
+
+
 my $seqname = 'cp_test_sequence';
 $cp->drop_sequence_if_exists($seqname);
 
diff --git a/t/02_wal_files.t b/t/02_wal_files.t
index 9320fa4..c8ee625 100644
--- a/t/02_wal_files.t
+++ b/t/02_wal_files.t
@@ -17,6 +17,7 @@ my $cp = CP_Testing->new({default_action => 'wal_files'});
 $dbh = $cp->test_database_handle();
 
 my $S = q{Action 'wal_files'};
+my $label = 'POSTGRES_WAL_FILES';
 
 $t=qq{$S fails when called with an invalid option};
 like ($cp->run('foobar=12'), qr{^\s*Usage:}, $t);
@@ -25,24 +26,37 @@ $t=qq{$S fails when called with an invalid option};
 like ($cp->run('--warning=30%'), qr{ERROR:.+must be an integer}, $t);
 like ($cp->run('--warning=-30'), qr{ERROR:.+must be an integer}, $t);
 
+my $ver = $dbh->{pg_server_version};
+if ($ver < 80100) {
+
+	$t=qq{$S gives an error when run against an old Postgres version};
+	like ($cp->run('--warning=99'), qr{ERROR.*server version must be >= 8.1}, $t);
+
+  SKIP: {
+		skip 'Cannot test wal_files completely on Postgres 8.0 or lower', 7;
+	}
+
+	exit;
+}
+
 $t=qq{$S works as expected for warnings};
-like ($cp->run('--warning=30'), qr{POSTGRES_WAL_FILES OK}, $t);
-like ($cp->run('--warning=0'), qr{POSTGRES_WAL_FILES WARNING}, $t);
+like ($cp->run('--warning=30'), qr{^$label OK}, $t);
+like ($cp->run('--warning=0'), qr{^$label WARNING}, $t);
 
 $t=qq{$S works as expected for criticals};
-like ($cp->run('--critical=30'), qr{POSTGRES_WAL_FILES OK}, $t);
-like ($cp->run('--critical=0'), qr{POSTGRES_WAL_FILES CRITICAL}, $t);
+like ($cp->run('--critical=30'), qr{^$label OK}, $t);
+like ($cp->run('--critical=0'), qr{^$label CRITICAL}, $t);
 
 $cp->drop_schema_if_exists();
 $cp->create_fake_pg_table('pg_ls_dir', 'text');
 
-like ($cp->run('--critical=1'), qr{POSTGRES_WAL_FILES OK}, $t);
+like ($cp->run('--critical=1'), qr{^$label OK}, $t);
 
 $dbh->do(q{INSERT INTO cptest.pg_ls_dir SELECT 'ABCDEF123456ABCDEF123456' FROM generate_series(1,99)});
 $dbh->commit();
 
 $t=qq{$S returns correct number of files};
-like ($cp->run('--critical=1'), qr{POSTGRES_WAL_FILES CRITICAL.+ 99 \|}, $t);
+like ($cp->run('--critical=1'), qr{^$label CRITICAL.+ 99 \|}, $t);
 
 $t=qq{$S returns correct MRTG information};
 is ($cp->run('--critical=1 --output=mrtg'), "99\n0\n\n\n", $t);
diff --git a/t/CP_Testing.pm b/t/CP_Testing.pm
index b4d9f78..9106abc 100644
--- a/t/CP_Testing.pm
+++ b/t/CP_Testing.pm
@@ -131,22 +131,22 @@ sub test_database_handle {
 		}
 	}
 
+	my $pg_ctl
+		= $ENV{PG_CTL}   ? $ENV{PG_CTL}
+		: $ENV{PGBINDIR} ? "$ENV{PGBINDIR}/pg_ctl"
+		:                  'pg_ctl';
+
+	if (qx{$pg_ctl --version} !~ /(\d+)\.(\d+)/) {
+		die qq{Could not determine the version of pg_ctl in use!\n};
+	}
+	my ($maj,$min) = ($1,$2);
+
 	if ($needs_startup) {
 
 		my $logfile = "$dbdir/pg.log";
 
 		unlink $logfile;
 
-		my $pg_ctl
-			= $ENV{PG_CTL}   ? $ENV{PG_CTL}
-			: $ENV{PGBINDIR} ? "$ENV{PGBINDIR}/pg_ctl"
-			:                  'pg_ctl';
-
-		if (qx{$pg_ctl --version} !~ /(\d+)\.(\d+)/) {
-			die qq{Could not determine the version of pg_ctl in use!\n};
-		}
-		my ($maj,$min) = ($1,$2);
-
 		my $sockdir = 'socket';
 		if ($maj < 8 or ($maj==8 and $min < 1)) {
 			$sockdir = qq{"$dbdir/data space/socket"};
@@ -187,7 +187,12 @@ sub test_database_handle {
 			$COM = qq{psql -d template1 -q -h "$host" -c "CREATE USER $newuser"};
 			system $COM;
 			my $SQL = q{UPDATE pg_shadow SET usesuper='t' WHERE usename = 'check_postgres_testing'};
-			$COM = qq{psql -d template1 -q -h "$host" -c "$SQL"};
+			$COM = qq{psql -d postgres -q -h "$host" -c "$SQL"};
+			system $COM;
+			my $createlang = $ENV{PGBINDIR} ? "$ENV{PGBINDIR}/createlang" : 'pg_ctl';
+			$COM = qq{$createlang -d postgres -h "$host" plperlu};
+			system $COM;
+			$COM = qq{$createlang -d postgres -h "$host" plpgsql};
 			system $COM;
 		}
 
@@ -218,9 +223,16 @@ sub test_database_handle {
 
 	$dbh->{AutoCommit} = 1;
 	$dbh->{RaiseError} = 0;
-	$dbh->do("CREATE USER $dbuser SUPERUSER");
-	$dbh->do('CREATE USER sixpack NOSUPERUSER CREATEDB');
-	$dbh->do('CREATE USER readonly NOSUPERUSER NOCREATEDB');
+	if ($maj < 8 or ($maj==8 and $min < 1)) {
+		## Old school
+		$dbh->do('CREATE USER sixpack');
+		$dbh->do('CREATE USER readonly');
+	}
+	else {
+		$dbh->do("CREATE USER $dbuser SUPERUSER");
+		$dbh->do('CREATE USER sixpack NOSUPERUSER CREATEDB');
+		$dbh->do('CREATE USER readonly NOSUPERUSER NOCREATEDB');
+	}
 	$dbh->do('ALTER USER readonly SET default_transaction_read_only = 1');
 	$dbh->do('CREATE DATABASE beedeebeedee');
 	$dbh->do('CREATE DATABASE ardala');
-- 
1.6.0.5



More information about the Check_postgres mailing list