citusdata/pg_cron

How to execute cron in database other than postgres

Opened this issue · 1 comments

I am trying to execute

psql -d postgres -U postgres

SELECT cron.schedule_in_database('latest_height_job', '*/1 * * * *', 'my_db', 'my_user', $$ SELECT height FROM transactions ORDER BY height DESC LIMIT 1 $$);

It gives me error

pg_Cron is installed in postgres. How to schedule a cron in my_db

You can view the cron settings by running:

SELECT * FROM pg_settings where name ilike '%cron%';

pg_cron can only run within one database in your cluster. You can change the default by running:

ALTER SYSTEM SET cron.database_name = '<database>';

Because it's a postmaster level setting, you'll have restart the cluster (pg_ctl)