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

时间:2017-02-09 19:37:13

标签: postgresql

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

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

会永远停止运行吗?如果我不想让这个工作再运行,我怎么能删除它呢?

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

提前致谢!

1 个答案:

答案 0 :(得分:1)

您可以在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)