citusdata / pg_cron

Run periodic jobs in PostgreSQL
PostgreSQL License
2.89k stars 193 forks source link

confirmation that pg_cron only runs on one database per server #334

Closed chrislungu closed 3 weeks ago

chrislungu commented 4 months ago

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

AyoubKaz07 commented 2 months ago

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:

https://github.com/citusdata/pg_cron/blob/f5d111117ddc0f4d83a1bad34d61b857681b6720/README.md?plain=1#L40

chrislungu commented 3 weeks ago

thanks, it's clear!