diff --git a/pgwatch2/metrics/replication/10/metric.sql b/pgwatch2/metrics/replication/10/metric.sql index d878830f..e6532196 100644 --- a/pgwatch2/metrics/replication/10/metric.sql +++ b/pgwatch2/metrics/replication/10/metric.sql @@ -2,6 +2,7 @@ select /* pgwatch2_generated */ (extract(epoch from now()) * 1e9)::int8 as epoch_ns, application_name as tag_application_name, concat(coalesce(client_addr::text, client_hostname), '_', client_port::text) as tag_client_info, + coalesce(pg_wal_lsn_diff(case when pg_is_in_recovery() then pg_last_wal_receive_lsn() else pg_current_wal_lsn() end, sent_lsn)::int8, 0) as sent_lag_b, coalesce(pg_wal_lsn_diff(case when pg_is_in_recovery() then pg_last_wal_receive_lsn() else pg_current_wal_lsn() end, write_lsn)::int8, 0) as write_lag_b, coalesce(pg_wal_lsn_diff(case when pg_is_in_recovery() then pg_last_wal_receive_lsn() else pg_current_wal_lsn() end, flush_lsn)::int8, 0) as flush_lag_b, coalesce(pg_wal_lsn_diff(case when pg_is_in_recovery() then pg_last_wal_receive_lsn() else pg_current_wal_lsn() end, replay_lsn)::int8, 0) as replay_lag_b, diff --git a/pgwatch2/metrics/replication_slots/10/metric_master.sql b/pgwatch2/metrics/replication_slots/10/metric_master.sql index fae5c41b..46867515 100644 --- a/pgwatch2/metrics/replication_slots/10/metric_master.sql +++ b/pgwatch2/metrics/replication_slots/10/metric_master.sql @@ -5,6 +5,7 @@ select /* pgwatch2_generated */ 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 from pg_replication_slots; diff --git a/pgwatch2/sql/config_store/metric_definitions.sql b/pgwatch2/sql/config_store/metric_definitions.sql index 4f152d16..7581b71a 100644 --- a/pgwatch2/sql/config_store/metric_definitions.sql +++ b/pgwatch2/sql/config_store/metric_definitions.sql @@ -1834,6 +1834,7 @@ SELECT (extract(epoch from now()) * 1e9)::int8 as epoch_ns, application_name as tag_application_name, concat(coalesce(client_addr::text, client_hostname), '_', client_port::text) as tag_client_info, + coalesce(pg_wal_lsn_diff(case when pg_is_in_recovery() then pg_last_wal_receive_lsn() else pg_current_wal_lsn() end, sent_lsn)::int8, 0) as sent_lag_b, coalesce(pg_wal_lsn_diff(case when pg_is_in_recovery() then pg_last_wal_receive_lsn() else pg_current_wal_lsn() end, write_lsn)::int8, 0) as write_lag_b, coalesce(pg_wal_lsn_diff(case when pg_is_in_recovery() then pg_last_wal_receive_lsn() else pg_current_wal_lsn() end, flush_lsn)::int8, 0) as flush_lag_b, coalesce(pg_wal_lsn_diff(case when pg_is_in_recovery() then pg_last_wal_receive_lsn() else pg_current_wal_lsn() end, replay_lsn)::int8, 0) as replay_lag_b, @@ -6929,6 +6930,7 @@ select 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 from pg_replication_slots;