Skip to content

Commit

Permalink
adjust pg_replication_slots metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
yanboer committed May 26, 2023
1 parent fb316ad commit 9422d8b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions cmd/postgres_exporter/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ var queryOverrides = map[string][]OverrideQuery{
{
semver.MustParseRange(">=10.0.0"),
`
SELECT slot_name, database, active, pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)
FROM pg_replication_slots
SELECT slot_name, database, active,
(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
FROM pg_replication_slots;
`,
},
},
Expand Down
4 changes: 2 additions & 2 deletions collector/replication_slots.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ var pgReplicationSlot = map[string]*prometheus.Desc{

func (PGReplicationSlotCollector) Update(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error {
rows, err := db.QueryContext(ctx,
`SELECT
`SELECT
slot_name,
pg_current_wal_lsn() - '0/0' AS current_wal_lsn,
(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,
coalesce(confirmed_flush_lsn, '0/0') - '0/0',
active
FROM
Expand Down

0 comments on commit 9422d8b

Please sign in to comment.