Skip to content

Commit 7d56cc7

Browse files
glynastilldf7cb
authored andcommitted
Fix issues with latest changes to check_sequence and run_command:
check_sequence - Split big UNION of sequence selects into chunks to avoid overrunning system argument size run_command - If we have specified a "target" database, skip all others in global targetdb list
1 parent e3d43fe commit 7d56cc7

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

check_postgres.pl

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,6 +2254,10 @@ sub run_command {
22542254
if ($arg->{dbnumber} and $arg->{dbnumber} != $num) {
22552255
next;
22562256
}
2257+
## Likewise if we have specified "target" database info and this is not our choice
2258+
if ($arg->{target} and $arg->{target} != $db) {
2259+
next;
2260+
}
22572261

22582262
## Just to keep things clean:
22592263
truncate $tempfh, 0;
@@ -7291,30 +7295,34 @@ sub check_sequence {
72917295
FROM $seqname) foo
72927296
};
72937297
}
7294-
my $seqinfo = run_command(join("\nUNION ALL\n", @seq_sql), { target => $db }); # execute all SQL commands at once
7295-
for my $r2 (@{$seqinfo->{db}[0]{slurp}}) { # now look at all results
7296-
my ($seqname, $last, $slots, $used, $percent, $left) = @$r2{qw/ seqname last_value slots used percent numleft / };
7297-
if (! defined $last) {
7298-
ndie msg('seq-die', $seqname);
7299-
}
7300-
my $msg = msg('seq-msg', $seqname, $percent, $left);
7301-
my $nicename = perfname("$multidb$seqname");
7302-
$seqperf{$percent}{$seqname} = [$left, " $nicename=$percent%;$w%;$c%"];
7303-
if ($percent >= $maxp) {
7304-
$maxp = $percent;
7305-
if (! exists $opt{perflimit} or $limit++ < $opt{perflimit}) {
7306-
push @{$seqinfo{$percent}} => $MRTG ? [$seqname,$percent,$slots,$used,$left] : $msg;
7298+
# Use UNION ALL to query multiple sequences at once, however if there are too many sequences this can exceed
7299+
# maximum argument length; so split into chunks of 200 sequences or less and iterate over them.
7300+
while (my @seq_sql_chunk = splice @seq_sql, 0, 200) {
7301+
my $seqinfo = run_command(join("\nUNION ALL\n", @seq_sql_chunk), { target => $db }); # execute all SQL commands at once
7302+
for my $r2 (@{$seqinfo->{db}[0]{slurp}}) { # now look at all results
7303+
my ($seqname, $last, $slots, $used, $percent, $left) = @$r2{qw/ seqname last_value slots used percent numleft / };
7304+
if (! defined $last) {
7305+
ndie msg('seq-die', $seqname);
73077306
}
7308-
}
7309-
next if $MRTG;
7307+
my $msg = msg('seq-msg', $seqname, $percent, $left);
7308+
my $nicename = perfname("$multidb$seqname");
7309+
$seqperf{$percent}{$seqname} = [$left, " $nicename=$percent%;$w%;$c%"];
7310+
if ($percent >= $maxp) {
7311+
$maxp = $percent;
7312+
if (! exists $opt{perflimit} or $limit++ < $opt{perflimit}) {
7313+
push @{$seqinfo{$percent}} => $MRTG ? [$seqname,$percent,$slots,$used,$left] : $msg;
7314+
}
7315+
}
7316+
next if $MRTG;
73107317

7311-
if (length $critical and $percent >= $c) {
7312-
push @crit => $msg;
7313-
}
7314-
elsif (length $warning and $percent >= $w) {
7315-
push @warn => $msg;
7318+
if (length $critical and $percent >= $c) {
7319+
push @crit => $msg;
7320+
}
7321+
elsif (length $warning and $percent >= $w) {
7322+
push @warn => $msg;
7323+
}
73167324
}
7317-
}
7325+
}
73187326
if ($MRTG) {
73197327
my $msg = join ' | ' => map { $_->[0] } @{$seqinfo{$maxp}};
73207328
do_mrtg({one => $maxp, msg => $msg});
@@ -7958,8 +7966,6 @@ sub check_wal_files {
79587966

79597967
} ## end of check_wal_files
79607968

7961-
7962-
79637969
=pod
79647970
79657971
=encoding utf8

0 commit comments

Comments
 (0)