Versions:

alter_job()
Community

Actions scheduled via TimescaleDB's automation framework run periodically in a background worker. You can change the schedule of their execution using alter_job. To alter an existing job, you must refer to it by job_id. The job_id which executes a given action and its current schedule can be found either in the timescaledb_information.jobs view, which lists information about every scheduled action, as well as in timescaledb_information.job_stats. The job_stats view additionally contains information about when each job was last run and other useful statistics for deciding what the new schedule should be.

Required Arguments

NameTypeDescription
job_idINTEGERthe id of the policy job being modified

Optional Arguments

NameTypeDescription
schedule_intervalINTERVALThe interval at which the job runs
max_runtimeINTERVALThe maximum amount of time the job will be allowed to run by the background worker scheduler before it is stopped
max_retriesINTEGERThe number of times the job will be retried should it fail
retry_periodINTERVALThe amount of time the scheduler will wait between retries of the job on failure
scheduledBOOLEANSet to FALSE to exclude this job from being run as background job.
configJSONBJob-specific configuration (this will be passed to the function when executed)
next_startTIMESTAMPTZThe next time at which to run the job. The job can be paused by setting this value to 'infinity' (and restarted with a value of now()).
if_existsBOOLEANSet to true to avoid throwing an error if the job does not exist, a notice will be issued instead. Defaults to false.

Returns

ColumnTypeDescription
job_idINTEGERthe id of the job being modified
schedule_intervalINTERVALThe interval at which the job runs
max_runtimeINTERVALThe maximum amount of time the job will be allowed to run by the background worker scheduler before it is stopped
max_retriesINTEGERThe number of times the job will be retried should it fail
retry_periodINTERVALThe amount of time the scheduler will wait between retries of the job on failure
scheduledBOOLEANTrue if this job will be executed by the TimescaleDB scheduler.
configJSONBJob-specific configuration (this will be passed to the function when executed)
next_startTIMESTAMPTZThe next time at which to run the job.

Sample Usage

SELECT alter_job(1000, schedule_interval => INTERVAL '2 days');

Reschedules the job with id 1000 so that it runs every two days.

SELECT alter_job(job_id, scheduled => false)
FROM timescaledb_information.jobs
WHERE proc_name = 'policy_compression' AND hypertable_name = 'conditions'

Disables scheduling of the compression policy on hypertable conditions.

SELECT alter_job(1015, next_start => '2020-03-15 09:00:00.0+00');

Reschedules continuous aggregate job 1015 so that the next execution of the job starts at the specified time (9:00:00 am on March 15, 2020).

Found an issue on this page?

Report an issue!

Related Content