Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit e91c163

Browse files
committed
Fix replication delay in seconds metric
1 parent 2c6719e commit e91c163

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: gauges/replication.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ func (g *Gauges) ReplicationDelayInSeconds() prometheus.Gauge {
6060
Help: "Dabatase replication delay in seconds",
6161
ConstLabels: g.labels,
6262
},
63-
"SELECT coalesce(extract(epoch from now() - pg_last_xact_replay_timestamp()), 0) AS replication_delay",
63+
`
64+
SELECT CASE WHEN pg_is_in_recovery() is true
65+
THEN COALESCE(EXTRACT(EPOCH FROM now() - pg_last_xact_replay_timestamp()), 0)
66+
ELSE 0
67+
END AS replication_delay
68+
`,
6469
)
6570
}
6671

0 commit comments

Comments
 (0)