diff --git a/check_postgres.pl b/check_postgres.pl index d88cad7..0c7a447 100755 --- a/check_postgres.pl +++ b/check_postgres.pl @@ -5634,7 +5634,7 @@ sub check_hot_standby_delay { } # check if master and slave comply with the check using pg_is_in_recovery() - my ($master, $slave); + my ($master, $slave, $is_all_recovery); $SQL = q{SELECT pg_is_in_recovery() AS recovery;}; # Check if master is online (e.g. really a master) @@ -5663,6 +5663,12 @@ sub check_hot_standby_delay { $slave = 2; } + ## If no master detected, assume 1 is master is replicating to 2. The master can also be in recovery mode. + if (! defined $master) { + $master = 1; + $is_all_recovery = 1; + } + ## Get xlog positions my ($moffset, $s_rec_offset, $s_rep_offset, $time_delta); @@ -5704,6 +5710,9 @@ sub check_hot_standby_delay { ## On master if ($version >= 10) { $SQL = q{SELECT pg_current_wal_lsn() AS location}; + if ($is_all_recovery) { + $SQL = q{SELECT pg_last_wal_replay_lsn() AS location}; + } } else { $SQL = q{SELECT pg_current_xlog_location() AS location};