Postgres Cron: differenze tra le versioni
Jump to navigation
Jump to search
(Creata pagina con "per poter schedulare jon all'nterno di postgres, è necessario installare un componente aggiuntivo: apt install postgresql-14-cron successivamente va configurato: alter sys...") |
Nessun oggetto della modifica |
||
Riga 1: | Riga 1: | ||
per poter schedulare jon all'nterno di postgres, è necessario installare un componente aggiuntivo: |
per poter schedulare jon all'nterno di postgres, è necessario installare un componente aggiuntivo: |
||
apt install postgresql-14-cron |
apt install postgresql-14-cron |
||
successivamente va configurato: |
successivamente va configurato: |
||
alter system set shared_preload_libraries = 'pg_cron'; |
alter system set shared_preload_libraries = 'pg_cron'; |
||
-- serve riavvio per poter eseguire gli altri comandi di configurazione |
-- serve riavvio per poter eseguire gli altri comandi di configurazione |
||
-- NON SERVE: SELECT pg_reload_conf(); |
-- NON SERVE: SELECT pg_reload_conf(); |
||
-- NON FUNZIONA: load 'pg_cron'; |
-- NON FUNZIONA: load 'pg_cron'; |
||
alter system set cron.database_name = 'postgres'; |
alter system set cron.database_name = 'postgres'; |
||
create extension pg_cron; |
create extension pg_cron; |
||
-- grant usage on schema cron to utente01; |
-- grant usage on schema cron to utente01; |
||
Riga 18: | Riga 18: | ||
select * from cron.job; |
select * from cron.job; |
||
-- Delete old data on Saturday at 3:30am (GMT) |
-- 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'$$); |
SELECT cron.schedule('30 3 * * 6', $$DELETE FROM events WHERE event_time < now() - interval '1 week'$$); |
||
-- Vacuum every day at 10:00am (GMT) |
-- Vacuum every day at 10:00am (GMT) |
||
SELECT cron.schedule('0 10 * * *', 'VACUUM'); |
SELECT cron.schedule('0 10 * * *', 'VACUUM'); |
||
-- Unschedule all tasks |
-- Unschedule all tasks |
||
SELECT cron.unschedule(jobid) FROM cron.job; |
SELECT cron.unschedule(jobid) FROM cron.job; |
||
Versione attuale delle 14:18, 22 mar 2022
per poter schedulare jon all'nterno di postgres, è necessario installare un componente aggiuntivo:
apt install postgresql-14-cron
successivamente va configurato:
alter system set shared_preload_libraries = 'pg_cron'; -- serve riavvio per poter eseguire gli altri comandi di configurazione -- NON SERVE: SELECT pg_reload_conf(); -- NON FUNZIONA: load 'pg_cron'; alter system set cron.database_name = 'postgres'; create extension pg_cron; -- grant usage on schema cron to utente01;
per utilizzarlo, ci sono le funzioni:
select * from cron.job;
-- 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'$$);
-- Vacuum every day at 10:00am (GMT) SELECT cron.schedule('0 10 * * *', 'VACUUM');
-- Unschedule all tasks SELECT cron.unschedule(jobid) FROM cron.job;