Skip to main content

Supabase Cron Job Setup Guide

A guide for setting up and configuring scheduled cron jobs in Supabase using the Dashboard.

Prerequisites​

  • A Supabase project with the pg_cron extension enabled
  • Access to the Supabase Dashboard
  1. Open your Supabase project dashboard
  2. Go to Integrations → Cron → Jobs
  3. Click Create job or navigate directly to the new job form

Configure Your Cron Job​

Job Name​

Enter a descriptive name for your job (e.g., upload_try_week_clean_job).

Important: Job names are case-sensitive and cannot be renamed after creation. Creating a second job with the same name will overwrite the first.

Schedule​

Enter a cron expression or use the "Use natural language" toggle for presets.

Cron Syntax Reference​

┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-6, Sunday=0)
│ │ │ │ │
* * * * *

Common Examples​

ExpressionDescription
0 0 * * 0Every Sunday at midnight (GMT)
0 0 * * 1Every Monday at midnight (GMT)
0 2 * * 1Every Monday at 2:00 AM (GMT)
*/5 * * * *Every 5 minutes
0 0 1 * *First day of each month at midnight
0 3 * * 6Every Saturday at 3:00 AM (GMT)
30 secondsEvery 30 seconds (requires Postgres 15.1.1.61+)

Job Type​

Choose one of the following:

TypeDescriptionRequirements
SQL SnippetExecute raw SQL statementsNone
Database functionCall an existing Postgres functionFunction must exist
HTTP RequestSend HTTP requests to external URLspg_net extension
Supabase Edge FunctionTrigger a Supabase Edge Functionpg_net extension

SQL Snippet Example​

For a weekly reset of upload attempt counters:

UPDATE users
SET avatar_upload_tries = 0;

Save the Job​

Click Save cron job to activate your scheduled job.

Managing Existing Jobs​

Edit a Job​

  1. Find the job in the Jobs list
  2. Click the three-dot menu (⋮) on the right
  3. Select Edit cron job
  4. Make changes and click Save cron job

Activate/Deactivate a Job​

Toggle the Active/Inactive switch next to the job name.

Delete a Job​

  1. Click the three-dot menu (⋮) on the right
  2. Select Delete cron job
  3. Confirm by typing the job name

View Job History​

Click the History button next to the job name to inspect past runs.

Installing pg_net Extension​

Required for HTTP requests and Edge Function triggers:

  1. In the cron job form, click Install pg_net extension
  2. Or run via SQL:
CREATE EXTENSION IF NOT EXISTS pg_net WITH SCHEMA extensions;

Advanced Examples​

Delete Old Data Weekly​

SELECT cron.schedule(
'saturday-cleanup',
'30 3 * * 6', -- Saturday at 3:30 AM (GMT)
$$ DELETE FROM events WHERE event_time < now() - interval '1 week' $$
);

Run Vacuum Daily​

SELECT cron.schedule('nightly-vacuum', '0 3 * * *', 'VACUUM');

Call a Database Function​

SELECT cron.schedule('call-db-function', '*/5 * * * *', 'SELECT hello_world()');

Invoke Edge Function​

SELECT cron.schedule(
'invoke-function-every-half-minute',
'30 seconds',
$$
SELECT net.http_post(
url := 'https://project-ref.supabase.co/functions/v1/function-name',
headers := jsonb_build_object(
'Content-Type', 'application/json',
'Authorization', 'Bearer ' || 'YOUR_ANON_KEY'
),
body := jsonb_build_object('time', now()),
timeout_milliseconds := 5000
) AS request_id;
$$
);

Caution​

Be careful when scheduling system maintenance tasks. For example, terminating idle connections with pg_terminate_backend(pid) can disrupt background processes like nightly backups.

Consider using existing Postgres settings (like idle_session_timeout) instead of custom cron jobs for common maintenance tasks.

References​