S
Supabase2mo ago
Pondia

Cron do schedule but never execute

Hello, The job are well scheduled but never executed. I have followed this guide https://supabase.com/docs/guides/troubleshooting/pgcron-debugging-guide-n1KTaz but everything is fine regarding the cron scheduler. job_run_details table remain empty.
CREATE EXTENSION IF NOT EXISTS pg_cron;

GRANT usage ON SCHEMA cron TO postgres;
GRANT all privileges ON ALL TABLES IN SCHEMA cron TO postgres;
CREATE EXTENSION IF NOT EXISTS pg_cron;

GRANT usage ON SCHEMA cron TO postgres;
GRANT all privileges ON ALL TABLES IN SCHEMA cron TO postgres;
On the SQL editor
SELECT cron.schedule(
'job_in_1_minutes',
TO_CHAR(NOW() + interval '1 minutes', 'MI HH24 DD MM') || ' *',
$$SELECT now()$$
);


SELECT cron.schedule(
'job_in_2_minutes',
TO_CHAR(NOW() + interval '2 minutes', 'MI HH24 DD MM') || ' *',
$$SELECT now()$$
);


SELECT cron.schedule(
'job_in_5_minutes',
TO_CHAR(NOW() + interval '5 minutes', 'MI HH24 DD MM') || ' *',
$$SELECT now()$$
);
SELECT cron.schedule(
'job_in_1_minutes',
TO_CHAR(NOW() + interval '1 minutes', 'MI HH24 DD MM') || ' *',
$$SELECT now()$$
);


SELECT cron.schedule(
'job_in_2_minutes',
TO_CHAR(NOW() + interval '2 minutes', 'MI HH24 DD MM') || ' *',
$$SELECT now()$$
);


SELECT cron.schedule(
'job_in_5_minutes',
TO_CHAR(NOW() + interval '5 minutes', 'MI HH24 DD MM') || ' *',
$$SELECT now()$$
);
13 Replies
garyaustin
garyaustin2mo ago
Have you tried hard coding a cron time? Also try the Cron UI to see if you can get any cron to run.
Pondia
PondiaOP2mo ago
I have created a job from the UI, when I manually execute it by clicking the "Run command" button I got the toast success message but it never been executed. "Last run" column remain empty.
No description
No description
garyaustin
garyaustin2mo ago
I would go back thru that guide again. Did you restart your instance? Your cron code works fine on my system.
No description
Pondia
PondiaOP2mo ago
Restarting the instance did works ! Thank you @garyaustin Now, I'm unable to say what is the root source of this issue and I'm a bit concern to have cron jobs silently not executing planned tasks. Does Supabase is able to captured the issue on clients instance ? May I also ask why jobs schedule are not on UTC by default ? If I provide a date UTC for exemple 2025-09-02 14:58:00+00 it will schedule the next run on 02 Sep 2025 16:58:00 (+0200). My database is deployed in France/Paris timezone UTC+2. For exemple, I'm expecting the following to be scheduled at UTC time:
SELECT cron.schedule(
'test_timezone',
TO_CHAR((NOW() AT TIME ZONE 'UTC') + interval '1 minutes', 'MI HH24 DD MM') || ' *',
$$SELECT now()$$
);
SELECT cron.schedule(
'test_timezone',
TO_CHAR((NOW() AT TIME ZONE 'UTC') + interval '1 minutes', 'MI HH24 DD MM') || ' *',
$$SELECT now()$$
);
garyaustin
garyaustin2mo ago
I thought Supabase servers where set to UTC and Cron by default uses UTC.
garyaustin
garyaustin2mo ago
My crons run UTC time. It is 10:30 for me and 3:30 UTC/GMT
No description
garyaustin
garyaustin2mo ago
Not sure what you mean by capture issues on clients instance. You have logs. Supabase can see those logs I assume, not sure if they have other logs or not. When I ran your original code it ran 1 minute later.
Pondia
PondiaOP2mo ago
For me, it set this at (+0200) in 2026 (meaning the date has passed which is not possible). So there is a missmatch of timezone between what I set as UTC in my SQL and what my instance get)
No description
garyaustin
garyaustin2mo ago
What are you showing there?
Pondia
PondiaOP2mo ago
I'm showing the Cron UI of the test_timezone job (above snippet)
garyaustin
garyaustin2mo ago
Ah. I don't use that. Let me see if it shows anything useful for me. So that view seems to show your timezone. But if you look at the cron schema run details it is in GMT/UTC. Unless you changed it Supabase servers should be GMT and cron runs default to that time for their setting.
Pondia
PondiaOP2mo ago
Hello ! So I've been trying to use cron job for a while now, and it seems that, if I don't restart the project time to time I endup having cron jobs not running at all. I'm unable to find the root source if the issue
garyaustin
garyaustin2mo ago
Not sure I've seen anyone in that situation. I would look to the repository https://github.com/citusdata/pg_cron and see if there are similar issues. I'd make sure I was cleaning up my job_run_details table as described in the docs there also especially if running 5 minutes or less type tasks.
GitHub
GitHub - citusdata/pg_cron: Run periodic jobs in PostgreSQL
Run periodic jobs in PostgreSQL. Contribute to citusdata/pg_cron development by creating an account on GitHub.

Did you find this page helpful?