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; -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). @@ -235,6 +235,22 @@ select cron.schedule ( ); ``` +### Clean up job run history + +{/* */} + +`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: + +{/* */} + +```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 {/* */}