Skip to content
cron_utils

cron_utils

cron_utils : Parse cron expressions and compute previous or next trigger times

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
1140
cron_utils
cron_utils
0.1.0
TIME
MIT
SQL
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
----d-r
No
No
No
Yes
yes
no
Relationships
See Also
pg_cron
pg_when
pgcalendar
periods

The PGXN 0.1.0 distribution is marked unstable; the control file marks the extension relocatable.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PIGSTY
0.1.0
18
17
16
15
14
cron_utils-
RPM
PIGSTY
0.1.0
18
17
16
15
14
cron_utils_$v-
DEB
PIGSTY
0.1.0
18
17
16
15
14
postgresql-$v-cron-utils-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
el8.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
el9.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
el9.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
el10.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
el10.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
d12.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
d12.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
d13.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
d13.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u22.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u22.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u24.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u24.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u26.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u26.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PackageVersionOSORGSIZEFile URL
cron_utils_180.1.0el8.x86_64pigsty11.6 KiBcron_utils_18-0.1.0-1PIGSTY.el8.noarch.rpm
cron_utils_180.1.0el8.aarch64pigsty11.5 KiBcron_utils_18-0.1.0-1PIGSTY.el8.noarch.rpm
cron_utils_180.1.0el9.x86_64pigsty11.5 KiBcron_utils_18-0.1.0-1PIGSTY.el9.noarch.rpm
cron_utils_180.1.0el9.aarch64pigsty11.5 KiBcron_utils_18-0.1.0-1PIGSTY.el9.noarch.rpm
cron_utils_180.1.0el10.x86_64pigsty11.6 KiBcron_utils_18-0.1.0-1PIGSTY.el10.noarch.rpm
cron_utils_180.1.0el10.aarch64pigsty11.6 KiBcron_utils_18-0.1.0-1PIGSTY.el10.noarch.rpm
postgresql-18-cron-utils0.1.0d12.x86_64pigsty5.5 KiBpostgresql-18-cron-utils_0.1.0-1PIGSTY~bookworm_all.deb
postgresql-18-cron-utils0.1.0d12.aarch64pigsty5.5 KiBpostgresql-18-cron-utils_0.1.0-1PIGSTY~bookworm_all.deb
postgresql-18-cron-utils0.1.0d13.x86_64pigsty5.5 KiBpostgresql-18-cron-utils_0.1.0-1PIGSTY~trixie_all.deb
postgresql-18-cron-utils0.1.0d13.aarch64pigsty5.5 KiBpostgresql-18-cron-utils_0.1.0-1PIGSTY~trixie_all.deb
postgresql-18-cron-utils0.1.0u22.x86_64pigsty5.5 KiBpostgresql-18-cron-utils_0.1.0-1PIGSTY~jammy_all.deb
postgresql-18-cron-utils0.1.0u22.aarch64pigsty5.5 KiBpostgresql-18-cron-utils_0.1.0-1PIGSTY~jammy_all.deb
postgresql-18-cron-utils0.1.0u24.x86_64pigsty5.5 KiBpostgresql-18-cron-utils_0.1.0-1PIGSTY~noble_all.deb
postgresql-18-cron-utils0.1.0u24.aarch64pigsty5.5 KiBpostgresql-18-cron-utils_0.1.0-1PIGSTY~noble_all.deb
postgresql-18-cron-utils0.1.0u26.x86_64pigsty5.5 KiBpostgresql-18-cron-utils_0.1.0-1PIGSTY~resolute_all.deb
postgresql-18-cron-utils0.1.0u26.aarch64pigsty5.5 KiBpostgresql-18-cron-utils_0.1.0-1PIGSTY~resolute_all.deb

Source

pig build pkg cron_utils;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install cron_utils;		# install via package name, for the active PG version

pig install cron_utils -v 18;   # install for PG 18
pig install cron_utils -v 17;   # install for PG 17
pig install cron_utils -v 16;   # install for PG 16
pig install cron_utils -v 15;   # install for PG 15
pig install cron_utils -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION cron_utils;

Usage

Sources:

cron_utils parses five-field cron expressions and calculates trigger timestamps inside PostgreSQL. It is a scheduling utility, not a job runner: use it to preview, validate, or query a schedule, and use a scheduler such as pg_cron separately to execute work.

Core Workflow

CREATE EXTENSION cron_utils;

-- First trigger at or after the supplied time.
SELECT cron_first_trigger('0 9 * * 1-5', now());

-- Last trigger before the supplied time (strict is true by default).
SELECT cron_last_trigger('0 9 * * 1-5', now());

-- Next five hourly triggers.
SELECT *
FROM cron_iterate_n('0 * * * *', now(), false, 'next', 5);

To inspect a bounded window:

SELECT *
FROM cron_first_last_triggers(
  '0 0 * * *',
  date_trunc('month', now()),
  date_trunc('month', now()) + interval '1 month'
);

Either returned boundary can be NULL when the expression has no trigger in the window.

Important Objects

  • cron_parts is the parsed representation of the minute, hour, day, month, and day-of-week fields.
  • parse_cron(text) parses *, lists, ranges, and step syntax.
  • cron_first_trigger(expr, base_time, strict) searches forward. With strict = true, a trigger exactly at base_time is skipped.
  • cron_last_trigger(expr, base_time, strict) searches backward and defaults to strict matching.
  • cron_first_last_triggers(expr, start_time, end_time) returns the first and last matches in a window.
  • cron_iterate_n(expr, base_time, strict, direction, max_matches) returns consecutive matches in the next or prev direction.

Semantics and Caveats

Expressions use the standard five fields minute hour day month dow; seconds are not accepted. Day-of-week uses 1 = Monday through 7 = Sunday. Results are timestamptz, so session time zone affects the displayed local time and daylight-saving transitions should be tested for local-time schedules.

The extension is pure SQL/PL/pgSQL, relocatable, and has no pg_cron dependency. Its functions are declared immutable and parallel-safe. Version 0.1.0 is marked unstable in the control metadata, so pin behavior and retest edge cases before embedding it in a critical scheduler.

Last updated on