The Redshift scheduler lets you run SQL statements or stored procedures automatically at defined intervals.
Automated jobs refresh materialized views, load data, and purge old records without manual effort. They keep analytics current and reduce operational toil.
Redshift provides built-in Scheduler objects: SCHEDULE and JOB. A SCHEDULE defines timing (CRON or rate), while a JOB binds SQL or a stored procedure to that schedule.
1) CREATE SCHEDULE with a cron expression. 2) CREATE JOB referencing the schedule and containing the SQL. 3) Monitor with system views like svl_scheduled_jobs.
Only superusers or users granted the pg_scheduler
role can create, alter, or drop schedules and jobs.
Define a human-readable name and CRON string. Example: run nightly at 02:00 UTC.
CREATE SCHEDULE nightly_2am
ON CRON '0 2 * * *';
Create a job that references the schedule and executes either inline SQL or a stored procedure.
CREATE JOB refresh_daily_sales
ON SCHEDULE nightly_2am
DO $$
REFRESH MATERIALIZED VIEW daily_sales;
$$ LANGUAGE SQL;
Query information_schema.scheduled_job_run_times
to list the next run time and history.
Use ALTER JOB ... DISABLE
to pause without losing definition, or DROP JOB
to remove permanently.
Group related load, transform, and refresh steps under one schedule to minimize queue contention. Use descriptive names like orders_hourly_load
.
Wrong timezone: CRON is interpreted in UTC. Convert local time before defining schedules.
Long-running SQL: If job execution exceeds frequency, overlaps occur. Add LIMIT clauses or optimize queries.
Alert on failed runs by querying svl_scheduled_job_log
for status <> 'SUCCEEDED'. Integrate with CloudWatch for notifications.
Yes. Wrap the CALL statement inside the job’s DO block or reference it directly: DO $$ CALL load_daily_orders(); $$ LANGUAGE plpgsql;
.
Use ALTER SCHEDULE
to modify the CRON or RATE expression, then the change applies to all linked jobs.
History is available in svl_scheduled_job_log
and svl_scheduled_job_step_log
system views, including start time, end time, and status.