Platform schedule guide
PostgreSQL pg_cron Extension Guide
Schedule SQL jobs inside PostgreSQL with pg_cron: standard five-field cron, cron.schedule syntax, timezone via PostgreSQL settings, and safety practices.
Platform behavior reviewed against the official documentation on August 5, 2026.
- Format
- 5-field cron
- API
- cron.schedule(job_name, schedule, command)
- Storage
- cron.job table
- Default TZ
- UTC (server timezone affects interpretation)
Overview
pg_cron is a PostgreSQL extension that runs jobs on a cron schedule inside the database.
It uses standard five-field cron syntax passed to cron.schedule().
Schedules are stored in cron.job and executed by a background worker in UTC by default.
pg_cron schedule format
The schedule argument accepts the same five fields as Unix crontab.
Commands are SQL statements or CALL to procedures — not shell commands.
cron.schedule(
'job-name',
'0 9 * * 1-5',
$$SELECT refresh_materialized_views()$$
);| Field | Position | Values | Platform note |
|---|---|---|---|
| Minute | 1 | 0-59 | Standard cron. |
| Hour | 2 | 0-23 | Follows DB timezone settings. |
| Day of month | 3 | 1-31 | Standard. |
| Month | 4 | 1-12 | Standard. |
| Day of week | 5 | 0-7 | 0 and 7 = Sunday. |
Copyable schedule examples
Weekdays 9 AM
0 9 * * 1-5
SELECT cron.schedule('weekday-report', '0 9 * * 1-5', $$CALL generate_report()$$);Every 15 minutes
*/15 * * * *
Daily midnight
0 0 * * *
First of month 2 AM
0 2 1 * *
Enable and schedule
Install pg_cron and register jobs with cron.schedule.
CREATE EXTENSION pg_cron;
SELECT cron.schedule(
'nightly-vacuum',
'0 3 * * *',
$$VACUUM ANALYZE large_table$$
);Deployment checklist
- Enable pg_cron extension (requires superuser / rds admin).
- Validate cron string in CronWizard before cron.schedule.
- Use job names for observability and cron.unschedule when retiring jobs.
- Monitor cron.job_run_details for failures.
Database timezone
pg_cron evaluates schedules using the PostgreSQL timezone setting.
Set TimeZone explicitly and preview with CronWizard using the same IANA name.
SET TIME ZONE 'Europe/Istanbul';Limits and platform behavior
- SQL only
- Cannot run shell — use COPY or external workers for file IO.
- Single database
- Jobs belong to the database where pg_cron is installed.
- Long transactions
- Lengthy jobs block the cron worker — keep jobs short.
- Managed cloud variants
- RDS/Cloud SQL enablement steps differ by provider.
Production gotchas
Superuser extension
Not available on all managed tiers.
Duplicate schedules
cron.schedule without unschedule can duplicate jobs.
Lock contention
Heavy jobs during peak hours affect OLTP.
TimeZone mismatch
App ORM timezone may differ from pg_cron evaluation.
Frequently asked questions
Can pg_cron run shell scripts?
No. It executes SQL. Use external schedulers for shell.
How do I validate expressions?
Use CronWizard validator, then paste into cron.schedule.
Where are jobs stored?
In the cron.job catalog table.
How do I remove a job?
Use cron.unschedule(job_id) or unschedule by name where supported.