Monitor Supabase Cron and pg_cron jobs

On this page

Supabase Cron is pg_cron, and pg_cron records each run in a table nobody reads. A failed job writes a row to cron.job_run_details, not an alert. A ping at the end of the job command makes a failed or stuck job visible within minutes.

How can a scheduled job fail silently on Supabase Cron and pg_cron?

  • pg_cron runs several jobs in parallel but only one instance of each job at a time. If a second run is due before the first finishes, it waits in a queue and starts when the first ends, so a slow job drifts later every time.
  • pg_cron does not run any jobs while the server is in hot standby mode. It starts again when the server is promoted.
  • Supabase recommends no more than 8 jobs running at once and no job running longer than 10 minutes.
  • The default time zone is GMT, set with cron.timezone. A schedule written in local time is wrong until the setting matches.
  • Job history lives in cron.job_run_details and grows if nobody prunes it.

What are the limits of Supabase Cron and pg_cron?

LimitWhat the documentation says
FrequencySupabase Cron runs jobs anywhere from every second to once a year.
SecondsAn interval of 1 to 59 seconds is allowed, but you cannot mix seconds with the other time units.
ConcurrencyRecommended maximum of 8 jobs at once; each job no more than 10 minutes.
Per-job instancesOne at a time; a due second run is queued.
Time zoneGMT by default; cron.timezone changes it.
Run historycron.job_run_details records the status of every run.

How do you add a CronMissed ping to Supabase Cron and pg_cron?

Make the job command call the work and then send the ping. If the work raises an error, the whole command fails before the ping, so a ping means success. The second statement uses the pg_net extension on Supabase to send the request.

sql
select cron.schedule(
  'nightly-cleanup',
  '15 3 * * *',
  $$
    select public.cleanup_old_rows();
    select net.http_get(url := 'https://ping.cronmissed.com/5f0c1b2e-7a3d-4c8e-9b61-2d4f8a7e3c10');
  $$
);

To catch jobs that fail, read the run history once an hour and ping a second check with the result.

sql
select count(*) filter (where status = 'failed') as failed_last_hour
from cron.job_run_details
where start_time > now() - interval '1 hour';

Which check settings fit Supabase Cron and pg_cron?

Create a cron check with the same expression in GMT. A job that keeps its work short needs only a few minutes of grace; give a job near the 10 minute guidance 15. For a job that runs every few seconds, a heartbeat check is the wrong tool: watch the failed count in cron.job_run_details instead and ping once a minute from a summary job.

How do you confirm the check works?

  1. Run select cron.schedule for a test job every minute, wait for a run, and look at cron.job_run_details.
  2. Make the cleanup function raise an exception and confirm that no ping arrives and the check goes down after the grace.
  3. Unschedule the job with cron.unschedule and confirm the check goes late.

Sources

Questions and answers

Does pg_net send the request inside the transaction?
No. pg_net sends requests asynchronously, so a slow CronMissed response cannot hold up your job. A request is queued only if the command reaches that statement, which is why it comes last.
Can I just check cron.job_run_details?
It tells you what ran. It cannot tell you that nothing ran, for example when the extension is stopped or the database is unreachable. The heartbeat catches both.
Know when this job stops

Create a check, add the ping to the job, and CronMissed alerts you the first time a run is late or reports a failure.

Start monitoring