Skip to content

Cronjob

Schedule SQL queries to run on a cron expression β€” but only while the DuckDB process is alive.

52,957
extension loads Β· last 90 days
On this page

Technical Overview

A scheduler that lives inside the process

How it works

  • β€’ A background thread on a tick loop: One thread owned by the extension wakes periodically, evaluates which registered jobs are due, executes each due query, and writes the outcome (status, last run time, last result or error message) back into the job table. The introspection table surfaces all of that so you can monitor schedules from SQL like any other relation.
  • β€’ Six-field cron expressions: Schedules use the six-field form second minute hour day-of-month month day-of-week β€” one more field than POSIX, giving second-level resolution. The standard *, ?, ,, -, / operators and MON–SUN weekday names all work. crontab.guru is handy for sanity-checking, but note it parses the five-field POSIX form, so the leading seconds field here is an extension.
  • β€’ Same connection, same access: A scheduled query runs against the database the scheduler was registered from, inheriting that session's access rights, attached databases, and secrets. Anything you can run interactively, you can schedule β€” including CREATE OR REPLACE TABLE, COPY ... TO, ANALYZE, or a webhook-firing query. One caveat: register against an in-memory database and the schedule disappears when that database does, even before process exit.
  • β€’ Sequential per job: Each registered job is single-threaded against itself: if a tick's query runs longer than the schedule interval, the next tick for that job waits its turn. There is no overlap and no parallel re-entry of the same registration.

Production caveats

  • β€’ Schedules die with the process: This is the central caveat. A kill -9, a deploy, an OOM, or a clean shutdown all wipe the in-memory registry β€” there is no WAL entry, no on-disk table, and no resume. If the work must happen on a wall-clock cadence regardless of process state, drive the run from an external orchestrator (system cron(8), systemd timers, Kubernetes CronJob) and have that invoke DuckDB.
  • β€’ No multi-process coordination: Two DuckDB processes that both load Cronjob and register the same job will both run it. There is no leader election and no lease β€” pick one process to own the schedule, or de-duplicate downstream.
  • β€’ Errors are recorded, not retried: A failed query writes its error message into the job's last-result column. The extension does not retry, back off, or alert β€” wrap the scheduled query in its own error-reporting logic (write to an audit table, fire a webhook) if you need notification.
  • β€’ Long-running queries block the next tick: Because each job is sequential against itself, a query that overruns its interval delays its own next run. Schedule with headroom, or split heavy work so no single run can starve the cadence.
  • β€’ Experimental status: Marked experimental upstream. The function surface is small and stable in spirit, but pin a known-good extension version in production until it's promoted.

Deep Dive

Technical Details

Install

INSTALL cronjob FROM community;
LOAD cronjob;

Quick Start

Run a query every 15 seconds during hours 1–4

SELECT cron('SELECT now()', '*/15 * 1-4 * * *');

Inspect scheduled jobs

SELECT * FROM cron_jobs();

Cancel a job by its job_id

SELECT cron_delete('task_0');

Reference

Extension Contents

Quick reference to all available functions and settings organized by category.

Name Description
Scheduling
cron() Register a SQL query to run on a six-field cron expression (second minute hour day-of-month month day-of-week).
cron_delete() Cancel a scheduled job by job_id (the value returned from cron or visible in cron_jobs).
cron_jobs() Table function listing every scheduled job in this process β€” job_id, query, schedule, next_run, status, last_run, and last_result.

API Reference

Function Documentation

Practical Examples

Cookbook

Real-world recipes and patterns for common use cases.

Platform Support

Compatibility

Extension availability may vary by platform and DuckDB version. Check below to ensure this extension supports your environment before installation.

Quick Facts

Release status Experimental
Software License MIT
Pricing Free
Written In C++
Source Available Yes
View on GitHub
Usage
52,957
loads Β· last 90 days

Platforms

  • Linux x86_64 aarch64
  • Linux (musl) Not available
  • macOS Intel Apple Silicon
  • Windows x86_64
  • WASM eh mvp threads
Compiled binary sizes
Platform Architecture Size
Linux x86_64 10.59 MB
Linux aarch64 9.34 MB
macOS Intel 8.17 MB
macOS Apple Silicon 7.19 MB
Windows x86_64 7.39 MB
WASM eh 27.3 KB
WASM mvp 23.5 KB
WASM threads 27.5 KB

Compressed download size from the Haybarn extension repository.

DuckDB & Haybarn

Release calendar