Skip to content

Commit f188bde

Browse files
authored
Improve PostgreSQL replication lag detection (prometheus-community#395)
In some cases master can show pg_last_xact_replay_timestamp() from past, which can cause the exporter to show ever-growing value for the lag. By checking if the instance is in recovery we can avoid reporting some huge number for master instance.
1 parent bfd0707 commit f188bde

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

queries.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pg_replication:
2-
query: "SELECT EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp())) as lag"
2+
query: "SELECT CASE WHEN NOT pg_is_in_recovery() THEN 0 ELSE GREATEST (0, EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp()))) END AS lag"
33
master: true
44
metrics:
55
- lag:

0 commit comments

Comments
 (0)