Skip to content

Commit

Permalink
Fix of replication slots metrics when it's executed on the replica in…
Browse files Browse the repository at this point in the history
…stance and pg_current_wal_lsn execution is not allowed
  • Loading branch information
marcelorauldiaz committed Apr 24, 2024
1 parent 4ac7dfe commit 9f78273
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions pgwatch2/metrics/replication_slots/10/metric_master.sql
Original file line number Diff line number Diff line change
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,
greatest(age(xmin), age(catalog_xmin))::int8 as xmin_age_tx
case when pg_is_in_recovery() = FALSE 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 pg_is_in_recovery() = FALSE 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
Original file line number Diff line number Diff line change
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 pg_is_in_recovery() = FALSE 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 pg_is_in_recovery() = FALSE 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 9f78273

Please sign in to comment.