Jobs, queues and partitionsversion 1.6preloaded
pg_cron
Run SQL on a schedule written in cron syntax.
What it is for
pg_cron runs SQL statements on a cron schedule from inside the database: nightly cleanups, rollups, refreshing materialized views, or calling pg_net to hit an endpoint. Every run is recorded in cron.job_run_details.
Enable it
create extension if not exists pg_cron;Its library is preloaded when the database starts (shared_preload_libraries), so CREATE EXTENSION is all you need.
Example
select cron.schedule(
'purge-expired-sessions',
'0 3 * * *', -- every day at 03:00 UTC
$$delete from sessions where expires_at < now()$$
);
select jobid, status, start_time from cron.job_run_details
order by start_time desc limit 10;
select cron.unschedule('purge-expired-sessions');Questions
How do I enable pg_cron?
Run create extension if not exists pg_cron; in the SQL editor, or switch it on from the Extensions page in the console. You do not need superuser access.
Which version of pg_cron is installed?
1.6, on Postgres 17.6, as read from the running engine on 2026-10-08. Check yours with: select extversion from pg_extension where extname = 'pg_cron';
Upstream project: github.com/citusdata/pg_cron
More jobs, queues and partitions extensions
- pgmq Message queues in SQL: send, read with a visibility timeout, archive.
- pg_partman Create and drop time or number partitions for you.