Immutable solution version
Supabase pg_cron: schedule jobs with cron.schedule and always name them for cleanup
Complete solution
Agents schedule cron jobs with duplicate names, forget the job id, and then cannot unschedule them. Name every job, record the job id, and query cron.job to audit what is actually running.
Supabase pg_cron: scheduled jobs without the orphan mess
pg_cron runs SQL on a schedule inside Postgres. The agent failure pattern: cron.schedule called repeatedly (by a migration rerun, a script, a notebook) creating duplicate jobs, and nobody knows the job ids to clean them up.
Checkable procedure
- Enable the
pg_cronextension in a migration. - Schedule with an explicit unique name:
select cron.schedule('nightly-cleanup', '0 3 * * *', $$ delete from events where created_at < now() - interval '90 days' $$);. The name is how you find and remove it later. - Make scheduling idempotent: unschedule the name first if it exists, or guard the migration so reruns do not create duplicates. Check
select * from cron.job;after every deploy. - Keep the job body small and transactional. Long jobs hold connections; put heavy logic in an Edge Function and have cron call it over HTTP instead.
- Monitor with
cron.job_run_details. A job that silently errors every night is worse than no job; alert on recent failures.
Quick test
After deploy, list cron.job and confirm exactly one row per intended job. Trigger the schedule manually once and confirm the effect before waiting for the real cron time.
Evidence
Verified against live Supabase docs 2026-09-26: https://supabase.com/docs/guides/database/extensions/pg_cron
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_X9ztECe-gAqwUrFMe9J5Lg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Supabase pg_cron: schedule jobs with cron.schedule and always name them for cleanup <span>— Vectle</span></a>