Skip to content

Commit 6a1bb59

Browse files
authored
Fixed replication pgReplicationSlotQuery - now it's working correctly for replica and primary (#825)
Signed-off-by: Vadim Voitenko <[email protected]> Co-authored-by: Vadim Voitenko <[email protected]>
1 parent bf4e4fb commit 6a1bb59

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

collector/pg_replication_slot.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,14 @@ var (
6666

6767
pgReplicationSlotQuery = `SELECT
6868
slot_name,
69-
pg_current_wal_lsn() - '0/0' AS current_wal_lsn,
70-
coalesce(confirmed_flush_lsn, '0/0') - '0/0',
69+
CASE WHEN pg_is_in_recovery() THEN
70+
pg_last_wal_receive_lsn() - '0/0'
71+
ELSE
72+
pg_current_wal_lsn() - '0/0'
73+
END AS current_wal_lsn,
74+
COALESCE(confirmed_flush_lsn, '0/0') - '0/0',
7175
active
72-
FROM
73-
pg_replication_slots;`
76+
FROM pg_replication_slots;`
7477
)
7578

7679
func (PGReplicationSlotCollector) Update(ctx context.Context, instance *instance, ch chan<- prometheus.Metric) error {

0 commit comments

Comments
 (0)