Skip to content

Commit d915932

Browse files
authored
Merge pull request #1 from yanboer/release-v0.12.1
adjust pg_replication_slots metrics
2 parents fb316ad + 9422d8b commit d915932

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

cmd/postgres_exporter/queries.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ var queryOverrides = map[string][]OverrideQuery{
112112
{
113113
semver.MustParseRange(">=10.0.0"),
114114
`
115-
SELECT slot_name, database, active, pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)
116-
FROM pg_replication_slots
115+
SELECT slot_name, database, active,
116+
(case pg_is_in_recovery() when 't' then pg_last_wal_receive_lsn() - restart_lsn else pg_current_wal_lsn() - restart_lsn end) as pg_wal_lsn_diff
117+
FROM pg_replication_slots;
117118
`,
118119
},
119120
},

collector/replication_slots.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ var pgReplicationSlot = map[string]*prometheus.Desc{
5353

5454
func (PGReplicationSlotCollector) Update(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error {
5555
rows, err := db.QueryContext(ctx,
56-
`SELECT
56+
`SELECT
5757
slot_name,
58-
pg_current_wal_lsn() - '0/0' AS current_wal_lsn,
58+
(case pg_is_in_recovery() when 't' then pg_last_wal_receive_lsn() - '0/0' else pg_current_wal_lsn() - '0/0' end) as current_wal_lsn,
5959
coalesce(confirmed_flush_lsn, '0/0') - '0/0',
6060
active
6161
FROM

0 commit comments

Comments
 (0)