Re: PG_CRON

From: Erik Wienhold <ewie(at)ewie(dot)name>
To: Geri Wright <geri(dot)w123(at)gmail(dot)com>
Cc: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: PG_CRON
Date: 2024-03-25 19:04:34
Message-ID: 6ej6oi5yhq67vmqpg5ihgvvssvevvbvm7ox2iww7zxxd7mzusq@nz462tui7wwm
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On 2024-03-25 16:48 +0100, Geri Wright wrote:
> I have pg_cron installed. It's working fine for simple schedules but having
> difficulty scheduling a job to run only on the 4th Sunday of the month at 3
> am. It seams to ignore the combination of "day of month" and "day of week".
> It runs everyday from the 22nd through the 28th. I have tried with the
> following schedules.
>
> 0 3 22-28 * 0
> 0 3 22-28 * 7
> 0 3 22,23,24,25,26,27,28 * 0
> 0 3 22,23,24,25,26,27,28 * 7

That's a question for the pg_cron maintainers but I'd say its simply
POSIX-compliant: POSIX specifies that day-of-month or day-of-week should
match if both are specified (i.e. not *):

"if either the month or day of month is specified as an element or list,
and the day of week is also specified as an element or list, then any
day matching either the month and day of month, or the day of week,
shall be matched" [1]

Example 3 in [1] also illustrates this.

And pg_cron implements[2] it like that if I'm not mistaken:

(schedule->flags & (DOM_STAR|DOW_STAR)) != 0
? (thisdom && thisdow) : (thisdom) || thisdow

This condition is false if day-of-month and day-of-week are specified:

(schedule->flags & (DOM_STAR|DOW_STAR)) != 0

so we end up with:

(thisdom) || thisdow

[1] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/crontab.html
[2] https://github.com/citusdata/pg_cron/blob/c9dedd3947d80566b6418c0fb2e30f10191d3dca/src/pg_cron.c#L989,L990

--
Erik

In response to

  • PG_CRON at 2024-03-25 15:48:27 from Geri Wright

Browse pgsql-admin by date

  From Date Subject
Next Message Clay Jackson (cjackson) 2024-03-25 19:06:12 RE: Ora2pg migration
Previous Message Geri Wright 2024-03-25 15:48:27 PG_CRON