From 15c6da254e8eb15f0164e3b243d1f193b9ecd312 Mon Sep 17 00:00:00 2001 From: "Mikhail.Balayan" Date: Fri, 13 Oct 2023 18:25:40 +0800 Subject: [PATCH 1/2] Additional metrics based on stat_statements stats --- pgwatch2/sql/config_store/metric_definitions.sql | 2 ++ 1 file changed, 2 insertions(+) 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; From 7645403e8130160786c8a359315ad8d05dcd1f84 Mon Sep 17 00:00:00 2001 From: "Mikhail.Balayan" Date: Mon, 16 Oct 2023 11:33:08 +0800 Subject: [PATCH 2/2] updating the files in the `metric` folder --- pgwatch2/metrics/replication/10/metric.sql | 1 + pgwatch2/metrics/replication_slots/10/metric_master.sql | 1 + 2 files changed, 2 insertions(+) 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;