Skip to content

Commit 2c61a7b

Browse files
committed
check if the number of partitions is at least the number of configured premakes
1 parent beffd80 commit 2c61a7b

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

check_postgres.pl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ package check_postgres;
204204
'opt-psql-nover' => q{Could not determine psql version},
205205
'opt-psql-restrict' => q{Cannot use the --PGBINDIR or --PSQL option when NO_PSQL_OPTION is on},
206206
'partman-premake-ok' => q{All premade partitions are present},
207+
'partman-premake' => q{Not all premade partitions are present},
207208
'partman-conf-tbl' => q{misconfigured in partman.part_config or not a partitioned table},
208209
'partman-conf-mis' => q{missing table in partman.part_config},
209210
'pgagent-jobs-ok' => q{No failed jobs},
@@ -6749,6 +6750,41 @@ sub check_partman_premake {
67496750
};
67506751
};
67516752

6753+
# check, if the number of partitions is at least equal to premake
6754+
# retention is not taken into account
6755+
6756+
$SQL = q{
6757+
SELECT
6758+
current_database() as database,
6759+
a.parent_table,
6760+
a.count as partitions,
6761+
p.premake
6762+
FROM ( SELECT
6763+
inhparent::regclass::text as parent_table,
6764+
count(*)
6765+
FROM pg_inherits i
6766+
JOIN pg_class c ON c.oid = i.inhrelid
6767+
WHERE c.relkind = 'r'
6768+
AND pg_catalog.pg_get_expr(c.relpartbound, i.inhrelid) != 'DEFAULT'
6769+
GROUP BY inhparent) a
6770+
JOIN partman.part_config p
6771+
ON p.parent_table=a.parent_table
6772+
WHERE a.count <= (p.premake )
6773+
};
6774+
6775+
$info = run_command($SQL, {regex => qr[\w+], emptyok => 1 } );
6776+
6777+
for $db (@{$info->{db}}) {
6778+
my ($maxage,$maxdb) = (0,''); ## used by MRTG only
6779+
ROW: for my $r (@{$db->{slurp}}) {
6780+
my ($dbname,$parent_table,$partitions,$premake) = ($r->{database},$r->{parent_table},$r->{partitions},$r->{premake});
6781+
$found = 1 if ! $found;
6782+
next ROW if skip_item($dbname);
6783+
$found = 2;
6784+
$msg = "$dbname=$parent_table " . msg('partman-premake') . " premake: $premake num partitions: $partitions";
6785+
push @crit => $msg;
6786+
};
6787+
};
67526788

67536789
$SQL = q{
67546790
SELECT

0 commit comments

Comments
 (0)