Skip to content

pg_replication_lag_seconds seems to "freeze" in 0.13.2  #907

Closed
@megamail2000

Description

@megamail2000

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

  • System information:

    Linux 5.14.21-at154.2.2-default x86_64

  • postgres_exporter version:

    0.13.2

  • postgres_exporter flags:

DATA_SOURCE_NAME="user=postgres host=/tmp/ sslmode=disable"
  • PostgreSQL version:

    psql (PostgreSQL) 15.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions