← All guides

Supabase Cron Job Not Running? Causes and Fixes

Supabase

You asked your AI builder for a nightly cleanup, a reminder email or a sync every five minutes. It handed you a block of SQL with cron.schedule(...) in it, you ran it, and nothing visible happens. Or the dashboard says every run succeeded while the Edge Function it was supposed to call never shows a request.

Scheduled jobs fail quietly. No user sees an error page, so the first sign is missing data days later. This guide is a checklist in the order the symptoms show up: confirm the job exists and is active, read its run history, check that the scheduler process is alive, then follow the HTTP call into pg_net and the Edge Function. Each step has a query you can paste into the SQL Editor. Supabase fixes: /fix/supabase. If the app was built in Lovable: /fix/lovable.

How Supabase Cron works

Supabase Cron is built on the pg_cron Postgres extension, which does the scheduling and runs each job. Jobs live in the cron.job table, and every run writes a row to cron.job_run_details with its status (Supabase Cron). You can create jobs from Integrations → Cron in the dashboard or with SQL; both end up in the same table.

A job’s command is plain SQL. When that SQL calls net.http_post(...), a second extension, pg_net, is doing the HTTP work, and it works asynchronously: the request is queued, it only goes out after the transaction commits, and the response lands in a separate table later (pg_net). That split explains the confusing “succeeded but nothing happened” case covered below.

Two scheduling details catch AI-generated snippets:

  • Times are in GMT. The schedule examples in Supabase’s quickstart are annotated as GMT, so 0 9 * * * fires at 09:00 GMT, not 9 AM where you live (Cron quickstart).
  • Names are unique and case sensitive. Scheduling a second job under an existing name replaces the first one. If two prompts both produced a job called daily-job, only the newer command survives (Cron quickstart).

Step 1: confirm the job exists and is active

Start with what is actually scheduled:

select jobid, jobname, schedule, active, username, command
from cron.job
order by jobid;

Look for three things:

  • The job is missing. The SQL was never run against this project, ran against a different project, or a later cron.unschedule removed it.
  • active is false. Someone (or an AI agent) paused it. Turn it back on with cron.alter_job:
select cron.alter_job(jobid, active := true)
from cron.job
where jobname = 'your-job-name';
  • The command is not what you expect. An overwritten job (same name, newer SQL) shows up here.

If the job looks right, move on to its history.

Step 2: read the run history in cron.job_run_details

Every run that pg_cron starts gets a row with a status, a return_message, and start and end times (Cron quickstart). For a single job:

select d.runid, d.status, d.return_message, d.start_time, d.end_time
from cron.job_run_details d
join cron.job j on j.jobid = d.jobid
where j.jobname = 'your-job-name'
order by d.start_time desc
limit 20;

To list only problem runs across every job in the last two days:

select jobid, status, return_message, start_time
from cron.job_run_details
where status not in ('succeeded', 'running')
  and start_time > now() - interval '2 days'
order by start_time desc;

Read the result like this:

What you seeWhat it points to
No rows at all, even past the scheduled timeThe scheduler is not running, or the schedule has not matched yet (check GMT). Go to Step 3.
failed with an error in return_messageThe SQL itself broke: a missing table, a permissions error, a typo, or a timeout. Fix the SQL and test it by hand in the SQL Editor.
succeeded, but the Edge Function or API never got the requestThe HTTP step is the problem. Go to the pg_net section.
Rows that stay running and pile upLong jobs overlapping each other. See the timeouts section.

The same history is in the dashboard under Integrations → Cron → Jobs via the History button next to each job.

One side effect: Supabase does not prune cron.job_run_details for you, so the table keeps growing until you schedule a cleanup (Cron quickstart; Troubleshooting cron jobs). A cleanup job is in the last section.

Step 3: is the pg_cron scheduler alive?

All jobs depend on one background process named pg_cron scheduler. If it has died, nothing runs and nothing is logged. Supabase’s debugging guide checks for it in pg_stat_activity (pg_cron debugging guide). A shorter version:

select pid, application_name, backend_start, state
from pg_stat_activity
where application_name ilike 'pg_cron scheduler';
  • One row comes back: the scheduler is up. The cause is elsewhere.
  • No row: the worker is gone. Supabase’s fix is a fast reboot from Project Settings → General. A reboot restarts the database, so pick a moment when a short interruption is acceptable.

The same guide recommends a software upgrade from General Settings when the Postgres version is below 15.6.1.122. That upgrade brings pg_cron 1.6.4 or later, which Supabase says includes bug fixes and can revive the scheduler on its own (pg_cron debugging guide).

The cron launcher crashes about once a minute

Supabase documents one specific crash loop. The pg_cron launcher fails roughly every minute with duplicate key value violates unique constraint "job_run_details_pkey". The cause is the cron.runid_seq sequence falling behind the IDs already stored in cron.job_run_details. The documented fix is to empty the history table (launcher crash article):

truncate cron.job_run_details;

This deletes all run history. If you need it, copy it to your own table first.

“Succeeded” but the Edge Function never answered

This case is the hardest to spot from the dashboard. A job whose command is select net.http_post(...) only asks pg_net to send a request and returns a request ID. That counts as success for pg_cron, whether or not the HTTP call works afterwards. The real result is stored by pg_net in net._http_response, keyed by the request ID, and kept for six hours by default (pg_net).

Check the newest responses:

select id, status_code, timed_out, error_msg, left(content, 300) as body_start, created
from net._http_response
order by created desc
limit 20;

Or only the failures:

select id, status_code, timed_out, error_msg, created
from net._http_response
where error_msg is not null or status_code >= 400
order by created desc;

How to read it:

  • timed_out is true. pg_net gave up before the function replied. Its default timeout_milliseconds is 2000, which is two seconds (pg_net). Any function that takes longer looks like a failure from the database side. Pass a larger value, as in the Vault example below.
  • status_code is 401 or 403. The function rejected the credentials. See the next section.
  • status_code is 404. The URL path or function name is wrong, or the function is not deployed on this project.
  • status_code is 500, 504 or 546. The function itself failed. Supabase’s Edge Function limits put the request idle timeout at 150 seconds, after which the caller gets a 504 (Edge Function limits). For reading these codes and the function logs, see Edge Function returned a non-2xx status code.
  • No matching row for the time of the run. The response is older than six hours, or the request never went out. pg_net stores its queue and responses in unlogged tables, and Postgres discards those after a crash or an unclean shutdown (pg_net).

Then open the function’s Invocations and Logs in the dashboard for the same time window. If pg_net shows a 2xx response but the expected rows or emails are still missing, the bug is inside the function’s own code. If the job sends sign-up or password emails and those never arrive, also check Supabase auth emails not sending.

Wrong key or header on the Edge Function call

Snippets copied from older tutorials or produced by an AI tool can put a key in the wrong header, or paste the key straight into the SQL. Supabase’s current guidance for calling a function from pg_cron has three parts (Scheduling Edge Functions; Securing Edge Functions):

  1. Send the secret key, not the publishable key. The publishable key is public, so a function that accepts it can be called by anyone holding it.
  2. Put the key on the apikey header. Supabase’s newer API keys aren’t JWTs, and Supabase reserves the Authorization header for user tokens (Authorization headers).
  3. Store the project URL and the key in Vault and read them inside the job, so the key never sits in the job’s command text.

Save the two values once:

select vault.create_secret('https://your-project-ref.supabase.co', 'project_url');
select vault.create_secret('your-secret-key', 'cron_secret_key');

Then schedule the call, reading both values from vault.decrypted_secrets at run time:

select cron.schedule(
  'nightly-report',
  '0 2 * * *',
  $$
  select net.http_post(
    url := (select decrypted_secret from vault.decrypted_secrets where name = 'project_url')
      || '/functions/v1/nightly-report',
    headers := jsonb_build_object(
      'Content-Type', 'application/json',
      'apikey', (select decrypted_secret from vault.decrypted_secrets where name = 'cron_secret_key')
    ),
    body := jsonb_build_object('triggered_at', now()),
    timeout_milliseconds := 10000
  ) as request_id;
  $$
);

Because the job name is reused, running this again with a corrected command replaces the old job rather than adding a second one.

On the function side, a call that carries only an API key has no user JWT, so the function needs two changes (Securing Edge Functions):

  • Turn off the platform JWT check for that one function in supabase/config.toml:
[functions.nightly-report]
verify_jwt = false
  • In the handler, wrap it with withSupabase from @supabase/server using auth: 'secret'. That mode only accepts the secret key named default. If you created a separate key for automations, use auth: 'secret:<name>' with that key’s name instead.

Turning off verify_jwt without the auth: 'secret' check leaves the function open to any caller, so do both together.

Two cautions from Supabase’s docs. Anyone who can read vault.decrypted_secrets can read the decrypted values, so keep that view’s privileges tight (Vault). And while a request waits in net.http_request_queue, the decrypted key sits there too, readable by any database role with login rights (Scheduling Edge Functions). If a secret key was ever pasted into a cron command, a migration or a chat with an AI tool, treat it as exposed: Leaked an API key? Do this first.

Long jobs and statement timeouts

Jobs that run SQL directly, such as a big delete or a stats rebuild, can hit Postgres timeouts. The cron.job table shows which role each job runs as (the username column). Supabase lists no role-level timeout for postgres, but the global default caps it at two minutes (Timeouts). A run that hits it shows as failed with a statement timeout in return_message.

Supabase’s debugging guide suggests moving long work into a database function with its own timeout (pg_cron debugging guide). The timeout is set on the function definition:

