More tweaks to support Postgres 8.0
authorGreg Sabino Mullane <[email protected]>
Thu, 30 Apr 2009 21:37:35 +0000 (17:37 -0400)
committerGreg Sabino Mullane <[email protected]>
Thu, 30 Apr 2009 21:37:35 +0000 (17:37 -0400)
12 files changed:
check_postgres.pl
t/02_backends.t
t/02_bloat.t
t/02_database_size.t
t/02_disabled_triggers.t
t/02_prepared_txns.t
t/02_query_time.t
t/02_relation_size.t
t/02_replicate_row.t
t/02_sequence.t
t/02_wal_files.t
t/CP_Testing.pm

index 978cea73ccb37a7ed51792107132eab8a33178a5..8144315ee9f9fbadb9954090e980d1db34dd495b 100755 (executable)
@@ -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++;
index 609d8ab557235ad8148d79006f9fa13e8cfb7e9a..3420a5fa21b05da361ae37193cbc3bce0f708fbc 100644 (file)
@@ -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();
 
index 72b02990c6d290604fa31b20a6a4dbb5896c5f3c..138079737f7253a8372c827e7dd46789eca1056f 100644 (file)
@@ -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);
index 9a6cf8de858d4a41ce27628d02e9e2fb8f537e75..ba348d8f689776312f3c842febc77e865f1c9005 100644 (file)
@@ -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);
index b163038f60d1f328c551ae9636294808f10d7a7f..8d40afe5654a9a0f7798e44fcc1beb4e64b0f152 100644 (file)
@@ -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);
index 72f356125a3e15c788c8ed87908ed809afa10152..56a8b0fc3502e1f7e50296aa9943244212a44c7f 100644 (file)
@@ -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;
index a851106204bfbbeb1d4e632bd32c02d1a6cf9a50..6cc133375f249f4f8a72d0a601cb9fbfb014522a 100644 (file)
@@ -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();
index add51b63f9d567fd5b0b9e3625d9eabd5d8b3904..db8ccad6587a274f62eb64fa9798d4a06bb0fdd2 100644 (file)
@@ -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};
index 05bb063de93c6e82e2fac84959ef73a6f2576c73..248e59d30ff5af3d103c407029304396d0ce0512 100644 (file)
@@ -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);
 
index 6be438795a60f12c85192bcf25789652b7b16256..8f10f701cf6c8e8cc2baa6e9ceb0d1cbfb759da7 100644 (file)
@@ -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);
 
index 9320fa4f29850c1d105f6cae40981e8916f67bfb..c8ee6258e083f2c8f0d482740a06c2562b5d5678 100644 (file)
@@ -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);
index b4d9f789433579b21e1743f6056f7a63e0373623..9106abc5ffbeb34b302f61a37926f91b2daafc2d 100644 (file)
@@ -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');