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
| Field | Required | Valid values | Supported wildcards |
|---|---|---|---|
| Second | Yes | 0–59 | * , - / |
| Minute | Yes | 0–59 | * , - / |
| Hour | Yes | 0–23 | * , - / |
| Day | Yes | 1–31 | * , - / ? L W |
| Month | Yes | 1–12 or JAN–DEC | * , - / |
| Week | Yes | 1–7 or MON–SUN (1 = Monday, 7 = Sunday) | * , - / ? L # |
| Year | No | 1970–2099 | * , - / |
Wildcards
| Wildcard | Description | Example | When triggered |
|---|---|---|---|
* | Matches all values in the field. | * in Month | Every month |
, | Specifies multiple discrete values. | 5,20 in Minute | At minutes 5 and 20 of each hour |
- | Specifies a range of values. | 5-20 in Minute | Once 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 Minute | Every 15 minutes starting from minute 0 (at :00, :15, :30, :45) |
3/20 in Minute | Every 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 15 | Matches any day of the week |
L | The last day. Only supported in the Day and Week fields. Do not combine L with a list or range. | L in Day | The last day of the month |
L in Week | Sunday (the last day of the week) | ||
6L in Week | The last Saturday of the month | ||
W | The 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 Day | If 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 Week | The second Thursday of the month |
Examples
Important
Cron expressions use UTC. Convert your local time to UTC before writing an expression.
| Scenario | UTC expression | UTC+8 expression |
|---|---|---|
| At 10:15 every day | 0 15 10 ? * * | 0 15 18 ? * * |
| At 10:15 every day | 0 15 10 * * ? | 0 15 18 * * ? |
| At 12:00 every day | 0 0 12 * * ? | 0 0 20 * * ? |
| At 10:00, 14:00, and 16:00 every day | 0 0 10,14,16 * * ? | 0 0 18,22,0 * * ? |
| Every 30 minutes from 09:00 to 17:00 every day | 0 0/30 9-17 * * ? | 0 0/30 17-2 * * ? |
| Every minute from 14:00 to 14:59 every day | 0 * 14 * * ? | 0 * 22 * * ? |
| Every minute from 14:00 to 14:05 every day | 0 0-5 14 * * ? | 0 0-5 22 * * ? |
| Every 5 minutes from 14:00 to 14:55 every day | 0 0/5 14 * * ? | 0 0/5 22 * * ? |
| Every 5 minutes from 14:00 to 14:55 and 18:00 to 18:55 every day | 0 0/5 14,18 * * ? | 0 0/5 22,3 * * ? |
| At 12:00 every Wednesday | 0 0 12 ? * WED | 0 0 20 ? * WED |
| At 10:15 on the 15th of every month | 0 15 10 15 * ? | 0 15 18 15 * ? |
| At 10:15 on the last day of every month | 0 15 10 L * ? | 0 15 18 L * ? |
| At 10:15 on the last Saturday of every month | 0 15 10 ? * 6L | 0 15 18 ? * 6L |
| At 10:15 on the third Saturday of every month | 0 15 10 ? * 6#3 | 0 15 18 ? * 6#3 |
| At 14:10 and 14:44 every Wednesday in March | 0 10,44 14 ? 3 WED | 0 10,44 22 ? 3 WED |
| At 10:15 every day in 2022 | 0 15 10 ? * * 2022 | 0 15 18 ? * * 2022 |
| At 10:15 every day, every year | 0 15 10 ? * * * | 0 15 18 ? * * * |
| Every 5 minutes from 14:00 to 14:55 and 18:00 to 18:55 every day in 2022 | 0 0/5 14,18 * * ? 2022 | 0 0/5 22,3 * * ? 2022 |
| At 10:15 on the third Saturday of every month in 2022 and 2023 | 0 15 10 ? * 6#3 2022,2023 | 0 15 18 ? * 6#3 2022,2023 |
| Every 30 minutes from 09:00 to 17:30 every day from 2022 to 2025 | 0 0/30 9-17 * * ? 2022-2025 | 0 0/30 17-2 * * ? 2022-2025 |
| At 14:10 and 14:44 every Wednesday in March, every two years starting from 2022 | 0 10,44 14 ? 3 WED 2022/2 | 0 10,44 22 ? 3 WED 2022/2 |
该文章对您有帮助吗?