Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/pg_cron.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ static void bgw_generate_returned_message(StringInfoData *display_msg, ErrorData
char *CronTableDatabaseName = "postgres";
static bool CronLogStatement = true;
static bool CronLogRun = true;
static bool CronDomDowAndLogic = false;

/* global variables */
static int CronTaskStartTimeout = 10000; /* maximum connection time */
Expand Down Expand Up @@ -327,6 +328,16 @@ _PG_init(void)
GUC_SUPERUSER_ONLY,
check_timezone, NULL, NULL);

DefineCustomBoolVariable(
"cron.dom_dow_and_logic",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Struggling a bit with this name, maybe cron.match_dom_and_dow communicates the intent slightly more rather than referring to the implementation logic. Any thoughts?

Copy link
Copy Markdown
Author

@vdjakovic vdjakovic Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, it becomes even more complicated with vacuum because it can't be run inside transaction/function, having is fixed here sounds most logical and future proof, cron.match_dom_and_dow is better name.

Is this one good for you?

DefineCustomBoolVariable(
	"cron.match_dom_and_dow",
	gettext_noop("Requires a day to match both the day-of-month and day-of-week fields."),
	NULL,
	&CronDomDowAndLogic,
	false,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, yes

gettext_noop("Use AND logic for day-of-month and day-of-week."),
NULL,
&CronDomDowAndLogic,
false,
PGC_SIGHUP,
GUC_SUPERUSER_ONLY,
NULL, NULL, NULL);

/* set up common data for all our workers */
worker.bgw_flags = BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION;
worker.bgw_start_time = BgWorkerStart_RecoveryFinished;
Expand Down Expand Up @@ -952,7 +963,7 @@ ShouldRunTask(entry *schedule, TimestampTz currentTime, bool doWild,
if (bit_test(schedule->minute, minute) &&
bit_test(schedule->hour, hour) &&
bit_test(schedule->month, month) &&
((schedule->flags & (DOM_STAR | DOW_STAR)) != 0
((CronDomDowAndLogic || (schedule->flags & (DOM_STAR | DOW_STAR)) != 0)
? (thisdom && thisdow)
: (thisdom || thisdow)))
{
Expand Down