DBAtlas · Database operations atlas

Create a scheduled job

Oracle

BEGIN
  DBMS_SCHEDULER.CREATE_JOB(
    job_name        => 'NIGHTLY_MAINT',
    job_type        => 'PLSQL_BLOCK',
    job_action      => 'BEGIN my_maintenance_proc; END;',
    start_date      => SYSTIMESTAMP,
    repeat_interval => 'FREQ=DAILY; BYHOUR=3',
    enabled         => TRUE);
END;
/

DBMS_SCHEDULER.CREATE_JOB defines a scheduled job; repeat_interval sets the recurrence with a calendaring expression.

PostgreSQL

SELECT cron.schedule('nightly-vacuum', '0 3 * * *', 'VACUUM ANALYZE');
-- Requires the pg_cron extension. Alternative: pgAgent.

The pg_cron extension defines jobs in standard cron syntax with cron.schedule; if the extension is not installed, use pgAgent or the operating system's cron.

MySQL

SET GLOBAL event_scheduler = ON;
CREATE EVENT nightly_cleanup
ON SCHEDULE EVERY 1 DAY STARTS '2026-01-01 03:00:00'
DO
  DELETE FROM logs WHERE created_at < NOW() - INTERVAL 30 DAY;

CREATE EVENT runs via the event scheduler; the event_scheduler global variable must be ON, otherwise events do not fire.

SQL Server

USE msdb;
EXEC dbo.sp_add_job @job_name = N'NightlyMaint';
EXEC dbo.sp_add_jobstep @job_name = N'NightlyMaint', @step_name = N'Step1',
     @subsystem = N'TSQL', @command = N'EXEC dbo.usp_Maintenance;';
EXEC dbo.sp_add_schedule @schedule_name = N'Daily3AM',
     @freq_type = 4, @freq_interval = 1, @active_start_time = 030000;
EXEC dbo.sp_attach_schedule @job_name = N'NightlyMaint', @schedule_name = N'Daily3AM';
EXEC dbo.sp_add_jobserver @job_name = N'NightlyMaint';

SQL Server Agent jobs are created with msdb procedures: the job, step and schedule are defined and attached to the server. The SQL Server Agent service must be running.

MongoDB

# Not applicable: MongoDB has no built-in scheduler. Use external cron/systemd timers, an application scheduler or a MongoDB Atlas Scheduled Trigger.

The Community edition has no scheduled jobs; an external scheduler or an Atlas Trigger is required.

Redis

# Not applicable: Redis has no built-in job scheduler. Use EXPIRE/keyspace notifications for key expiry and external cron for periodic tasks.

Redis does not run scheduled jobs; this is handled with TTL/keyspace notifications and external cron.

Elasticsearch

PUT _slm/policy/daily-snapshot
{
  "schedule": "0 30 1 * * ?",
  "name": "<snap-{now/d}>",
  "repository": "backup_repo",
  "config": { "indices": ["*"] },
  "retention": { "expire_after": "30d" }
}

SLM (Snapshot Lifecycle Management) takes scheduled snapshots; ILM is used for data lifecycle and Watcher for advanced automation.

Open in DBAtlas →