summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrien nayrat <adrien.nayrat@anayrat.info>2021-08-25 14:26:02 +0200
committerGitHub <noreply@github.com>2021-08-25 15:26:02 +0300
commit54018f5ffbcdc308d732cb84474c36806d3726ce (patch)
tree4aaba70d0e73b97731ca0b9da6dfb997e095c069
parent3848e97548063a8f8da057a0e067d30d87440b7b (diff)
Fix postgres replication_slot chart on standby (#11455)
From: https://github.com/OPMDG/check_pgactivity/pull/246
-rw-r--r--collectors/python.d.plugin/postgres/postgres.chart.py32
1 files changed, 28 insertions, 4 deletions
diff --git a/collectors/python.d.plugin/postgres/postgres.chart.py b/collectors/python.d.plugin/postgres/postgres.chart.py
index cab8f6161f..6cc1c16535 100644
--- a/collectors/python.d.plugin/postgres/postgres.chart.py
+++ b/collectors/python.d.plugin/postgres/postgres.chart.py
@@ -576,8 +576,20 @@ FROM
slot_type,
COALESCE (
floor(
- (pg_wal_lsn_diff(pg_current_wal_lsn (),slot.restart_lsn)
- - (pg_walfile_name_offset (restart_lsn)).file_offset) / (s.val)
+ CASE WHEN pg_is_in_recovery()
+ THEN (
+ pg_wal_lsn_diff(pg_last_wal_receive_lsn(), slot.restart_lsn)
+ -- this is needed to account for whole WAL retention and
+ -- not only size retention
+ + (pg_wal_lsn_diff(restart_lsn, '0/0') %% s.val)
+ ) / s.val
+ ELSE (
+ pg_wal_lsn_diff(pg_current_wal_lsn(), slot.restart_lsn)
+ -- this is needed to account for whole WAL retention and
+ -- not only size retention
+ + (pg_walfile_name_offset(restart_lsn)).file_offset
+ ) / s.val
+ END
),0) AS replslot_wal_keep
FROM pg_replication_slots slot
LEFT JOIN (
@@ -615,8 +627,20 @@ FROM
slot_type,
COALESCE (
floor(
- (pg_wal_lsn_diff(pg_current_wal_lsn (),slot.restart_lsn)
- - (pg_walfile_name_offset (restart_lsn)).file_offset) / (s.val)
+ CASE WHEN pg_is_in_recovery()
+ THEN (
+ pg_wal_lsn_diff(pg_last_wal_receive_lsn(), slot.restart_lsn)
+ -- this is needed to account for whole WAL retention and
+ -- not only size retention
+ + (pg_wal_lsn_diff(restart_lsn, '0/0') %% s.val)
+ ) / s.val
+ ELSE (
+ pg_wal_lsn_diff(pg_current_wal_lsn(), slot.restart_lsn)
+ -- this is needed to account for whole WAL retention and
+ -- not only size retention
+ + (pg_walfile_name_offset(restart_lsn)).file_offset
+ ) / s.val
+ END
),0) AS replslot_wal_keep
FROM pg_replication_slots slot
LEFT JOIN (