postgresqlreplicationpostgresql-10

Postgres recovery_min_apply_delay metric


We have delayed replicas (2h for example) and prometheus monitoring.
Prometheus do the query to get replication lag:

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

On delayed replicas it's return replication delay, like 7200 (2h replica delay).
I want to modify this request like this:

SELECT CASE WHEN NOT pg_is_in_recovery() THEN 0 ELSE GREATEST (0, EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp() - PG_GET_recovery_min_apply_delay()))) END AS lag

But i cannot find how i can get current recovery_min_apply_delay value via SQL.
Someone know how to get it?


Solution

  • https://www.postgresql.org/docs/14/functions-admin.html

    You want current_setting, which does what you would expect but returns a text value (because all settings can be represented as text)