prometheus-community / postgres_exporter

A PostgreSQL metric exporter for Prometheus
Apache License 2.0
2.83k stars 745 forks source link

pg_replication_lag_seconds seems to "freeze" in 0.13.2 #907

Closed megamail2000 closed 1 year ago

megamail2000 commented 1 year ago

The replication metrics request (taken from pg_replication.go) returns an actual replication state:

postgres=# SELECT
CASE
WHEN NOT pg_is_in_recovery() THEN 0
                WHEN pg_last_wal_receive_lsn () = pg_last_wal_replay_lsn () THEN 0
ELSE GREATEST (0, EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp())))
END AS lag,
CASE
WHEN pg_is_in_recovery() THEN 1
ELSE 0
END as is_replica
;
 lag | is_replica
-----+------------
   0 |          1

While the exporter still outputs the maximum value from the past:

# curl -s http://10.6.251.206:9187/metrics | grep pg_replication_lag
# HELP pg_replication_lag_seconds Replication lag behind master in seconds
# TYPE pg_replication_lag_seconds gauge
pg_replication_lag_seconds 1.138475469918e+06

In this case the other metrics are updated properly. How can I reset the output with an actual zero lag value?

Environment

DATA_SOURCE_NAME="user=postgres host=/tmp/ sslmode=disable"
sysadmind commented 1 year ago

I think #895 should fix this. It will be in the next release. If this does not resolve the issue, feel free to re-open.