sudo apt-get update
# Install the pg_cron extension
sudo apt-get -y install postgresql-10-cron
# add to postgresql.conf:
shared_preload_libraries = 'pg_cron'
cron.database_name = 'postgres'
run as superuser:

CREATE EXTENSION pg_cron;

--
 optionally, grant usage to regular users:
GRANT
 USAGE 
ON
 SCHEMA cron TO marco;
 -- Delete old data on Saturday at 3:30am (GMT)
SELECT cron.schedule('30 3 * * 6', $$DELETE FROM events WHERE event_time < now() - interval '1 week'$$);
schedule
---------
       42

-- Vacuum every day at 10:00am (GMT)
SELECT cron.schedule('0 10 * * *', 'VACUUM');
 schedule
----------
       43

-- Stop scheduling a job
SELECT cron.unschedule(43);
 unschedule
------------
          t

results matching ""

    No results matching ""