diff --git a/Makefile.PL b/Makefile.PL index 82e3948c..44d73fc2 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -47,6 +47,11 @@ my @cleanfiles = ( '/tmp/cptesting_socket3', '/tmp/cptesting_socket4', '/tmp/cptesting_socket5', + 'test_tablespace_check_postgres/', + 'test_tablespace_check_postgres2/', + 'test_tablespace_check_postgres3/', + 'test_tablespace_check_postgres4/', + 'test_tablespace_check_postgres5/', ); print "Configuring check_postgres $VERSION\n"; diff --git a/check_postgres.pl b/check_postgres.pl index 76514448..ccabcfc2 100755 --- a/check_postgres.pl +++ b/check_postgres.pl @@ -6992,6 +6992,12 @@ sub check_same_schema { next; } + ## Do not show tablespace differences if filtered out with "notablespace" + if (($col eq 'tablespace' or $col eq 'reltablespace') + and $opt{filtered}{notablespace}) { + next; + } + ## Do not show function body differences if filtered out with "nofuncbody" ## Also skip if the equivalent 'dash' and 'empty' if ($item eq 'function' @@ -9844,6 +9850,8 @@ =head2 B The filter option "noperm" prevents comparison of object permissions. +The filter option "notablespace" prevents comparison of object tablespaces. + To provide the second database, just append the differences to the first one by a call to the appropriate connection argument. For example, to compare databases on hosts alpha and bravo, use "--dbhost=alpha,bravo". Also see the diff --git a/t/02_same_schema.t b/t/02_same_schema.t index ed31071d..aaa7270f 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 => 76; +use Test::More tests => 78; use lib 't','.'; use CP_Testing; @@ -308,6 +308,20 @@ Table "public.berri": \s*Database 1: r/check_postgres_testing \s*Database 2: wd/check_postgres_testing\s*}s, $t); +$dbh2->do(q{REVOKE UPDATE,DELETE ON TABLE berri FROM alternate_owner}); +$dbh1->do(q{REVOKE SELECT ON TABLE berri FROM alternate_owner}); + +$t = qq{$S reports tablespace differences}; +$dbh1->do(q{ALTER TABLE berri SET TABLESPACE check_postgres}); +like ($cp1->run($connect2), + qr{^$label CRITICAL.*Items not matched: 1 .* +Table "public.berri": +\s*"reltablespace" is different:.* +\s*"tablespace" is different:.*}s, + $t); + +$t = qq{$S does not report tablespace differences if the 'notablespace' filter is given}; +like ($cp1->run("$connect2 --filter=notablespace"), qr{^$label OK}, $t); $t = qq{$S does not report table differences if the 'notable' filter is given}; like ($cp1->run("$connect3 --filter=notable"), qr{^$label OK}, $t); diff --git a/t/CP_Testing.pm b/t/CP_Testing.pm index 3ff08789..deaa92ae 100644 --- a/t/CP_Testing.pm +++ b/t/CP_Testing.pm @@ -23,6 +23,7 @@ sub new { my $self = { started => time(), dbdir => $arg->{dbdir} || 'test_database_check_postgres', + tsdir => $arg->{tsdir} || 'test_tablespace_check_postgres', testuser => $arg->{testuser} || 'check_postgres_testing', testuser2 => $arg->{testuser2} || 'powerless_pete', }; @@ -32,6 +33,9 @@ sub new { if (exists $arg->{dbnum} and $arg->{dbnum}) { $self->{dbdir} .= $arg->{dbnum}; } + if (exists $arg->{dbnum} and $arg->{dbnum}) { + $self->{tsdir} .= $arg->{dbnum}; + } return bless $self => $class; } @@ -84,6 +88,18 @@ sub test_database_handle { mkdir $dbdir; } + ## Create the test tablespace directory if it does not exist + my $tsdir = $arg->{tsdir} || $self->{tsdir}; + $DEBUG and warn qq{Tablespacedir: $tsdir\n}; + if (! -d $tsdir) { + + -e $tsdir and die qq{Oops: I cannot create "$tsdir", there is already a file there!\n}; + + Test::More::diag qq{Creating tablespace in directory "$tsdir"\n}; + + mkdir $tsdir; + } + my $datadir = "$dbdir/data space"; if (! -e $datadir) { @@ -350,6 +366,11 @@ sub test_database_handle { } } + $dbh->{RaiseError} = 1; + my $tablespaces = $dbh->selectall_hashref('SELECT spcname FROM pg_tablespace', 'spcname'); + $dbh->do("CREATE TABLESPACE check_postgres LOCATION '$here/$tsdir'") unless ($tablespaces->{check_postgres}); + $dbh->{RaiseError} = 0; + my $databases = $dbh->selectall_hashref('SELECT datname FROM pg_database', 'datname'); $dbh->do('CREATE DATABASE beedeebeedee') unless ($databases->{beedeebeedee}); $dbh->do('CREATE DATABASE ardala') unless ($databases->{ardala});