Supabase pg_cron Edge Function: Schedule Recurring Jobs

A Supabase pg_cron edge function is the free, in-database way to run recurring jobs. This guide covers pg_cron scheduling, triggering Edge Functions with pg_net, securing the endpoint, UTC pitfalls, and debugging.

Your Flutter app needs to send a digest email every morning, purge expired sessions every night, and retry failed webhooks hourly. You could rent a server, pay for a cron SaaS, or run a timer inside the app that dies the moment the phone sleeps. Every option costs money or breaks in production. Meanwhile your Supabase Postgres already ships a battle-tested scheduler — pg_cron — that can run SQL or ping an Edge Function on any schedule, for free, inside your database. Pair it with pg_net and a Supabase pg_cron edge function pattern, and you have the whole recurring-job story without leaving the platform. *Last updated: 2026-10-10* What you&#x27;ll build Your first pg_cron schedule: a nightly SQL cleanup job The pg_cron + pg_net pattern that triggers an Edge Function on a schedule Secret-header authentication so random callers can&#x27;t fire your cron endpoint Timezone-safe schedules (the UTC trap that bites everyone once) A monitoring habit using cron.job_run_details so silent failures stop being silent This builds on the complete Flutter and Supabase setup guide ; the Flutter side here is small — the work happens in SQL and Edge Functions. If you use Edge Functions already, skim the Edge Functions in Dart guide for the deployment half. Step 1: Enable pg_cron and schedule your first job pg_cron is platform-managed on Supabase — enable it under Database > Extensions , or run this in the SQL editor: create extension if not exists pg_cron; -- every night at 02:00 UTC: delete notifications older than 30 days select cron.schedule( &#x27;nightly-notification-cleanup&#x27;, &#x27;0 2 * * *&#x27;, $ delete from public.notifications where created_at < now() - interval &#x27;30 days&#x27; $ ); The signature is cron.schedule(job_name, schedule, command) — the schedule is…

Explore