[check_postgres] [commit] More support for older versions of Postgres, other cleanups.

check_postgres at bucardo.org check_postgres at bucardo.org
Thu Apr 30 13:26:57 UTC 2009


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

More support for older versions of Postgres, other cleanups.

---
 check_postgres.pl     |    2 +-
 t/02_autovac_freeze.t |   10 +++++++
 t/02_backends.t       |   68 +++++++++++++++++++++++++++++-------------------
 t/02_last_analyze.t   |    8 ++++++
 t/02_last_vacuum.t    |    8 ++++++
 t/02_logfile.t        |    2 +-
 t/02_query_time.t     |    6 +++-
 t/02_txn_idle.t       |   10 ++++---
 t/02_txn_wraparound.t |    4 +-
 t/02_version.t        |    2 +-
 t/02_wal_files.t      |    4 +-
 t/99_perlcritic.t     |    4 +-
 t/CP_Testing.pm       |   59 +++++++++++++++++++++++++++++++-----------
 13 files changed, 130 insertions(+), 57 deletions(-)

diff --git a/check_postgres.pl b/check_postgres.pl
index 8bd874c..978cea7 100755
--- a/check_postgres.pl
+++ b/check_postgres.pl
@@ -1760,7 +1760,7 @@ sub verify_version {
 			ndie msg('die-nosetting', $setting);
 		}
 		my $val = $info2->{db}[0]{slurp};
-		if ($val !~ /^on\b/) {
+		if ($val !~ /^\s*on\b/) {
 			ndie msg('die-noset', $action, $setting);
 		}
 	}
diff --git a/t/02_autovac_freeze.t b/t/02_autovac_freeze.t
index a24be52..a442628 100644
--- a/t/02_autovac_freeze.t
+++ b/t/02_autovac_freeze.t
@@ -18,10 +18,16 @@ $dbh = $cp->test_database_handle();
 $dbh->{AutoCommit} = 1;
 $dbname = $cp->get_dbname;
 $host = $cp->get_host();
+my $ver = $dbh->{pg_server_version};
+
 my $label = 'POSTGRES_AUTOVAC_FREEZE';
 
 my $S = q{Action 'autovac_freeze'};
 
