Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chrislungu opened this issue Jun 19, 2024 · 1 comment
Open

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

chrislungu opened this issue Jun 19, 2024 · 1 comment

Comments

@chrislungu
Copy link

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
Copy link

AyoubKaz07 commented Sep 2, 2024

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');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants