@@ -6716,22 +6716,22 @@ sub check_partman_premake {
67166716 current_database() as database,
67176717 parent_table
67186718FROM (
6719- SELECT
6720- parent_table,
6721- retention,
6722- partition_interval,
6723- EXTRACT(EPOCH FROM retention::interval) / EXTRACT(EPOCH FROM partition_interval::interval) AS configured_partitions
6719+ SELECT
6720+ p.parent_table,
6721+ p.retention,
6722+ p.premake,
6723+ p.partition_interval,
6724+ (EXTRACT(EPOCH FROM p.retention::interval) / EXTRACT(EPOCH FROM p.partition_interval::interval))::int AS configured_partitions,
6725+ count(*) as num_partitions
67246726 FROM
6725- partman.part_config
6727+ partman.part_config p
67266728 JOIN
67276729 pg_class c
67286730 ON
6729- c.relnamespace::regnamespace || '.' || c.relname = parent_table
6730- WHERE
6731- 4<1
6732- OR
6733- c.relkind='r'
6734- ) p;
6731+ c.relnamespace::regnamespace || '.' || c.relname = p.parent_table JOIN pg_inherits i
6732+ ON c.oid = i.inhparent
6733+ group by p.parent_table ) a
6734+ WHERE configured_partitions=0
67356735} ;
67366736
67376737 $info = run_command($SQL , {regex => qr [\w +] , emptyok => 1 } );
@@ -6744,13 +6744,59 @@ sub check_partman_premake {
67446744 next ROW if skip_item($dbname );
67456745 $found = 2;
67466746
6747- $msg = " $dbname =$parent_table " . msg(' partman-conf-tbl' );
6747+ $msg = " $dbname =$parent_table " . msg(' partman-conf-tbl' ) . " configured_partitions=0 " ;
67486748 # we consider this as critical, because even run_maintenance_proc fails at all at least in some of these cases.
67496749 push @crit => $msg ;
67506750 };
67516751 };
67526752
6753+ # check, if the number of partitions is at least configured_partitions + premake
6754+ # warning, if not, due to new partition sets
6755+
6756+ $SQL = q{
6757+ SELECT current_database() as database,
6758+ a.parent_table,
6759+ a.configured_partitions,
6760+ a.num_partitions,
6761+ a.premake
6762+ FROM (
6763+ SELECT
6764+ p.parent_table,
6765+ p.retention,
6766+ p.premake,
6767+ p.partition_interval,
6768+ (EXTRACT(EPOCH FROM p.retention::interval) / EXTRACT(EPOCH FROM p.partition_interval::interval))::int AS configured_partitions,
6769+ count(*) as num_partitions
6770+ FROM
6771+ partman.part_config p
6772+ JOIN
6773+ pg_class c
6774+ ON
6775+ c.relnamespace::regnamespace || '.' || c.relname = p.parent_table JOIN pg_inherits i
6776+ ON c.oid = i.inhparent
6777+ group by p.parent_table ) a
6778+ WHERE num_partitions < configured_partitions+premake
6779+ -- configured_partitions=0 is handled by another check
6780+ AND configured_partitions>0
6781+ } ;
6782+
6783+ $info = run_command($SQL , {regex => qr [\w +] , emptyok => 1 } );
6784+
6785+ for $db (@{$info -> {db }}) {
6786+ my ($maxage ,$maxdb ) = (0,' ' ); # # used by MRTG only
6787+ ROW: for my $r (@{$db -> {slurp }}) {
6788+ my ($dbname ,$parent_table ,$cpartitions ,$npartitions ,$premake ) = ($r -> {database },$r -> {parent_table },$r -> {configured_partitions },$r -> {num_partitions },$r -> {premake });
6789+ $found = 1 if ! $found ;
6790+ next ROW if skip_item($dbname );
6791+ $found = 2;
6792+ $msg = " $dbname =$parent_table " . msg(' partman-premake' ) . " num partitions: $npartitions configured partitions: $cpartitions premake: $premake " ;
6793+ push @warn => $msg ;
6794+ push @crit => $msg if (@crit );
6795+ };
6796+ };
6797+
67536798 # check, if the number of partitions is at least equal to premake
6799+ # critical, if not
67546800 # retention is not taken into account
67556801
67566802 $SQL = q{
@@ -6786,6 +6832,7 @@ sub check_partman_premake {
67866832 };
67876833 };
67886834
6835+
67896836 $SQL = q{
67906837SELECT
67916838 current_database() as database,
0 commit comments