The Postgres CRON
Add extension
CREATE EXTENSION pg_cron;
Execute the following commands to auto clean data from services. Note: After each command update the nodename in jobs table to empty or use command
UPDATE cron.job SET nodename = '';
Logging
Section titled “Logging”Delete messages that have been created for more than one year, every day.
SELECT cron.schedule_in_database('[logging] messages cleanup (1 year)', '0 1 * * *', $$DELETE FROM message WHERE created_at < now() - interval '1 year'$$, 'logging');
Integration Data
Section titled “Integration Data”Delete messages that have a retention date greater than now, every day.
SELECT cron.schedule_in_database('[integration-data] messags cleanup', '30 1 * * *', $$DELETE FROM message WHERE created_at < now() - interval '1 month'$$, 'integration_data');
Delete service values that have retention date greater than now, every day.
SELECT cron.schedule_in_database('[integration-data] service values cleanup', '35 1 * * *', $$DELETE FROM service_value WHERE retained_at < now()$$, 'integration_data');
Device Flow
Section titled “Device Flow”Delete messages that have retention date greater than now, every day.
SELECT cron.schedule_in_database('[device-flow] connector messages cleanup', '0 2 * * *', $$DELETE FROM connector_message WHERE created_at < now() - interval '1 year'$$, 'device_flow');
Device Coding
Section titled “Device Coding”Delete decoder messages that have been created for more than one year, every day.
SELECT cron.schedule_in_database('[device-coding] decoder messages cleanup', '0 3 * * *', $$DELETE FROM decoder_message WHERE created_at < now() - interval '1 year'$$, 'device_coding');
Measurement
Section titled “Measurement”Delete measurements that have reported time less than 3 years
SELECT cron.schedule_in_database('[measurements] measurement cleanup (3 year)', '0 1 * * *', $$DELETE FROM measurement WHERE reported_at < (now() - interval '3 year')$$, 'meter_data');