Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

docs(cron): document how to clean up cron.job_run_details (#50211)

Maksym Ionutsafe0afd66b8c8
diff --git a/apps/docs/content/guides/cron/quickstart.mdx b/apps/docs/content/guides/cron/quickstart.mdx
index 6c6b369c8e3..616aedbb84a 100644
--- a/apps/docs/content/guides/cron/quickstart.mdx
+++ b/apps/docs/content/guides/cron/quickstart.mdx
@@ -210,7 +210,7 @@ limit 10;
<Admonition type="caution">
-The records in the `cron.job_run_details` table are not cleaned up automatically. They are also not removed when jobs are unscheduled, which will take up disk space in your database.
+The records in the `cron.job_run_details` table are not cleaned up automatically. They are also not removed when jobs are unscheduled, which will take up disk space in your database. Schedule a cleanup Job to remove old records (see [Clean up job run history](#clean-up-job-run-history) below).
</Admonition>
@@ -235,6 +235,22 @@ select cron.schedule (
);
```
+### Clean up job run history
+
+{/* <!-- vale off --> */}
+
+`cron.job_run_details` grows with every Job run and is never cleaned up automatically, even after a Job is unscheduled. Schedule a Job to delete old records, keeping only the last 7 days:
+
+{/* <!-- vale on --> */}
+
+```sql
+select cron.schedule(
+ 'job-run-details-cleanup', -- name of the cron job
+ '0 0 * * *', -- daily at midnight (GMT)
+ $$ delete from cron.job_run_details where end_time < now() - interval '7 days' $$
+);
+```
+
### Run a vacuum every day
{/* <!-- vale off --> */}