Cron expressions

更新时间:
复制 MD 格式

AnalyticDB for PostgreSQL uses cron expressions to schedule periodic plans. A cron expression is a space-separated string of six or seven fields:

second minute hour day month week [year]

The Year field is optional. Each field accepts specific values or wildcard characters. When a field contains multiple values, separate them with commas (,).

Field values

FieldRequiredValid valuesSupported wildcards
SecondYes0–59* , - /
MinuteYes0–59* , - /
HourYes0–23* , - /
DayYes1–31* , - / ? L W
MonthYes1–12 or JAN–DEC* , - /
WeekYes1–7 or MON–SUN (1 = Monday, 7 = Sunday)* , - / ? L #
YearNo1970–2099* , - /

Wildcards

WildcardDescriptionExampleWhen triggered
*Matches all values in the field.* in MonthEvery month
,Specifies multiple discrete values.5,20 in MinuteAt minutes 5 and 20 of each hour
-Specifies a range of values.5-20 in MinuteOnce every minute from minute 5 through minute 20
/Specifies an increment. The value before / is the start; the value after is the step.0/15 in MinuteEvery 15 minutes starting from minute 0 (at :00, :15, :30, :45)
3/20 in MinuteEvery 20 minutes starting from minute 3
?No value. Only supported in the Day and Week fields. When you set a specific value in one of these fields, set the other to ? to avoid conflicts.? in Week when Day is 15Matches any day of the week
LThe last day. Only supported in the Day and Week fields. Do not combine L with a list or range.L in DayThe last day of the month
L in WeekSunday (the last day of the week)
6L in WeekThe last Saturday of the month
WThe nearest business day to the specified date, within the same month. Only supported in the Day field. LW matches the last business day of the month.5W in DayIf the 5th is Saturday: Friday (4th). If Sunday: Monday (6th). If Mon–Fri: the 5th.
#A specific weekday occurrence in the month. Only supported in the Week field.4#2 in WeekThe second Thursday of the month

Examples

Important

Cron expressions use UTC. Convert your local time to UTC before writing an expression.

ScenarioUTC expressionUTC+8 expression
At 10:15 every day0 15 10 ? * *0 15 18 ? * *
At 10:15 every day0 15 10 * * ?0 15 18 * * ?
At 12:00 every day0 0 12 * * ?0 0 20 * * ?
At 10:00, 14:00, and 16:00 every day0 0 10,14,16 * * ?0 0 18,22,0 * * ?
Every 30 minutes from 09:00 to 17:00 every day0 0/30 9-17 * * ?0 0/30 17-2 * * ?
Every minute from 14:00 to 14:59 every day0 * 14 * * ?0 * 22 * * ?
Every minute from 14:00 to 14:05 every day0 0-5 14 * * ?0 0-5 22 * * ?
Every 5 minutes from 14:00 to 14:55 every day0 0/5 14 * * ?0 0/5 22 * * ?
Every 5 minutes from 14:00 to 14:55 and 18:00 to 18:55 every day0 0/5 14,18 * * ?0 0/5 22,3 * * ?
At 12:00 every Wednesday0 0 12 ? * WED0 0 20 ? * WED
At 10:15 on the 15th of every month0 15 10 15 * ?0 15 18 15 * ?
At 10:15 on the last day of every month0 15 10 L * ?0 15 18 L * ?
At 10:15 on the last Saturday of every month0 15 10 ? * 6L0 15 18 ? * 6L
At 10:15 on the third Saturday of every month0 15 10 ? * 6#30 15 18 ? * 6#3
At 14:10 and 14:44 every Wednesday in March0 10,44 14 ? 3 WED0 10,44 22 ? 3 WED
At 10:15 every day in 20220 15 10 ? * * 20220 15 18 ? * * 2022
At 10:15 every day, every year0 15 10 ? * * *0 15 18 ? * * *
Every 5 minutes from 14:00 to 14:55 and 18:00 to 18:55 every day in 20220 0/5 14,18 * * ? 20220 0/5 22,3 * * ? 2022
At 10:15 on the third Saturday of every month in 2022 and 20230 15 10 ? * 6#3 2022,20230 15 18 ? * 6#3 2022,2023
Every 30 minutes from 09:00 to 17:30 every day from 2022 to 20250 0/30 9-17 * * ? 2022-20250 0/30 17-2 * * ? 2022-2025
At 14:10 and 14:44 every Wednesday in March, every two years starting from 20220 10,44 14 ? 3 WED 2022/20 10,44 22 ? 3 WED 2022/2