Add a per-job log_run option to disable job_run_details - #442
Open
Christopher Pruijsen (cpruijsen) wants to merge 1 commit into
Open
Christopher Pruijsen (cpruijsen) wants to merge 1 commit into
Christopher Pruijsen (cpruijsen) wants to merge 1 commit into
Conversation
High-frequency schedules fill cron.job_run_details and bury useful history. Store a log_run flag on cron.job, expose it on cron.schedule and cron.alter_job, and skip run-detail writes when it is false. The global cron.log_run setting still disables logging for every job.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
cron.job.log_run(boolean, default true) so a single schedule can skipcron.job_run_detailswithout turningcron.log_runoff for the whole cluster. High-frequency jobs are the case in #366: at second granularity they fill the table and make it useless for the jobs you do care about.cron.schedule(job_name, schedule, command, log_run)overload.cron.alter_job(..., log_run)so existing jobs can be changed without recreating them.ShouldLogRunDetails()helper that requires bothcron.log_runand the per-job flag, replacing the six open-codedif (CronLogRun)sites.Existing jobs keep logging: the column defaults to true and the upgrade script backfills it that way.
Fixes #366.
On the shape
This is a boolean disable switch, matching the title of #366 and the
cron.schedule(..., log boolean)signature originally asked for, and mirroring the existing boolean GUC. The argument is namedlog_runrather thanlogto match the GUC and the existingactivecolumn.The thread later discussed an
all/errors/offenum so failures stay recorded. I did not build that, because errors-only needs a policy this thread does not settle: a row is written when a job starts and updated as it progresses, so keeping only failures means either inserting and deleting on success, or deferring the insert until the outcome is known and giving up visibility of in-flight jobs. Those are different features. Happy to switch if you would rather have the enum, and the boolean is a compatible subset of it either way.Upgrade note
Adding a parameter to
cron.alter_jobrequires dropping and recreating it, so anyGRANTorREVOKEtargeting the old six-argumentcron.alter_job(bigint,text,text,text,text,boolean)does not carry over. I confirmed this: acrossALTER EXTENSION pg_cron UPDATE,information_schema.routine_privilegesfor a test grantee goes from one row to zero. The upgrade script comments it. Admins who granted execute to a role need to re-grant the seven-argument function.cron.schedule_in_databasedeliberately does not gain the parameter, for the same drop-and-recreate reason. Schedule first, thenalter_job.Test plan
Run against PostgreSQL 17.11 with
shared_preload_libraries = 'pg_cron'.makeclean under the repo's-Wall -Wextra -Werror, no new warningsmake installcheckpasses, noregression.diffsCREATE EXTENSION pg_cron VERSION '1.0'; ALTER EXTENSION pg_cron UPDATE;reaches 1.7 withcron.job.log_runpresentcron.schedule('quiet', '1 seconds', 'select 1', log_run := false)writes nojob_run_detailsrows over 12s, while a default job alongside it writes 11alter_job(..., log_run := true)resumes logging andlog_run := falsestops it, on a running launchercron.scheduleon an existing named job updates the schedule and leaveslog_rununtouchedcron.log_run = offsuppresses every job includinglog_run = trueRegression coverage added to
sql/pg_cron-test.sqlis metadata-only, matching the existing suite, which never waits for the launcher. The launcher behaviour above was checked by hand.