Skip to content

Commit 11ab5cc

Browse files
fix: pg_stat_replication works on cascading replicas
Signed-off-by: Michael Todorovic <[email protected]>
1 parent 1b9e76d commit 11ab5cc

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

cmd/postgres_exporter/postgres_exporter.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -403,26 +403,26 @@ var queryOverrides = map[string][]OverrideQuery{
403403
semver.MustParseRange(">=10.0.0"),
404404
`
405405
SELECT *,
406-
(case pg_is_in_recovery() when 't' then null else pg_current_wal_lsn() end) AS pg_current_wal_lsn,
407-
(case pg_is_in_recovery() when 't' then null else pg_wal_lsn_diff(pg_current_wal_lsn(), pg_lsn('0/0'))::float end) AS pg_current_wal_lsn_bytes,
408-
(case pg_is_in_recovery() when 't' then null else pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn)::float end) AS pg_wal_lsn_diff
406+
(case pg_is_in_recovery() when 't' then pg_last_wal_receive_lsn() else pg_current_wal_lsn() end) AS pg_current_wal_lsn,
407+
(case pg_is_in_recovery() when 't' then pg_wal_lsn_diff(pg_last_wal_receive_lsn(), pg_lsn('0/0'))::float else pg_wal_lsn_diff(pg_current_wal_lsn(), pg_lsn('0/0'))::float end) AS pg_current_wal_lsn_bytes,
408+
(case pg_is_in_recovery() when 't' then pg_wal_lsn_diff(pg_last_wal_receive_lsn(), replay_lsn)::float else pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn)::float end) AS pg_wal_lsn_diff
409409
FROM pg_stat_replication
410410
`,
411411
},
412412
{
413413
semver.MustParseRange(">=9.2.0 <10.0.0"),
414414
`
415415
SELECT *,
416-
(case pg_is_in_recovery() when 't' then null else pg_current_xlog_location() end) AS pg_current_xlog_location,
417-
(case pg_is_in_recovery() when 't' then null else pg_xlog_location_diff(pg_current_xlog_location(), replay_location)::float end) AS pg_xlog_location_diff
416+
(case pg_is_in_recovery() when 't' then pg_last_xlog_receive_location() else pg_current_xlog_location() end) AS pg_current_xlog_location,
417+
(case pg_is_in_recovery() when 't' then pg_xlog_location_diff(pg_last_xlog_receive_location(), replay_location)::float else pg_xlog_location_diff(pg_current_xlog_location(), replay_location)::float end) AS pg_xlog_location_diff
418418
FROM pg_stat_replication
419419
`,
420420
},
421421
{
422422
semver.MustParseRange("<9.2.0"),
423423
`
424424
SELECT *,
425-
(case pg_is_in_recovery() when 't' then null else pg_current_xlog_location() end) AS pg_current_xlog_location
425+
(case pg_is_in_recovery() when 't' then pg_last_xlog_receive_location() else pg_current_xlog_location() end) AS pg_current_xlog_location
426426
FROM pg_stat_replication
427427
`,
428428
},
@@ -433,7 +433,7 @@ var queryOverrides = map[string][]OverrideQuery{
433433
semver.MustParseRange(">=9.4.0 <10.0.0"),
434434
`
435435
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
436+
(case pg_is_in_recovery() when 't' then pg_xlog_location_diff(pg_last_xlog_receive_location(), restart_lsn) else pg_xlog_location_diff(pg_current_xlog_location(), restart_lsn) end) as pg_xlog_location_diff
437437
FROM pg_replication_slots
438438
`,
439439
},

0 commit comments

Comments
 (0)