whatisgithub

What is pg_cron?

citusdata/pg_cron — explained in plain English

Analysis updated 2026-06-26

3,781CAudience · ops devopsComplexity · 3/5Setup · moderate

In one sentence

A PostgreSQL extension that lets you schedule SQL commands to run automatically on a timer, like a built-in cron job that lives entirely inside your database.

Mindmap

mindmap
  root((pg_cron))
    What it does
      Schedule SQL jobs
      Inside PostgreSQL
      No external cron
    Scheduling
      5-field cron syntax
      Sub-minute intervals
      Last day of month
    Job management
      Create with SQL
      Pause and resume
      Per-user isolation
    Supported platforms
      Red Hat and Debian
      Amazon RDS
      Supabase
      Azure PostgreSQL
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Schedule a nightly DELETE to purge old rows from a logging table without setting up an external cron job or script.

USE CASE 2

Run a VACUUM or ANALYZE on a specific table every Sunday at midnight to keep database performance healthy.

USE CASE 3

Fire a stored procedure every 30 seconds for near-real-time background processing without leaving the database.

USE CASE 4

Set up end-of-month reporting jobs using the last-day-of-month shorthand so the schedule always lands on the right date.

What is it built with?

CPostgreSQLSQL

How does it compare?

citusdata/pg_cronptitseb/box86jordansissel/xdotool
Stars3,7813,7713,792
LanguageCCC
Setup difficultymoderatehardeasy
Complexity3/54/52/5
Audienceops devopsdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · moderate Time to first run · 30min

Requires adding pg_cron to shared_preload_libraries in postgresql.conf and restarting the server, not needed on managed providers like RDS or Supabase where it is pre-installed.

Open-source, check the repository for the exact license terms.

So what is it?

pg_cron is a PostgreSQL extension that lets you schedule SQL commands to run automatically on a timer, similar to how a system cron job works on a Unix server. The difference is that everything runs inside your database rather than on the operating system. You install it once, add it to PostgreSQL's startup configuration, and then create scheduled jobs using ordinary SQL function calls. Schedules use the familiar five-field cron syntax: minute, hour, day of month, month, and day of week. You can also write shorthand like "30 seconds" or "5 seconds" to run a job on a sub-minute interval. A special dollar sign character represents the last day of the month, which is useful for end-of-month processing tasks. The project links to crontab.guru, a web tool that helps you construct and verify cron expressions. Creating a job is a single SQL call. You pass a schedule string and any SQL command, from a simple DELETE or VACUUM to a stored procedure call. Jobs get a numeric ID and an optional name. You can remove a job by name or ID using cron.unschedule, change its schedule or command later using cron.alter_job, or pause it by setting it to inactive. A row-level security policy on the jobs table means each database user only sees and controls their own jobs unless they are a superuser. Jobs are stored in a table called cron.job. A background worker process wakes up periodically, reads the table, and fires any jobs whose schedule matches the current time. Multiple jobs can run at the same time, but each specific job runs only one instance at a time, if a second trigger arrives before the first finishes, it waits in a queue. The extension is available as a packaged install on Red Hat, Debian, and Ubuntu systems. It is also supported directly by several managed database providers including Amazon RDS, Azure Database for PostgreSQL, Supabase, and Crunchy Bridge.

Copy-paste prompts

Prompt 1
Show me how to install pg_cron on my PostgreSQL instance and schedule a nightly job that deletes rows older than 30 days from my events table.
Prompt 2
How do I create a pg_cron job that runs every 5 minutes and calls a stored procedure, then check its run history?
Prompt 3
Walk me through pausing a pg_cron job temporarily and then re-enabling it without deleting and recreating it.
Prompt 4
How do I set up pg_cron on Amazon RDS for PostgreSQL, what configuration steps are specific to managed databases?
Prompt 5
Help me schedule an end-of-month summary job in pg_cron using the last-day-of-month shorthand.

Frequently asked questions

What is pg_cron?

A PostgreSQL extension that lets you schedule SQL commands to run automatically on a timer, like a built-in cron job that lives entirely inside your database.

What language is pg_cron written in?

Mainly C. The stack also includes C, PostgreSQL, SQL.

What license does pg_cron use?

Open-source, check the repository for the exact license terms.

How hard is pg_cron to set up?

Setup difficulty is rated moderate, with roughly 30min to a first successful run.

Who is pg_cron for?

Mainly ops devops.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.