From 6a1bb59efb69df5d9fb223f6a72764174d8d4449 Mon Sep 17 00:00:00 2001 From: Vadim Voitenko <74241416+wwoytenko@users.noreply.github.com> Date: Tue, 27 Jun 2023 16:47:33 +0300 Subject: [PATCH] Fixed replication pgReplicationSlotQuery - now it's working correctly for replica and primary (#825) Signed-off-by: Vadim Voitenko Co-authored-by: Vadim Voitenko --- collector/pg_replication_slot.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/collector/pg_replication_slot.go b/collector/pg_replication_slot.go index 43eb8a9d..dec1b5da 100644 --- a/collector/pg_replication_slot.go +++ b/collector/pg_replication_slot.go @@ -66,11 +66,14 @@ var ( pgReplicationSlotQuery = `SELECT slot_name, - pg_current_wal_lsn() - '0/0' AS current_wal_lsn, - coalesce(confirmed_flush_lsn, '0/0') - '0/0', + CASE WHEN pg_is_in_recovery() THEN + pg_last_wal_receive_lsn() - '0/0' + ELSE + pg_current_wal_lsn() - '0/0' + END AS current_wal_lsn, + COALESCE(confirmed_flush_lsn, '0/0') - '0/0', active - FROM - pg_replication_slots;` + FROM pg_replication_slots;` ) func (PGReplicationSlotCollector) Update(ctx context.Context, instance *instance, ch chan<- prometheus.Metric) error {