Skip to content

Commit

Permalink
[-] fix replication slots metrics for replica instances (#768)
Browse files Browse the repository at this point in the history
* Fix of replication slots metrics when it's executed on the replica instance and pg_current_wal_lsn execution is not allowed
* Update pgwatch2/metrics/replication_slots/10/metric_master.sql
---------
Co-authored-by: Pavlo Golub <pavlo.golub@gmail.com>
  • Loading branch information
marcelorauldiaz committed Apr 24, 2024
1 parent 4387798 commit 35fbf79
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions pgwatch2/metrics/replication_slots/10/metric_master.sql
Expand Up @@ -4,8 +4,10 @@ select /* pgwatch2_generated */
coalesce(plugin, 'physical')::text as tag_plugin,
active,
case when active then 0 else 1 end as non_active_int,
pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)::int8 as restart_lsn_lag_b,
pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn)::int8 as confirmed_flush_lsn_lag_b,
case when not pg_is_in_recovery() then pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)::int8
else pg_wal_lsn_diff(pg_last_wal_replay_lsn(), restart_lsn)::int8 end as restart_lsn_lag_b,
case when not pg_is_in_recovery() then pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn)::int8
else pg_wal_lsn_diff(pg_last_wal_replay_lsn(), confirmed_flush_lsn)::int8 end as confirmed_flush_lsn_lag_b,
greatest(age(xmin), age(catalog_xmin))::int8 as xmin_age_tx
from
pg_replication_slots;
6 changes: 4 additions & 2 deletions pgwatch2/sql/config_store/metric_definitions.sql
Expand Up @@ -6929,8 +6929,10 @@ select
coalesce(plugin, 'physical')::text as plugin,
active,
case when active then 0 else 1 end as non_active_int,
pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)::int8 as restart_lsn_lag_b,
pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn)::int8 as confirmed_flush_lsn_lag_b,
case when not pg_is_in_recovery() then pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)::int8
else pg_wal_lsn_diff(pg_last_wal_replay_lsn(), restart_lsn)::int8 end as restart_lsn_lag_b,
case when not pg_is_in_recovery() then pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn)::int8
else pg_wal_lsn_diff(pg_last_wal_replay_lsn(), confirmed_flush_lsn)::int8 end as confirmed_flush_lsn_lag_b,
greatest(age(xmin), age(catalog_xmin))::int8 as xmin_age_tx
from
pg_replication_slots;
Expand Down

0 comments on commit 35fbf79

Please sign in to comment.