[{"data":1,"prerenderedAt":28},["ShallowReactive",2],{"$fReVM_5TDf1tv9ze0nzuM2lUGHQC8hwi4uzuJ7RTDe6U":3},{"slug":4,"title":5,"description":6,"date":7,"tags":8,"draft":12,"readingMinutes":13,"html":14,"related":15},"supabase-cron","Supabase Cron: Scheduled Jobs, and the Green Tick That Lies","Supabase Cron checked against the docs: cron.schedule syntax, seconds schedules, calling an Edge Function with pg_net, run history cleanup, and the success status that means less than it says.","2026-11-13",[9,10,11],"supabase","postgres","cron",false,5,"\u003Cp>Supabase Cron is pg_cron with a dashboard on top. You schedule a job with \u003Ccode>cron.schedule(&#39;name&#39;, &#39;0 3 * * *&#39;, &#39;some SQL&#39;)\u003C/code> or through Integrations &gt; Cron in the dashboard, and Postgres runs it on time, anywhere from every second to once a year. A job can run SQL, call a database function, or make an HTTP request through \u003Ccode>pg_net\u003C/code>, which is how you trigger an Edge Function on a schedule.\u003C/p>\n\u003Cp>It&#39;s the right tool for most scheduled work in a Supabase app, and I&#39;d pick it over an external scheduler for anything that mostly touches the database. But there&#39;s one thing about it that catches people, and it&#39;s in the run history. I&#39;ll get to that.\u003C/p>\n\u003Cp>Everything here is checked against Supabase&#39;s \u003Ca href=\"https://supabase.com/docs/guides/cron\">Cron docs\u003C/a>, the \u003Ca href=\"https://supabase.com/docs/guides/cron/quickstart\">quickstart\u003C/a> and the \u003Ca href=\"https://supabase.com/docs/guides/database/extensions/pg_net\">pg_net docs\u003C/a> on November 13, 2026.\u003C/p>\n\u003Ch2>The syntax, quickly\u003C/h2>\n\u003Cpre>\u003Ccode class=\"language-sql\">select cron.schedule(\n  &#39;nightly-cleanup&#39;,          -- job name, case sensitive\n  &#39;0 3 * * *&#39;,                -- min hour day month weekday\n  $$ delete from sessions where expires_at &lt; now() $$\n);\n\u003C/code>\u003C/pre>\n\u003Cp>The five fields are the classic cron ones, weekday 0 to 6 starting Sunday (7 also means Sunday). The docs write their examples in GMT, so think in UTC when you pick the hour. If your users are in New York, 3 am UTC is 10 or 11 pm for them, depending on daylight saving, which matters if the job sends emails.\u003C/p>\n\u003Cp>For sub-minute jobs you write \u003Ccode>&#39;30 seconds&#39;\u003C/code> instead of a cron expression, anything from 1 to 59 seconds. That needs Postgres 15.1.1.61 or later, so an old project might refuse it.\u003C/p>\n\u003Cp>Two details I&#39;d want to know on day one. Names can&#39;t be edited, and calling \u003Ccode>cron.schedule\u003C/code> again with the same name silently replaces the old job. That&#39;s handy for idempotent migrations and nasty if two people pick the name \u003Ccode>cleanup\u003C/code>. To change a schedule or pause a job, use \u003Ccode>cron.alter_job\u003C/code> with \u003Ccode>active := false\u003C/code> instead of deleting and recreating it.\u003C/p>\n\u003Cp>Supabase recommends no more than 8 jobs running at the same time and no job running longer than 10 minutes. If a job needs longer than that, it&#39;s a batch process pretending to be a cron job. Split it, or have the cron job enqueue work for something else to chew through.\u003C/p>\n\u003Ch2>Calling an Edge Function on a schedule\u003C/h2>\n\u003Cp>This is the pattern most apps end up with: cron fires, \u003Ccode>pg_net\u003C/code> posts to the function, the function does the real work (calls Stripe, sends emails, syncs an API).\u003C/p>\n\u003Cpre>\u003Ccode class=\"language-sql\">select cron.schedule(&#39;sync-invoices&#39;, &#39;*/15 * * * *&#39;, $$\n  select net.http_post(\n    url := &#39;https://&lt;project-ref&gt;.supabase.co/functions/v1/sync-invoices&#39;,\n    headers := jsonb_build_object(&#39;Content-Type&#39;, &#39;application/json&#39;, &#39;Authorization&#39;, &#39;Bearer &#39; || (select decrypted_secret from vault.decrypted_secrets where name = &#39;cron_key&#39;)),\n    body := &#39;{}&#39;::jsonb,\n    timeout_milliseconds := 5000\n  );\n$$);\n\u003C/code>\u003C/pre>\n\u003Cp>The docs&#39; own example puts the key straight into the SQL. I don&#39;t. The command text sits in \u003Ccode>cron.job\u003C/code> in plain view of anyone with database access, and it ends up in every schema dump you ever take. Keeping the key in Vault and reading it at run time is one extra line.\u003C/p>\n\u003Cp>The URL is the other trap. It&#39;s hard-coded to one project. Restore that dump into a new project, or clone production into staging, and the job keeps calling the old project every 15 minutes. Nothing errors. It just does the work in the wrong place.\u003C/p>\n\u003Ch2>The green tick that lies\u003C/h2>\n\u003Cp>Here&#39;s the part I promised. Every run lands in \u003Ccode>cron.job_run_details\u003C/code> with a status, and the dashboard shows it as a nice list of successes. For a job that calls an Edge Function, that &quot;succeeded&quot; means almost nothing.\u003C/p>\n\u003Cp>\u003Ccode>pg_net\u003C/code> is asynchronous. \u003Ccode>net.http_post\u003C/code> doesn&#39;t send anything while your job runs; it queues the request, and the request only goes out after the transaction commits. The job&#39;s SQL finished fine (it queued a request), so the run is marked succeeded. Whether the function returned 200, 500 or nothing at all is recorded somewhere else, in \u003Ccode>net._http_response\u003C/code>, and only for 6 hours by default.\u003C/p>\n\u003Cimg src=\"/blog/supabase-cron/two-logs.webp\" alt=\"The same cron run in two tables: cron.job_run_details says succeeded, net._http_response shows the Edge Function timed out after 2 seconds\" width=\"1600\" height=\"900\" loading=\"lazy\">\u003Cp>So a sync that has been failing for a week looks perfect in the cron history. To see the truth, check the responses:\u003C/p>\n\u003Cpre>\u003Ccode class=\"language-sql\">select id, status_code, timed_out, error_msg, created\nfrom net._http_response\nwhere status_code is distinct from 200 or timed_out\norder by created desc\nlimit 20;\n\u003C/code>\u003C/pre>\n\u003Cp>The default timeout is 2,000 ms, which is short for a function that calls a slow API. A timeout there means \u003Ccode>pg_net\u003C/code> stopped waiting, not that anything retried. Nothing retries. If the work matters, have the function write its own result row (started, finished, error) and alert on that, or at least raise the timeout. \u003Ccode>pg_net\u003C/code> also says it&#39;s meant for about 200 requests a second at most, which you won&#39;t hit from cron, but you will if a trigger fans out one request per row.\u003C/p>\n\u003Ch2>Clean up the history\u003C/h2>\n\u003Cp>\u003Ccode>cron.job_run_details\u003C/code> is never cleaned up automatically, and the rows stay even after you unschedule a job. A \u003Ccode>&#39;30 seconds&#39;\u003C/code> job writes 2,880 rows a day. The quickstart suggests a cron job to clean up the cron jobs, which is a little funny and exactly right:\u003C/p>\n\u003Cpre>\u003Ccode class=\"language-sql\">select cron.schedule(&#39;job-run-details-cleanup&#39;, &#39;0 0 * * *&#39;,\n  $$ delete from cron.job_run_details where end_time &lt; now() - interval &#39;7 days&#39; $$);\n\u003C/code>\u003C/pre>\n\u003Cp>Add it the same day you add your first job.\u003C/p>\n\u003Ch2>When I&#39;d use something else\u003C/h2>\n\u003Cp>If the job is mostly about the database (expire rows, refresh a materialized view, roll up stats), cron inside Postgres is perfect. Zero network, no extra service, and the job lives next to the data it touches.\u003C/p>\n\u003Cp>If the job is long, needs retries, or talks to five external APIs, I&#39;d still trigger it from cron but hand it to a queue. Supabase has \u003Ccode>pgmq\u003C/code> for that. A 10-minute cap and no retries is fine for a trigger and bad for a workflow.\u003C/p>\n\u003Cp>Apps built with Lovable often have a few of these jobs already, created from a prompt, with keys in the SQL and a project URL that nobody will remember during a migration. If that&#39;s yours, my agency \u003Ca href=\"https://lovable2live.com/\">Lovable 2 Live\u003C/a> moves and fixes them. For anything else, \u003Ca href=\"https://calendly.com/director-norsky/meeting\">book a free call\u003C/a>. All consultation is free.\u003C/p>\n",[16,20,24],{"slug":17,"title":18,"description":19},"supabase-backups","Supabase Backups: What Each Plan Keeps, and What It Skips","Supabase backups checked November 2026: none on Free, 7 days on Pro, PITR from $100 a month, what a restore leaves out, and the db dump I'd run anyway.",{"slug":21,"title":22,"description":23},"supabase-cli","Supabase CLI: Migrations, Types and the Docker Catch","The Supabase CLI in late 2026: how to install it, why local dev needs a container runtime, and the migration commands that keep production in sync.",{"slug":25,"title":26,"description":27},"supabase-realtime","Supabase Realtime: What It Costs and Where It Breaks","Supabase Realtime in late 2026: how messages are counted and billed, the per-plan limits, the errors you hit first, and when to switch from Postgres Changes to Broadcast.",1795910047875]