diff options
author | Guillaume Lelarge | 2012-12-27 08:57:55 +0000 |
---|---|---|
committer | Guillaume Lelarge | 2012-12-27 09:14:11 +0000 |
commit | 9b35523b9d8b5d3e38bc9d9b060c243738f7dd96 (patch) | |
tree | 842fdcdc75a888b686ef238926eb986b167bb928 /check_postgres.pl | |
parent | 803ededc681c2a63dbb11903975ffe795a1f52f9 (diff) |
Make sure hot_standby_delay doesn't return negative values
Before this patch, the hot_standby_delay action could return negative values.
To minimize the risk, we first query the slave, then the master. And to make
sure, we never get negative values, we set them to zero if we have a negative
value.
Report and ideas from Filip RembiaĆkowski.
Diffstat (limited to 'check_postgres.pl')
-rwxr-xr-x | check_postgres.pl | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/check_postgres.pl b/check_postgres.pl index ca92fbc97..fdd9236a1 100755 --- a/check_postgres.pl +++ b/check_postgres.pl @@ -4756,29 +4756,11 @@ sub check_hot_standby_delay { ## Get xlog positions my ($moffset, $s_rec_offset, $s_rep_offset); - ## On master - $SQL = q{SELECT pg_current_xlog_location() AS location}; - my $info = run_command($SQL, { dbnumber => $master }); - my $saved_db; - for $db (@{$info->{db}}) { - my $location = $db->{slurp}[0]{location}; - next if ! defined $location; - - my ($x, $y) = split(/\//, $location); - $moffset = (hex('ff000000') * hex($x)) + hex($y); - $saved_db = $db if ! defined $saved_db; - } - - if (! defined $moffset) { - add_unknown msg('hs-no-location', 'master'); - return; - } ## On slave $SQL = q{SELECT pg_last_xlog_receive_location() AS receive, pg_last_xlog_replay_location() AS replay}; - - $info = run_command($SQL, { dbnumber => $slave, regex => qr/\// }); - + my $info = run_command($SQL, { dbnumber => $slave, regex => qr/\// }); + my $saved_db; for $db (@{$info->{db}}) { my $receive = $db->{slurp}[0]{receive}; my $replay = $db->{slurp}[0]{replay}; @@ -4801,11 +4783,32 @@ sub check_hot_standby_delay { return; } + ## On master + $SQL = q{SELECT pg_current_xlog_location() AS location}; + $info = run_command($SQL, { dbnumber => $master }); + for $db (@{$info->{db}}) { + my $location = $db->{slurp}[0]{location}; + next if ! defined $location; + + my ($x, $y) = split(/\//, $location); + $moffset = (hex('ff000000') * hex($x)) + hex($y); + $saved_db = $db if ! defined $saved_db; + } + + if (! defined $moffset) { + add_unknown msg('hs-no-location', 'master'); + return; + } + ## Compute deltas $db = $saved_db; my $rec_delta = $moffset - $s_rec_offset; my $rep_delta = $moffset - $s_rep_offset; + # Make sure it's always positive or zero + $rec_delta = 0 if $rec_delta < 0; + $rep_delta = 0 if $rep_delta < 0; + $MRTG and do_mrtg({one => $rep_delta, two => $rec_delta}); $db->{perf} = sprintf ' %s=%s;%s;%s ', |