Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop postgres cron jobs ? is there even a way to stop it?

Tags:

postgresql

Suppose if I run the following cron job in my DB:

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

will that ever stop running ? How can I delete it if I do not want the job to run anymore ?

If there is no other way I can stop the above job, Please suggest an alternative that I can use.

Thanks in advance!

like image 241
Anusha Avatar asked Jan 21 '26 21:01

Anusha


1 Answers

You can find the job ID in the cron.job table and use the cron.unschedule function to stop the job:

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)
like image 91
Marco Slot Avatar answered Jan 24 '26 20:01

Marco Slot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!