cron_utils

Parse cron expressions and compute previous or next trigger times

Overview

PackageVersionCategoryLicenseLanguage
cron_utils0.1.0TIMEMITSQL
IDExtensionBinLibLoadCreateTrustRelocSchema
1140cron_utilsNoNoNoYesNoYes-
Relatedpg_cron pgcalendar pg_rrule pg_when pgagent pg_task pg_dbms_job pg_duration pg_bikram_sambat pg_dispatch

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

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY0.1.01817161514cron_utils-
RPMPIGSTY0.1.01817161514cron_utils_$v-
DEBPIGSTY0.1.01817161514postgresql-$v-cron-utils-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
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

Build

You can build the RPM / DEB packages for cron_utils using pig build:

pig build pkg cron_utils         # build RPM / DEB packages

Install

You can install cron_utils directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

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

Install the extension using pig or apt/yum/dnf:

pig install cron_utils;          # Install for current active PG version
pig ext install -y cron_utils -v 18  # PG 18
pig ext install -y cron_utils -v 17  # PG 17
pig ext install -y cron_utils -v 16  # PG 16
pig ext install -y cron_utils -v 15  # PG 15
pig ext install -y cron_utils -v 14  # PG 14
dnf install -y cron_utils_18       # PG 18
dnf install -y cron_utils_17       # PG 17
dnf install -y cron_utils_16       # PG 16
dnf install -y cron_utils_15       # PG 15
dnf install -y cron_utils_14       # PG 14
apt install -y postgresql-18-cron-utils   # PG 18
apt install -y postgresql-17-cron-utils   # PG 17
apt install -y postgresql-16-cron-utils   # PG 16
apt install -y postgresql-15-cron-utils   # PG 15
apt install -y postgresql-14-cron-utils   # PG 14

Create Extension:

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 Modified: 2026-07-30: extension update 2026-07-30 (7219c44)