create or replace function public.rebuild_daily_stats()
returns void
language plpgsql
set statement_timeout to '5min'
as $$
begin
  -- the long-running statements go here
  delete from public.events where created_at < now() - interval '90 days';
end;
$$;

select cron.schedule('rebuild-daily-stats', '15 3 * * *', 'select public.rebuild_daily_stats()');

Supabase also sets limits on how much cron work to run at once. Its Cron overview recommends no more than 8 jobs running concurrently and keeping each under 10 minutes (Supabase Cron). The debugging guide adds that pg_cron can run up to 32 jobs at the same time, each holding a database connection, and that jobs scheduled too close together can fail from connection overload (pg_cron debugging guide). If a job runs every minute but takes longer than a minute, runs start stacking up. Spread the schedules out or make each run do less.

For work that happens in an Edge Function, the limits are the function’s: a 150-second request idle timeout on every plan, and a wall-clock limit of 150 seconds on Free and 400 seconds on paid plans (Edge Function limits). Set timeout_milliseconds to cover the function’s normal run time, and split jobs that need more than that.

How to confirm it’s fixed

A green status in the history only proves the SQL ran. To prove the whole chain works, have the job leave a heartbeat you can check at a glance:

create table if not exists public.cron_heartbeat (
  id bigint generated always as identity primary key,
  source text not null,
  beat_at timestamptz not null default now()
);

alter table public.cron_heartbeat enable row level security;

select cron.schedule(
  'heartbeat-every-5-min',
  '*/5 * * * *',
  $$ insert into public.cron_heartbeat (source) values ('cron') $$
);

With RLS enabled and no policies, the table is closed to the public API, while jobs running as postgres can still write to it. Background on that: Supabase RLS policies explained.

For jobs that call an Edge Function, have the function insert its own row (for example with source = 'edge-function') at the end of a successful run. Then one query shows whether both halves are alive:

select source, max(beat_at) as last_beat, now() - max(beat_at) as age
from public.cron_heartbeat
group by source;

If cron is fresh and edge-function is stale, the scheduler works and the HTTP call or the function does not. If both are stale, go back to Step 3.

Finally, keep the history tables small with a cleanup job (Cron quickstart):

select cron.schedule(
  'cleanup-cron-history',
  '30 0 * * *',
  $$
  delete from cron.job_run_details where end_time < now() - interval '7 days';
  delete from public.cron_heartbeat where beat_at < now() - interval '7 days';
  $$
);

FAQ

Why does my cron job say succeeded but the Edge Function didn’t run?

The job only queued an HTTP request through pg_net, and queuing worked. The HTTP call happens after the job’s transaction commits, and its result is stored in net._http_response. Check that table for timed_out, status_code and error_msg. The two-second default timeout and a rejected key are the first things to rule out.

How do I see errors from a job that calls an Edge Function?

Three places, in order: cron.job_run_details for SQL errors, net._http_response for the HTTP status and body (kept for six hours by default), and the function’s Invocations and Logs in the dashboard. Supabase’s debugging guide also shows how to search the Postgres logs for pg_cron errors and how to add raise log lines inside a job’s function (pg_cron debugging guide).

How often can a cron job run?

Supabase’s Cron overview puts the range at one run per second at the fastest and one run per year at the slowest (Supabase Cron). Schedules under a minute use an interval such as '30 seconds' (1 to 59 seconds), and that syntax needs Postgres 15.1.1.61 or a newer version (Cron quickstart). The pg_net page still describes pg_cron as minute-precision; this guide follows the Cron docs, which cover second-level schedules. How often a job should run depends on how long each run takes, given the concurrency and 10-minute guidance above.

Is it safe to put my secret key in the cron SQL?

No. Pasted into the command, the key is stored in plain text in cron.job and visible to anyone who can read that table or the migration file. Store it in Vault and read it from vault.decrypted_secrets inside the job, as shown above. Even then, the decrypted key passes through pg_net’s request queue while the call is pending.

What if my project keeps restarting?

The Supabase docs and troubleshooting pages reviewed for this guide do not describe cron changes causing whole-project restarts. What they do document is narrower: the pg_cron launcher crashing about once a minute with a duplicate key error on job_run_details_pkey (fixed by truncating the history table), and a dead scheduler that needs a fast reboot. If the project itself is cycling, check status.supabase.com for an incident and open a Supabase support ticket with the project ref and the times you saw it. Meanwhile, pause recent jobs with cron.alter_job(..., active := false) so you can tell whether they are involved.

Comments

Add a comment

Generated for you. Click to type your own.

Required. Never shown on the page. Privacy policy.

Basic markdown: **bold**, *italic*, `code`, lists, quotes, and fenced code blocks. HTML shows as plain text.

Your draft stays on this device until you post.