diff --git a/initdb/02_2_signalk_cron.sql b/initdb/02_2_signalk_cron.sql index 45fd21c..94b2374 100644 --- a/initdb/02_2_signalk_cron.sql +++ b/initdb/02_2_signalk_cron.sql @@ -348,21 +348,6 @@ COMMENT ON FUNCTION public.cron_vacuum_fn IS 'init by pg_cron to full vacuum tables on schema api'; --- CRON for clean up job details logs -CREATE FUNCTION job_run_details_cleanup_fn() RETURNS void AS $$ -DECLARE -BEGIN - -- Remove job run log older than 3 months - RAISE NOTICE 'job_run_details_cleanup_fn'; - DELETE FROM cron.job_run_details - WHERE start_time <= NOW() AT TIME ZONE 'UTC' - INTERVAL '91 DAYS'; -END; -$$ language plpgsql; --- Description -COMMENT ON FUNCTION - public.job_run_details_cleanup_fn - IS 'init by pg_cron to cleanup job_run_details table on schema public postgres db'; - -- CRON for alerts notification CREATE FUNCTION cron_process_alerts_fn() RETURNS void AS $$ DECLARE @@ -473,3 +458,20 @@ $no_activity$ language plpgsql; COMMENT ON FUNCTION public.cron_process_no_activity_fn IS 'init by pg_cron, check for vessel with no activity for more than 200 days then send notification'; + +-- Need to be in the postgres database. +\c postgres +-- CRON for clean up job details logs +CREATE FUNCTION job_run_details_cleanup_fn() RETURNS void AS $$ +DECLARE +BEGIN + -- Remove job run log older than 3 months + RAISE NOTICE 'job_run_details_cleanup_fn'; + DELETE FROM cron.job_run_details + WHERE start_time <= NOW() AT TIME ZONE 'UTC' - INTERVAL '91 DAYS'; +END; +$$ language plpgsql; +-- Description +COMMENT ON FUNCTION + public.job_run_details_cleanup_fn + IS 'init by pg_cron to cleanup job_run_details table on schema public postgres db'; diff --git a/initdb/04pgcron.sql b/initdb/04pgcron.sql index 1db8147..fe61d67 100644 --- a/initdb/04pgcron.sql +++ b/initdb/04pgcron.sql @@ -76,7 +76,7 @@ UPDATE cron.job SET database = 'signalk'; UPDATE cron.job SET username = 'username'; -- TODO update to scheduler, pending process_queue update --UPDATE cron.job SET username = 'username' where jobname = 'cron_vacuum'; -- TODO Update to superuser for vaccuum permissions UPDATE cron.job SET nodename = '/var/run/postgresql/'; -- VS default localhost ?? -UPDATE cron.job SET database = 'postgresql' WHERE jobid=8; -- job_run_details_cleanup_fn +UPDATE cron.job SET database = 'postgresql' WHERE jobname = 'job_run_details_cleanup_fn'; -- check job lists SELECT * FROM cron.job; -- unschedule by job id