citusdata/pg_cron

confirmation that pg_cron only runs on one database per server

chrislungu opened this issue · 2 comments

hi all,

I just want to confirm something, the documentation is not best (sorry). it says the following:

pg_cron may only be installed to one database in a cluster. If you need to run jobs in multiple databases, use cron.schedule_in_database().

may I confirm that this means, in practice, that if I install pg_cron in the database "postgres" and I have additional databases on the same server, I can use pg_cron to schedule jobs across the entire server, i.e. in other databases?

thank you

Kinda late, but it seems clear
However, if you want to run a cron job across multiple databases you would use cron.schedule_in_database() instead of cron.schedule().
But jobs must be scheduled from the database configured in cron.database_name config param in postgresql.conf, since the pg_cron background worker reads job descriptions from that database.

cron.schedule_in_database() just has an extra param, which is the database name where the job should run.

Example of scheduling across databases from the docs:

SELECT cron.schedule_in_database('weekly-vacuum', '0 4 * * 0', 'VACUUM', 'some_other_database');