From e576430e8788e123ee41a2db16e7742b157c4aff Mon Sep 17 00:00:00 2001 From: Sergey Dudoladov Date: Thu, 5 Oct 2023 16:13:52 +0200 Subject: [PATCH] add replay-lag function (#932) Co-authored-by: Sergey Dudoladov --- postgres-appliance/scripts/_zmon_schema.dump | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/postgres-appliance/scripts/_zmon_schema.dump b/postgres-appliance/scripts/_zmon_schema.dump index aa45695c0..9f416d94e 100644 --- a/postgres-appliance/scripts/_zmon_schema.dump +++ b/postgres-appliance/scripts/_zmon_schema.dump @@ -477,4 +477,29 @@ CREATE OR REPLACE VIEW zmon_utils.last_status_active_cronjobs AS SELECT * FROM z REVOKE ALL ON TABLE zmon_utils.last_status_active_cronjobs FROM public; GRANT SELECT ON TABLE zmon_utils.last_status_active_cronjobs TO robot_zmon; +CREATE OR REPLACE FUNCTION zmon_utils.get_replay_lag( + OUT pid integer, + OUT usesysid oid, + OUT usename name, + OUT application_name text, + OUT replay_lag interval + ) RETURNS SETOF record AS +$BODY$ +SELECT pid, + usesysid, + usename, + application_name, + replay_lag + FROM pg_stat_replication + ORDER BY replay_lag DESC NULLS LAST; +$BODY$ +LANGUAGE sql SECURITY DEFINER STRICT SET search_path to 'pg_catalog'; + +CREATE OR REPLACE VIEW zmon_utils.replay_lag AS SELECT * FROM zmon_utils.get_replay_lag(); + +REVOKE EXECUTE ON FUNCTION zmon_utils.get_replay_lag() FROM public; +REVOKE ALL ON TABLE zmon_utils.replay_lag FROM public; + +GRANT SELECT ON TABLE zmon_utils.replay_lag TO robot_zmon; + GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA zmon_utils TO robot_zmon;