@@ -3066,7 +3066,7 @@ sub run_command {
30663066 next ;
30673067 }
30683068 # # Likewise if we have specified "target" database info and this is not our choice
3069- if ($arg -> {target } and $arg -> {target } != $db ) {
3069+ if ($arg -> {target } and $arg -> {target } ne $db ) {
30703070 next ;
30713071 }
30723072
@@ -6672,9 +6672,27 @@ sub check_partman_premake {
66726672 default_critical => ' 3' ,
66736673 });
66746674
6675+ # check, if partman is installed in this DB
6676+ my $SQL = q{
6677+ select current_database(), true from pg_extension where extname='pg_partman';
6678+ } ;
6679+
6680+ my $info = run_command($SQL , {emptyok => 1 });
6681+ my @localtargetlist ;
6682+ for my $db (@{$info -> {db }}) {
6683+ if ( exists $db -> {slurp }[0]{bool } ) {
6684+ # push db to a local targetlist, otherwise checks fail due to missing part_conf
6685+ push @localtargetlist => $db -> {slurp }[0]{current_database };
6686+ }
6687+ }
6688+ if (!@localtargetlist ) {
6689+ add_unknown msg(' no-match-db' );
6690+ return 1;
6691+ }
6692+
66756693 # check missing Config for range partitioned tables
66766694
6677- my $SQL = q{
6695+ $SQL = q{
66786696SELECT
66796697 current_database() AS database,
66806698 c.relnamespace::regnamespace || '.' || c.relname AS parent_table
@@ -6693,7 +6711,8 @@ sub check_partman_premake {
66936711 parent_table = c.relnamespace::regnamespace || '.' || c.relname);
66946712} ;
66956713
6696- my $info = run_command($SQL , {regex => qr [\w +] , emptyok => 1 } );
6714+ $info = run_command($SQL , {target => @localtargetlist , regex => qr [\w +] , emptyok => 1 } );
6715+
66976716 my (@crit ,@warn ,@ok );
66986717
66996718 for $db (@{$info -> {db }}) {
@@ -6734,7 +6753,7 @@ sub check_partman_premake {
67346753WHERE configured_partitions=0
67356754} ;
67366755
6737- $info = run_command($SQL , {regex => qr [\w +] , emptyok => 1 } );
6756+ $info = run_command($SQL , {target => @localtargetlist , regex => qr [\w +] , emptyok => 1 } );
67386757
67396758 for $db (@{$info -> {db }}) {
67406759 my ($maxage ,$maxdb ) = (0,' ' ); # # used by MRTG only
@@ -6773,7 +6792,7 @@ sub check_partman_premake {
67736792WHERE a.count <= (p.premake )
67746793 } ;
67756794
6776- $info = run_command($SQL , {regex => qr [\w +] , emptyok => 1 } );
6795+ $info = run_command($SQL , {target => @localtargetlist , regex => qr [\w +] , emptyok => 1 } );
67776796
67786797 for $db (@{$info -> {db }}) {
67796798 my ($maxage ,$maxdb ) = (0,' ' ); # # used by MRTG only
@@ -6827,7 +6846,7 @@ sub check_partman_premake {
68276846ORDER BY 3, 2 DESC
68286847} ;
68296848
6830- $info = run_command($SQL , {regex => qr [\w +] , emptyok => 1 } );
6849+ $info = run_command($SQL , {target => @localtargetlist , regex => qr [\w +] , emptyok => 1 } );
68316850
68326851 for $db (@{$info -> {db }}) {
68336852 my ($maxage ,$maxdb ) = (0,' ' ); # # used by MRTG only
@@ -6894,7 +6913,7 @@ sub check_partman_premake {
68946913HAVING count(*) < b.premake;
68956914 } ;
68966915
6897- $info = run_command($SQL , {regex => qr [\w +] , emptyok => 1 } );
6916+ $info = run_command($SQL , {target => @localtargetlist , regex => qr [\w +] , emptyok => 1 } );
68986917
68996918 for $db (@{$info -> {db }}) {
69006919 my ($maxage ,$maxdb ) = (0,' ' ); # # used by MRTG only
@@ -6970,7 +6989,6 @@ sub check_pgbouncer_checksum {
69706989 next if skip_item($key );
69716990 $newstring .= " $r ->{key} = $r ->{value}\n " ;
69726991 }
6973-
69746992 if (! length $newstring ) {
69756993 add_unknown msg(' no-match-set' );
69766994 }
0 commit comments