+SKIP:
+{
+	$ver < 80200 and skip 'Cannot test autovac_freeze on old Postgres versions', 8;
+
 $t = qq{$S self-identifies correctly};
 $result = $cp->run(q{-w 0%});
 like ($result, qr{^$label}, $t);
@@ -46,3 +52,7 @@ like ($cp->run('-w 99%'), qr{$label OK:.*ardala=\d+%.*?beedeebeedee=\d+%.*?postg
 
 $t=qq{$S produces MRTG output};
 like ($cp->run('--output=mrtg -w 99%'), qr{0\n\d+\n\nardala \| beedeebeedee \| postgres \| template1\n}, $t);
+
+}
+
+exit;
diff --git a/t/02_backends.t b/t/02_backends.t
index 73933c8..609d8ab 100644
--- a/t/02_backends.t
+++ b/t/02_backends.t
@@ -16,13 +16,16 @@ my $cp = CP_Testing->new( {default_action => 'backends'} );
 
 $dbh = $cp->test_database_handle();
 
+my $ver = $dbh->{pg_server_version};
+my $goodver = $ver >= 80200 ? 1 : 0;
+
 ## Check current number of connections: should be 1 (for recent versions of PG)
 $SQL = 'SELECT count(*) FROM pg_stat_activity';
 $count = $dbh->selectall_arrayref($SQL)->[0][0];
 
 $t=q{Current number of backends is one (ourselves)};
-is ($count, 1, $t);
-1==$count or BAIL_OUT "Cannot continue unless we start from a sane connection count\n";
+$count <= 1 or BAIL_OUT "Cannot continue unless we start from a sane connection count\n";
+pass $t;
 
 $host = $cp->get_host();
 
@@ -37,13 +40,17 @@ $t=qq{$S returned correct host name};
 like ($result, qr{^POSTGRES_BACKENDS OK: \(host:$host\)}, $t);
 
 $t=qq{$S returned correct connection count};
-like ($result, qr{^POSTGRES_BACKENDS OK: \(host:$host\) 2 of 10 connections}, $t);
+SKIP: {
+	skip 'Cannot test backends completely with older version of Postgres', 3;
+
+	like ($result, qr{^POSTGRES_BACKENDS OK: \(host:$host\) 2 of 10 connections}, $t);
 
-$t=qq{$S returned correct percentage};
-like ($result, qr{^POSTGRES_BACKENDS OK: \(host:$host\) 2 of 10 connections \(20%\)}, $t);
+	$t=qq{$S returned correct percentage};
+	like ($result, qr{^POSTGRES_BACKENDS OK: \(host:$host\) 2 of 10 connections \(20%\)}, $t);
 
-$t=qq{$S returned correct performance data};
-like ($result, qr{ \| time=(\d\.\d\d)  ardala=0 beedeebeedee=0 postgres=2 template0=0 template1=0\s$}, $t);
+	$t=qq{$S returned correct performance data};
+	like ($result, qr{ \| time=(\d\.\d\d)  ardala=0 beedeebeedee=0 postgres=2 template0=0 template1=0\s$}, $t);
+}
 
 $t=qq{$S fails when called with an invalid option};
 like ($cp->run('foobar=12'), qr{^\s*Usage:}, $t);
@@ -72,12 +79,15 @@ $t=qq{$S fails when the critical option is a negative percent};
 like ($cp->run('-c -10%'), qr{^ERROR: Cannot specify a negative percent}, $t);
 
 $t=qq{$S with the 'noidle' option returns expected result};
-like ($cp->run('-noidle'), qr{^POSTGRES_BACKENDS OK:.+ 2 of 10 connections}, $t);
+my $num = $goodver ? 2 : 1;
+like ($cp->run('-noidle'), qr{^POSTGRES_BACKENDS OK:.+ $num of 10 connections}, $t);
 $dbh2 = $cp->get_fresh_dbh();
 $dbh2->do('SELECT 123');
-like ($cp->run('-noidle'), qr{^POSTGRES_BACKENDS OK:.+ 3 of 10 connections}, $t);
+$num++ if $goodver;
+like ($cp->run('-noidle'), qr{^POSTGRES_BACKENDS OK:.+ $num of 10 connections}, $t);
 $dbh2->commit();
-like ($cp->run('-noidle'), qr{^POSTGRES_BACKENDS OK:.+ 2 of 10 connections}, $t);
+$num = $goodver ? 2 : '(?:1|2)';
+like ($cp->run('-noidle'), qr{^POSTGRES_BACKENDS OK:.+ $num of 10 connections}, $t);
 
 $t=qq{$S has critical option trump the warning option};
 like ($cp->run('-w 1 -c 1'), qr{^POSTGRES_BACKENDS CRITICAL}, $t);
@@ -85,74 +95,78 @@ like ($cp->run('--critical=1 --warning=0'), qr{^POSTGRES_BACKENDS CRITICAL}, $t)
 
 $t=qq{$S works with warning option as an absolute number};
 like ($cp->run('-w 2'), qr{^POSTGRES_BACKENDS WARNING}, $t);
-like ($cp->run('-w 3'), qr{^POSTGRES_BACKENDS WARNING}, $t);
+$num = $goodver ? 3 : 2;
+like ($cp->run("-w $num"), qr{^POSTGRES_BACKENDS WARNING}, $t);
 like ($cp->run('-w 4'), qr{^POSTGRES_BACKENDS OK}, $t);
 
 $t=qq{$S works with warning option as an percentage};
 like ($cp->run('-w 20%'), qr{^POSTGRES_BACKENDS WARNING}, $t);
-like ($cp->run('-w 30%'), qr{^POSTGRES_BACKENDS WARNING}, $t);
+like ($cp->run("-w ${num}0%"), qr{^POSTGRES_BACKENDS WARNING}, $t);
 like ($cp->run('-w 40%'), qr{^POSTGRES_BACKENDS OK}, $t);
 
 $t=qq{$S works with warning option as a negative number};
 like ($cp->run('-w -6'), qr{^POSTGRES_BACKENDS WARNING}, $t);
 like ($cp->run('-w -7'), qr{^POSTGRES_BACKENDS WARNING}, $t);
-like ($cp->run('-w -8'), qr{^POSTGRES_BACKENDS OK}, $t);
+$num = $goodver ? 8 : 9;
+like ($cp->run("-w -$num"), qr{^POSTGRES_BACKENDS OK}, $t);
 
 $t=qq{$S works with critical option as an absolute number};
 like ($cp->run('-c 2'), qr{^POSTGRES_BACKENDS CRITICAL}, $t);
-like ($cp->run('-c 3'), qr{^POSTGRES_BACKENDS CRITICAL}, $t);
+$num = $goodver ? 3 : 2;
+like ($cp->run("-c $num"), qr{^POSTGRES_BACKENDS CRITICAL}, $t);
 like ($cp->run('-c 4'), qr{^POSTGRES_BACKENDS OK}, $t);
 
 $t=qq{$S works with critical option as an percentage};
 like ($cp->run('-c 20%'), qr{^POSTGRES_BACKENDS CRITICAL}, $t);
-like ($cp->run('-c 30%'), qr{^POSTGRES_BACKENDS CRITICAL}, $t);
+like ($cp->run("-c ${num}0%"), qr{^POSTGRES_BACKENDS CRITICAL}, $t);
 like ($cp->run('-c 40%'), qr{^POSTGRES_BACKENDS OK}, $t);
 
 $t=qq{$S works with critical option as a negative number};
 like ($cp->run('-c -6'), qr{^POSTGRES_BACKENDS CRITICAL}, $t);
 like ($cp->run('-c -7'), qr{^POSTGRES_BACKENDS CRITICAL}, $t);
-like ($cp->run('-c -8'), qr{^POSTGRES_BACKENDS OK}, $t);
+$num = $goodver ? 8 : 9;
+like ($cp->run("-c -$num"), qr{^POSTGRES_BACKENDS OK}, $t);
 
 $t=qq{$S works when no items caught by pg_stat_activity};
 
-$cp->drop_schema_if_exists($fakeschema);
+$cp->drop_schema_if_exists();
 $cp->create_fake_pg_table('pg_stat_activity');
 like ($cp->run(), qr{^POSTGRES_BACKENDS OK: .+No connections}, $t);
 
 $t=qq{$S returns correct MRTG output when no rows};
 is ($cp->run('--output=MRTG'), qq{0\n0\n\nDB=postgres Max connections=10\n}, $t);
 
-$cp->remove_fake_pg_table('pg_stat_activity');
-
 $t=qq{$S fails as expected when max_connections cannot be determined};
 $cp->create_fake_pg_table('pg_settings');
 like ($cp->run(), qr{^POSTGRES_BACKENDS UNKNOWN: .+max_connections}, $t);
-$cp->remove_fake_pg_table('pg_settings');
+$cp->drop_schema_if_exists();
 
 $t=qq{$S returns correct MRTG output when rows found};
-is ($cp->run('--output=MRTG'), qq{3\n0\n\nDB=postgres Max connections=10\n}, $t);
+$num = $goodver ? 3 : 2;
+is ($cp->run('--output=MRTG'), qq{$num\n0\n\nDB=postgres Max connections=10\n}, $t);
 
 $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};
-like ($cp->run('--include=postgres'), qr{POSTGRES_BACKENDS OK: .+3 of 10}, $t);
+$num = $goodver ? 3 : 2;
+like ($cp->run('--include=postgres'), qr{POSTGRES_BACKENDS OK: .+$num 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: .+3 of 10}, $t);
+like ($cp->run('--exclude=foobar'), 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);
+like ($cp->run('--exclude=postgres --include=postgres'), qr{POSTGRES_BACKENDS OK: .+$num 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: .+3 of 10}, $t);
+like ($cp->run('--include=postgres --exclude=postgres'), qr{POSTGRES_BACKENDS OK: .+$num 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);
+like ($cp->run('--include=postgres'), qr{ \| time=(\d\.\d\d)  ardala=0 beedeebeedee=0 postgres=$num}, $t);
 
-$cp->drop_schema_if_exists($fakeschema);
+$cp->drop_schema_if_exists();
 
 exit;
diff --git a/t/02_last_analyze.t b/t/02_last_analyze.t
index efa9461..a3d08c1 100644
--- a/t/02_last_analyze.t
+++ b/t/02_last_analyze.t
@@ -19,10 +19,16 @@ my $cp = CP_Testing->new( {default_action => 'last_analyze'} );
 $dbh = $cp->test_database_handle();
 $dbname = $cp->get_dbname;
 $host = $cp->get_host();
+my $ver = $dbh->{pg_server_version};
+
 my $label = 'POSTGRES_LAST_ANALYZE';
 
 my $S = q{Action 'last_analyze'};
 
+SKIP:
+{
+	$ver < 80200 and skip 'Cannot test autovac_freeze on old Postgres versions', 14;
+
 $t = qq{$S self-identifies correctly};
 $result = $cp->run(q{-w 0});
 like ($result, qr{^$label}, $t);
@@ -76,4 +82,6 @@ $t = qq{$S returns correct MRTG information (fail case)};
 like($cp->run(q{--output=mrtg -w 0 --exclude=~.* --include=no_such_table}),
   qr{0\n0\n\nDB: $dbname TABLE: \?\n}, $t);
 
+}
+
 exit;
diff --git a/t/02_last_vacuum.t b/t/02_last_vacuum.t
index 53cd8e7..e8d1bce 100644
--- a/t/02_last_vacuum.t
+++ b/t/02_last_vacuum.t
@@ -19,10 +19,16 @@ my $cp = CP_Testing->new( {default_action => 'last_vacuum'} );
 $dbh = $cp->test_database_handle();
 $dbname = $cp->get_dbname;
 $host = $cp->get_host();
+my $ver = $dbh->{pg_server_version};
+
 my $label = 'POSTGRES_LAST_VACUUM';
 
 my $S = q{Action 'last_vacuum'};
 
+SKIP:
+{
+	$ver < 80200 and skip 'Cannot test autovac_freeze on old Postgres versions', 14;
+
 $t = qq{$S self-identifies correctly};
 $result = $cp->run(q{-w 0});
 like ($result, qr{^$label}, $t);
@@ -77,4 +83,6 @@ $t = qq{$S returns correct MRTG information (fail case)};
 like ($cp->run('--output=mrtg -w 0 --exclude=~.* --include=no_such_table'),
 	  qr{0\n0\n\nDB: $dbname TABLE: \?\n}, $t);
 
+}
+
 exit;
diff --git a/t/02_logfile.t b/t/02_logfile.t
index ffd3778..239cbb1 100644
--- a/t/02_logfile.t
+++ b/t/02_logfile.t
@@ -34,7 +34,7 @@ like ($result, qr{^$label}, $t);
 $t = qq{$S identifies host};
 like ($result, qr{host:$host}, $t);
 
-$t = qq{$S correctly identified logfile};
+$t = qq{$S correctly identifies logfile};
 like ($result, qr{logs to: $logfile}, $t);
 
 $t = qq{$S correcly identifies host};
diff --git a/t/02_query_time.t b/t/02_query_time.t
index 8366d6e..a851106 100644
--- a/t/02_query_time.t
+++ b/t/02_query_time.t
@@ -51,14 +51,18 @@ for ('-1 second',
 my $child = fork();
 if ($child == 0) {
     my $kiddbh = $cp->test_database_handle();
-    $kiddbh->do(q{SELECT pg_sleep(3)});
+	$cp->database_sleep($kiddbh, 3);
+	$kiddbh->rollback();
     $kiddbh->disconnect;
     exit;
 }
 
 sleep 1;
+$dbh->disconnect();
 $dbh = $cp->test_database_handle();
 $t = qq{$S detects running query};
 like ($cp->run(q{-w 1}), qr{$label WARNING:}, $t);
+$dbh->rollback();
+$dbh->disconnect();
 
 exit;
diff --git a/t/02_txn_idle.t b/t/02_txn_idle.t
index 75e1f8d..16001d5 100644
--- a/t/02_txn_idle.t
+++ b/t/02_txn_idle.t
@@ -30,19 +30,21 @@ $t = qq{$S identifies host};
 like ($result, qr{host:$host}, $t);
 
 $t = qq{$S accepts valid -w input};
-for my $name ('1 second',
+for my $arg (
+     '1 second',
      '1 minute',
      '1 hour',
      '1 day'
     ) {
-   like ($cp->run(qq{-w "$_"}), qr/^$label/, "$t ($name)");
+   like ($cp->run(qq{-w "$arg"}), qr{^$label}, "$t ($arg)");
 }
 
 $t = qq{$S rejects invalid -w input};
-for ('-1 second',
+for my $arg (
+     '-1 second',
      'abc'
     ) {
-   like ($cp->run(qq{-w "$_"}), qr/^ERROR:.*?must be a valid time/, $t . " ($_)");
+   like ($cp->run(qq{-w "$arg"}), qr{^ERROR:.*?must be a valid time}, "$t ($arg)");
 }
 
 $t = qq{$S flags no-match-user};
diff --git a/t/02_txn_wraparound.t b/t/02_txn_wraparound.t
index c44af2a..b077438 100644
--- a/t/02_txn_wraparound.t
+++ b/t/02_txn_wraparound.t
@@ -46,10 +46,10 @@ for my $arg (-1, 0, 'a') {
 }
 
 $t = qq{$S rejects warning values 2 billion or higher};
-like ($cp->run(qq{-w 2000000000}), qr{ERROR:.+less than 2 billion}, $t);
+like ($cp->run(q{-w 2000000000}), qr{ERROR:.+less than 2 billion}, $t);
 
 $t = qq{$S rejects critical values 2 billion or higher};
-like ($cp->run(qq{-c 2200000000}), qr{ERROR:.+less than 2 billion}, $t);
+like ($cp->run(q{-c 2200000000}), qr{ERROR:.+less than 2 billion}, $t);
 
 $t = qq{$S accepts valid -c input};
 like ($cp->run(q{-c 1400000000}), qr{$label OK}, $t);
diff --git a/t/02_version.t b/t/02_version.t
index 1ff66d0..e9e7e08 100644
--- a/t/02_version.t
+++ b/t/02_version.t
@@ -107,7 +107,7 @@ is ($cp->run('--output=MRTG --mrtg=7.8'), qq{1\n0\n\n7.8.12\n}, $t);
 $t=qq{$S gives correct output for MRTG output};
 is ($cp->run('--output=MRTG --mrtg=7.8.12'), qq{1\n0\n\n7.8.12\n}, $t);
 
-$cp->drop_schema_if_exists($fakeschema);
+$cp->drop_schema_if_exists();
 $cp->reset_path();
 
 exit;
diff --git a/t/02_wal_files.t b/t/02_wal_files.t
index 53c61fc..9320fa4 100644
--- a/t/02_wal_files.t
+++ b/t/02_wal_files.t
@@ -33,7 +33,7 @@ $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);
 
-$cp->drop_schema_if_exists($fakeschema);
+$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);
@@ -50,6 +50,6 @@ is ($cp->run('--critical=1 --output=mrtg'), "99\n0\n\n\n", $t);
 $t=qq{$S returns correct MRTG information};
 is ($cp->run('--critical=101 --output=mrtg'), "99\n0\n\n\n", $t);
 
-$cp->drop_schema_if_exists($fakeschema);
+$cp->drop_schema_if_exists();
 
 exit;
diff --git a/t/99_perlcritic.t b/t/99_perlcritic.t
index 2d1c830..288d80a 100644
--- a/t/99_perlcritic.t
+++ b/t/99_perlcritic.t
@@ -25,14 +25,14 @@ else {
 	opendir my $dir, 't' or die qq{Could not open directory 't': $!\n};
 	@testfiles = map { "t/$_" } grep { /^.+\.(t|pl)$/ } readdir $dir;
 	closedir $dir;
-	plan tests => 3+ at testfiles;
+	plan tests => 4+ at testfiles;
 }
 ok(@testfiles, 'Found files in test directory');
 
 ## Check some non-test files
 my $critic = Perl::Critic->new(-severity => 1, '-profile-strictness' => 'quiet');
 
-for my $filename (qw{check_postgres.pl }) {
+for my $filename (qw{check_postgres.pl t/CP_Testing.pm}) {
 
 	if ($ENV{TEST_CRITIC_SKIPNONTEST}) {
 		pass qq{Skipping non-test file "$filename"};
diff --git a/t/CP_Testing.pm b/t/CP_Testing.pm
index c7fac75..c23e9b0 100644
--- a/t/CP_Testing.pm
+++ b/t/CP_Testing.pm
@@ -2,6 +2,7 @@ package CP_Testing;
 
 ## Common methods used by the other tests for check_postgres.pl
 
+use 5.006;
 use strict;
 use warnings;
 use Data::Dumper;
@@ -88,6 +89,7 @@ sub test_database_handle {
 		print $cfh qq{max_connections = 10\n};
 		print $cfh qq{max_prepared_transactions = 5\n};
 		print $cfh qq{autovacuum = off\n};
+		print $cfh qq{stats_command_string = on\n};
 		print $cfh "\n";
 		close $cfh or die qq{Could not close "$cfile": $!\n};
 
@@ -141,7 +143,7 @@ sub test_database_handle {
 	  SCAN: {
 			seek $logfh, 0, 0;
 			while (<$logfh>) {
-				if (/ready to accept connections/) {
+				if (/ready to accept connections/ or /database system is ready/) {
 					last SCAN;
 				}
 			}
@@ -181,17 +183,18 @@ 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");
-	$dbh->do("ALTER USER readonly SET default_transaction_read_only = 1");
-	$dbh->do("CREATE DATABASE beedeebeedee");
-	$dbh->do("CREATE DATABASE ardala");
-    $dbh->do("CREATE LANGUAGE plpgsql");
+	$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');
+    $dbh->do('CREATE LANGUAGE plpgsql');
+    $dbh->do('CREATE LANGUAGE plperlu');
 	$dbh->{AutoCommit} = 0;
 	$dbh->{RaiseError} = 1;
 
 	if (! exists $self->{keep_old_schema}) {
-		my $SQL = "SELECT count(*) FROM pg_namespace WHERE nspname = " . $dbh->quote($fakeschema);
+		my $SQL = 'SELECT count(*) FROM pg_namespace WHERE nspname = ' . $dbh->quote($fakeschema);
 		my $count = $dbh->selectall_arrayref($SQL)->[0][0];
 		if ($count) {
 			local $dbh->{Warn} = 0;
@@ -206,7 +209,7 @@ sub test_database_handle {
 		eval { $tmp_dbh = DBI->connect($tmp_dsn, @superdsn[1..$#superdsn]) };
 		if ($@) {
 			local($dbh->{AutoCommit}) = 1;
-			$dbh->do("CREATE DATABASE " . $arg->{dbname});
+			$dbh->do('CREATE DATABASE ' . $arg->{dbname});
 			eval { $tmp_dbh = DBI->connect($tmp_dsn, @superdsn[1..$#superdsn]) };
 			die $@ if $@;
 		}
@@ -221,8 +224,8 @@ sub test_database_handle {
 
 	## Sanity check
 	$dbh->do("ALTER USER $dbuser SET search_path = public");
-	$dbh->do("SET search_path = public");
-	$dbh->do("COMMIT");
+	$dbh->do('SET search_path = public');
+	$dbh->do('COMMIT');
 
 	return $dbh;
 
@@ -246,9 +249,9 @@ sub run {
 
 	my $double = $action =~ s/DB2// ? 1 : 0;
 
-	my $dbhost = $self->{dbhost}   || die "No dbhost?";
-	my $dbuser = $self->{testuser} || die "No testuser?";
-	my $dbname = $self->{dbname}   || die "No dbname?";
+	my $dbhost = $self->{dbhost}   || die 'No dbhost?';
+	my $dbuser = $self->{testuser} || die 'No testuser?';
+	my $dbname = $self->{dbname}   || die 'No dbname?';
 	my $com = qq{perl check_postgres.pl --action=$action --dbhost="$dbhost" --dbuser=$dbuser};
     if ($extra =~ s/--nodbname//) {
     }
@@ -345,6 +348,7 @@ sub create_fake_pg_table {
 
 	$dbh->do("ALTER USER $dbuser SET search_path = $fakeschema, public, pg_catalog");
 	$dbh->commit();
+	return;
 
 } ## end of create_fake_pg_table
 
@@ -365,6 +369,7 @@ sub set_fake_schema {
 
 	$dbh->do("ALTER USER $dbuser SET search_path = $fakeschema, public, pg_catalog");
 	$dbh->commit();
+	return;
 
 } ## end of set_fake_schema
 
@@ -399,9 +404,10 @@ sub drop_schema_if_exists {
 
 	my ($self,$name) = @_;
 	my $dbh = $self->{dbh} || die;
+	$name ||= $fakeschema;
 
 	if (! exists $self->{keep_old_schema}) {
-		my $SQL = "SELECT count(*) FROM pg_namespace WHERE nspname = " . $dbh->quote($name);
+		my $SQL = 'SELECT count(*) FROM pg_namespace WHERE nspname = ' . $dbh->quote($name);
 		my $count = $dbh->selectall_arrayref($SQL)->[0][0];
 		if ($count) {
 			local $dbh->{Warn};
@@ -427,7 +433,7 @@ sub drop_table_if_exists {
 
 	my $safetable = $dbh->quote($name);
 	my $safeschema = $dbh->quote($schema);
-	my $SQL = $schema 
+	my $SQL = $schema
 		? q{SELECT count(*) FROM pg_class c JOIN pg_namespace n ON (n.oid = c.relnamespace) }.
 		  qq{WHERE relkind = 'r' AND nspname = $safeschema AND relname = $safetable}
         : qq{SELECT count(*) FROM pg_class WHERE relkind='r' AND relname = $safetable};
@@ -470,6 +476,7 @@ sub drop_sequence_if_exists {
 		$dbh->do("DROP SEQUENCE $name");
 		$dbh->commit();
 	}
+	return;
 
 } ## end of drop_sequence_if_exists
 
@@ -531,6 +538,7 @@ sub fake_self_version {
 	print $fh $slurp;
 	truncate $fh, tell($fh);
 	close $fh or die qq{Could not close "$file": $!\n};
+	return;
 
 } ## end of fake_self_version
 
@@ -547,6 +555,7 @@ sub restore_self_version {
 	print $fh $slurp;
 	truncate $fh, tell($fh);
 	close $fh or die qq{Could not close "$file": $!\n};
+	return;
 
 } ## end of restore_self_version
 
@@ -570,7 +579,25 @@ sub drop_all_tables {
 		$dbh->do("DROP TABLE $tab CASCADE");
 	}
 	$dbh->commit();
+	return;
 
 } ## end of drop_all_tables
 
+sub database_sleep {
+
+	my ($self,$dbh,$time) = @_;
+
+	my $ver = $dbh->{pg_server_version};
+
+	if ($ver < 80200) {
+		my $SQL = q{CREATE OR REPLACE FUNCTION pg_sleep(float) RETURNS VOID LANGUAGE plperlu AS 'select(undef,undef,undef,shift)'};
+		$dbh->do($SQL);
+		$dbh->commit();
+	}
+	$dbh->do(qq{SELECT pg_sleep($time)});
+	return;
+
+
+} ## end of database_sleep
+
 1;
-- 
1.6.0.5



More information about the Check_postgres mailing list