Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scheduling a stored procedure in PostgreSQL 9.2.8

I've a simple stored procedure which calculates values from 1 table and insert it in another. I want to schedule it to run once in a day.

I came across pg_cron but it looks like it will only work for version 9.5 and above.

How to to schedule this sp or it;s select statement select * from stored_procedure_name() in postgres

like image 788
Nouman Bhatti Avatar asked Oct 23 '25 15:10

Nouman Bhatti


2 Answers

as mentioned by @AlexM I started looking in Cron and found few useful links to do this outside of postgresql.

crontab in linux with 20 useful examples helps me out in understanding the structure for creating a new entry in the crontab.

edit the crontab file and added the following entry in it. As it's in the same server so no need to pass credentials for the postgresql

00    00    *     *    * psql -c "select query here;"
like image 165
Nouman Bhatti Avatar answered Oct 26 '25 09:10

Nouman Bhatti


Unfortunately, the previous comments are correct. There is no scheduler within PostgreSQL nor any of the supplied utilities. Your only option is to use an external scheduler.

like image 31
Kirk Roybal Avatar answered Oct 26 '25 08:10

Kirk Roybal



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!