Published October 21, 2026
How to Monitor Supabase pg_cron Jobs
Supabase Cron, built on the pg_cron extension, lets you schedule SQL, database functions, and HTTP calls from inside Postgres. It's great for cleanup tasks, rollups, refreshing materialized views, and calling Edge Functions on a timer.
The catch: when a pg_cron job fails, the error goes into a table. Nothing tells you about it unless you go and look. And if the job stops running altogether, there's no row at all.
This guide shows you how to inspect pg_cron runs, and how to add a heartbeat with pg_net that fires only when the job actually succeeds.
A quick pg_cron refresher
Schedule a job with cron.schedule(name, schedule, command):
select cron.schedule(
'purge-expired-sessions', -- job name
'15 3 * * *', -- 03:15 every day (UTC by default)
$$ delete from public.sessions where expires_at < now() - interval '7 days' $$
);
Useful facts:
- Jobs are stored in
cron.job, and every run is recorded incron.job_run_details. - Schedules use standard five-field cron syntax. Recent pg_cron versions also accept intervals like
'30 seconds'. - Times are in UTC (GMT) unless your setup changes the
cron.timezonesetting. - Calling
cron.scheduleagain with the same name updates the job. Remove one withselect cron.unschedule('purge-expired-sessions');.
See what's failing right now
-- Most recent runs, newest first
select j.jobname, d.status, d.return_message, d.start_time, d.end_time
from cron.job_run_details d
join cron.job j using (jobid)
order by d.start_time desc
limit 20;
-- Failures in the last 24 hours
select j.jobname, d.start_time, d.return_message
from cron.job_run_details d
join cron.job j using (jobid)
where d.status = 'failed'
and d.start_time > now() - interval '24 hours'
order by d.start_time desc;
-- Last successful run per job, to spot jobs that went quiet
select j.jobname, j.schedule, j.active, max(d.end_time) as last_success
from cron.job j
left join cron.job_run_details d
on d.jobid = j.jobid and d.status = 'succeeded'
group by j.jobname, j.schedule, j.active
order by last_success nulls first;
That last query is the one people wish they'd run sooner. An inactive job, or one with an old last_success, is a silent failure in progress.
The Supabase Dashboard also has a Cron page where you can view jobs and their run history.
Why the table isn't enough
cron.job_run_details is a log, not an alert. It doesn't help when:
- Nobody checks it. Failures accumulate quietly.
- The job never runs. If the job was unscheduled, set to inactive, or the scheduler isn't running, no row is written at all.
- The database itself isn't running. If the project is paused or down, nothing inside it can tell you that.
- The job "succeeds" without doing the work. A
deletethat matches zero rows succeeds.
You need a signal that leaves the database and goes to something that expects it.
Add a heartbeat with pg_net
pg_net lets Postgres make asynchronous HTTP requests. Enable it in the Dashboard (Database → Extensions → pg_net), or with SQL:
create extension if not exists pg_net;
The important property, from Supabase's docs: pg_net requests are not started until the transaction commits. If your job's work and the ping run in the same transaction, a failed job rolls back the ping too. You get a ping only on success, with no extra logic.
Wrap the job in a function
Putting the work and the ping in one function keeps them in one transaction and makes the job easy to test.
create or replace function public.job_purge_expired_sessions()
returns void
language plpgsql
security definer
set search_path = public
as $$
declare
deleted int;
begin
delete from public.sessions
where expires_at < now() - interval '7 days';
get diagnostics deleted = row_count;
-- Optional: treat "nothing to do" as normal for this job.
-- If zero rows would be abnormal, raise instead:
-- if deleted = 0 then raise exception 'no rows purged'; end if;
perform net.http_get(
url := 'https://cronnudge.com/ping/<check-id>',
timeout_milliseconds := 5000
);
end;
$$;
Then schedule the function:
select cron.schedule(
'purge-expired-sessions',
'15 3 * * *',
$$ select public.job_purge_expired_sessions(); $$
);
If the delete throws, the function raises, the transaction rolls back, the queued ping is discarded, and CronNudge alerts once after grace. A later success sends one recovery alert. The URL is https://cronnudge.com/ping/<check-id>. GET, POST, and HEAD all count, and the response is text/plain ok. Do not publish the ping URL. It is a different id from the optional badge, which stays off until you turn it on. Free is 10 checks, with email and one Slack or Discord channel. Signed webhooks and the API are on Pro ($12 a month, 100 checks).
Keep the ping URL out of your migrations
If your SQL lives in a public repo, don't hardcode the ping URL. Anyone with it could send fake success pings. Store it in Supabase Vault and read it at runtime:
-- once, from the SQL editor
select vault.create_secret('https://cronnudge.com/ping/<check-id>', 'hb_purge_sessions');
-- inside the function
perform net.http_get(
url := (select decrypted_secret from vault.decrypted_secrets where name = 'hb_purge_sessions'),
timeout_milliseconds := 5000
);
Monitoring jobs that call Edge Functions
A common pattern is a pg_cron job that calls an Edge Function with net.http_post. In that case, the pg_cron run "succeeds" as soon as the request is queued, even if the Edge Function later fails. Put the heartbeat inside the Edge Function, after its work completes:
// supabase/functions/daily-rollup/index.ts
Deno.serve(async () => {
await buildDailyRollup(); // throws on failure
try {
await fetch(Deno.env.get("HEARTBEAT_DAILY_ROLLUP")!, {
signal: AbortSignal.timeout(5000),
});
} catch (e) {
console.error("heartbeat failed", e);
}
return new Response("ok");
});
Set the schedule and grace period
Use the same cron expression in your monitor, in UTC. CronNudge's default grace is 5 minutes. The form offers none, 1 minute, 5 minutes, 15 minutes, and 1 hour. The API accepts any whole number of seconds from 0 through 7 days.
A job every 5 minutes can use 5 or 15 minutes of grace. A nightly job can use 1 hour. Recent pg_cron versions accept interval schedules such as 30 seconds. CronNudge's shortest period is 5 minutes on Free and 1 minute on Pro, so a sub-minute job cannot be given a matching period.
Housekeeping
cron.job_run_details grows forever. On a frequent schedule, it can get large. Prune it with... a cron job:
select cron.schedule(
'prune-cron-history',
'0 4 * * *',
$$ delete from cron.job_run_details where end_time < now() - interval '14 days' $$
);
pg_net responses are temporary. Look in net._http_response if you need to debug a ping. How long those rows stay is a Supabase setting, not a CronNudge one:
select id, status_code, error_msg, created
from net._http_response
order by created desc
limit 10;
Overlapping runs. Keep jobs short, or batch the work, so a slow run does not collide with the next one. CronNudge can also alert on overlap if the check pings /start and run tracking is on.
Common reasons a pg_cron job doesn't run
- It's inactive. Check
select jobname, active from cron.job;. - Time zone. It ran at 03:15 UTC, not local time.
- Wrong database. pg_cron jobs run in the database recorded on the job. If you scheduled it somewhere unexpected, it may be running against the wrong data.
- Permissions. The job runs as the user who scheduled it. A function that works in the SQL editor as
postgresmay fail for another role. - The project was paused or restarted. Nothing scheduled inside the database runs while it's down.
- Invalid schedule. Validate the expression with the crontab explainer.
FAQ
Where do I see pg_cron errors?
In cron.job_run_details, in the status and return_message columns, or on the Cron page in the Supabase Dashboard.
Does pg_cron alert on failure? No. It records the result. You need to query the table on a schedule or send a heartbeat out of the database.
Will the pg_net ping fire if my job fails? Not if the ping is in the same transaction as the work. pg_net only sends requests after the transaction commits, so a rollback cancels the ping.
What time zone does Supabase Cron use? UTC by default.
Can pg_cron run every few seconds?
Recent pg_cron versions support interval schedules such as '30 seconds'. Use them sparingly.
How do I monitor a pg_cron job that calls an Edge Function? Send the heartbeat from the Edge Function after it finishes its work, not from the SQL that triggers it.
CronNudge gives each pg_cron job a ping URL and alerts you when it goes quiet. Free is 10 checks, with email and one Slack or Discord channel. Pro is $12 a month for 100 checks, and adds signed webhooks and the API. Add a check.