summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcheck_postgres.pl74
-rw-r--r--t/02_same_schema.t32
2 files changed, 103 insertions, 3 deletions
diff --git a/check_postgres.pl b/check_postgres.pl
index d5a0ec158..c01961a94 100755
--- a/check_postgres.pl
+++ b/check_postgres.pl
@@ -4625,7 +4625,23 @@ SQL
};
}
}
- }
+
+ ## Get a list of all languages
+ $SQL = q{SELECT lanname FROM pg_language};
+ $info = run_command($SQL, { dbuser => $opt{dbuser}[$x-1], dbnumber => $x } );
+ for $db (@{$info->{db}}) {
+ for my $line (split /\n/, $db->{slurp}) {
+ unless ($line =~ /^\s*(\w+)\s*/gmo) {
+ warn "Query processing failed:\n$line\nfrom $SQL\n";
+ next;
+ }
+ my ($lang) = ($1);
+ $thing{$x}{language}{$lang} = 1;
+ }
+ }
+
+
+ } ## end each database to query
$db = $saved_db;
@@ -5134,6 +5150,22 @@ SQL
}
}
+ ## Compare languages
+ for my $name (sort keys %{$thing{1}{language}}) {
+ if (!exists $thing{2}{language}{$name}) {
+ push @{$fail{language}{notexist}{1}} => $name;
+ $failcount++;
+ next;
+ }
+ }
+ for my $name (sort keys %{$thing{2}{language}}) {
+ if (!exists $thing{1}{language}{$name}) {
+ push @{$fail{language}{notexist}{2}} => $name;
+ $failcount++;
+ next;
+ }
+ }
+
## Compare functions
## Functions on 1 but not 2?
@@ -5147,6 +5179,14 @@ SQL
}
}
+ ## Skip if these are a side effect of having a language
+ for my $lang (@{$fail{language}{notexist}{1}}) {
+ $lang =~ s/u$//;
+ next FUNCTION if
+ $name eq "pg_catalog.${lang}_call_handler()"
+ or $name eq "pg_catalog.${lang}_validator(oid)";
+ }
+
push @{$fail{functions}{notexist}{1}} => $name;
$failcount++;
}
@@ -5161,6 +5201,14 @@ SQL
}
}
+ ## Skip if these are a side effect of having a language
+ for my $lang (@{$fail{language}{notexist}{2}}) {
+ $lang =~ s/u$//;
+ next FUNCTION if
+ $name =~ "pg_catalog.${lang}_call_handler()"
+ or $name eq "pg_catalog.${lang}_validator(oid)";
+ }
+
if (! exists $thing{1}{functions}{$name}) {
push @{$fail{functions}{notexist}{2}} => $name;
$failcount++;
@@ -5196,6 +5244,7 @@ SQL
}
}
+
##
## Comparison is done, let's report the results
##
@@ -5546,6 +5595,23 @@ SQL
}
}
+ ## Language differences
+ if (exists $fail{language}) {
+ if (exists $fail{language}{notexist}) {
+ if (exists $fail{language}{notexist}{1}) {
+ for my $name (@{$fail{language}{notexist}{1}}) {
+ $db->{perf} .= " Language on 1 but not 2: $name ";
+ }
+ }
+ if (exists $fail{language}{notexist}{2}) {
+ for my $name (@{$fail{language}{notexist}{2}}) {
+ $db->{perf} .= " Language on 2 but not 1: $name ";
+ }
+ }
+ }
+ }
+
+
add_critical msg('same-failed', $failcount);
return;
@@ -7491,6 +7557,12 @@ Items not specifically attributed are by Greg Sabino Mullane.
=over 4
+=item B<Version 2.10.0>
+
+ For same_schema, compare view definitions, and compare languages.
+ Make script into a global executable via the Makefile.PL file.
+ Better output when comparing two databases.
+
=item B<Version 2.9.5> (July 24, 2009)
Don't use a LIMIT in check_bloat if --include is used. Per complaint from Jeff Frost.
diff --git a/t/02_same_schema.t b/t/02_same_schema.t
index db255ebb9..3713c3b90 100644
--- a/t/02_same_schema.t
+++ b/t/02_same_schema.t
@@ -6,7 +6,7 @@ use 5.006;
use strict;
use warnings;
use Data::Dumper;
-use Test::More tests => 41;
+use Test::More tests => 45;
use lib 't','.';
use CP_Testing;
@@ -307,7 +307,6 @@ like ($cp1->run($stdargs),
$dbh1->do(q{DROP FUNCTION f4()});
$dbh2->do(q{DROP FUNCTION f4()});
-
#/////////// Columns
$dbh1->do(q{CREATE TABLE table_1_only (a int)});
@@ -341,4 +340,33 @@ like ($cp1->run($stdargs),
qr{^$label CRITICAL.*Items not matched: 1\b.*position is 2 on 1, but 4 on 2},
$t);
+$dbh1->do('DROP TABLE table_1_only');
+$dbh2->do('DROP TABLE table_1_only');
+
+
+#/////////// Languages
+
+$t = qq{$S works when languages are the same};
+like ($cp1->run($stdargs),
+ qr{^$label OK:},
+ $t);
+
+$t = qq{$S fails when database 1 has a language that 2 does not};
+$dbh1->do('create language plpgsql');
+like ($cp1->run($stdargs),
+ qr{^$label CRITICAL:.*Items not matched: 1 .*Language on 1 but not 2: plpgsql},
+ $t);
+
+$t = qq{$S works when languages are the same};
+$dbh2->do('create language plpgsql');
+like ($cp1->run($stdargs),
+ qr{^$label OK:},
+ $t);
+
+$t = qq{$S fails when database 2 has a language that 1 does not};
+$dbh1->do('drop language plpgsql');
+like ($cp1->run($stdargs),
+ qr{^$label CRITICAL:.*Items not matched: 1 .*Language on 2 but not 1: plpgsql},
+ $t);
+
exit;