Skip to content

Commit 1b9e76d

Browse files
fix: handle pg_replication_slots on replicas and cascading replicas
Signed-off-by: Michael Todorovic <[email protected]>
1 parent 134e908 commit 1b9e76d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

cmd/postgres_exporter/postgres_exporter.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,16 @@ var queryOverrides = map[string][]OverrideQuery{
432432
{
433433
semver.MustParseRange(">=9.4.0 <10.0.0"),
434434
`
435-
SELECT slot_name, database, active, pg_xlog_location_diff(pg_current_xlog_location(), restart_lsn)
435+
SELECT slot_name, database, active,
436+
(case pg_is_in_recovery() when 't' then pg_xlog_location_diff(pg_current_xlog_location(), restart_lsn) else pg_xlog_location_diff(pg_last_xlog_receive_location(), restart_lsn) as pg_xlog_location_diff
436437
FROM pg_replication_slots
437438
`,
438439
},
439440
{
440441
semver.MustParseRange(">=10.0.0"),
441442
`
442-
SELECT slot_name, database, active, pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)
443+
SELECT slot_name, database, active,
444+
(case pg_is_in_recovery() when 't' then pg_wal_lsn_diff(pg_last_wal_receive_lsn(), restart_lsn) else pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) end) as pg_wal_lsn_diff
443445
FROM pg_replication_slots
444446
`,
445447
},

0 commit comments

Comments
 (0)