如何停止 postgres cron 工作?有没有办法阻止它?

Anu*_*sha 0 postgresql

假设我在我的数据库中运行以下 cron 作业:

SELECT cron.schedule('30 3 * * 6', $$DELETE FROM events WHERE event_time < now() - interval '1 week'$$);
Run Code Online (Sandbox Code Playgroud)

那会停止运行吗?如果我不想再运行该作业,我该如何删除它?

如果没有其他方法可以停止上述工作,请提出我可以使用的替代方法。

提前致谢!

小智 5

您可以在 cron.job 表中找到作业 ID 并使用该cron.unschedule函数停止作业:

postgres=# SELECT * FROM cron.job;
 jobid ?  schedule  ?                             command                             ? nodename  ? nodeport ? database ? username ? active ? jobname 
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
     1 ? 30 3 * * 6 ? DELETE FROM events WHERE event_time < now() - interval '1 week' ? localhost ?     5432 ? postgres ? marco    ? t      ? 
(1 row)

postgres=# SELECT cron.unschedule(1);
 unschedule 
????????????
 t
(1 row)

postgres=# SELECT * FROM cron.job;
 jobid ? schedule ? command ? nodename ? nodeport ? database ? username ? active ? jobname 
???????????????????????????????????????????????????????????????????????????????????????????
(0 rows)
Run Code Online (Sandbox Code Playgroud)