Hologres V4.2 and later support cron jobs, which automatically execute SQL statements on a specified schedule. Typical use cases include periodic data imports, cleanups, and computations.
Overview
Hologres V4.2 introduces the Holo Cron feature. Use system functions such as hologres.hg_register_cron_job to run SQL statements on a cron expression or interval. Typical scenarios:
-
Scheduled data import: Periodically copy data from a source table to a target table.
-
Scheduled cleanup: Run
TRUNCATEorDELETEto remove expired data. -
Scheduled data computation: Periodically refresh summary tables, build indexes, or update materialized views.
Limits
-
A single task must contain either pure DDL or pure DML. Mixed DDL and DML is not supported.
-
DQL (query statements) is not supported.
-
The default maximum concurrency is 100. Tasks exceeding this limit may be delayed.
-
Each task occupies one connection on the corresponding warehouse during execution.
-
Only one task per job is scheduled at a time. If a task runs longer than the next scheduled trigger time, the next task is skipped.
-
Deleting a cron job does not interrupt running tasks, but no further tasks are scheduled.
Permissions
-
Regular users can register, manage, and view only their own cron jobs.
-
Superusers can register, manage, and view cron jobs of any user.
Command reference
Register a scheduled task: hologres.hg_register_cron_job
Register a new cron job with hologres.hg_register_cron_job. Syntax:
SELECT hologres.hg_register_cron_job(
job_name => '<job_name>',
command => '<command>',
[comment => '<comment>',]
[schedule => '<schedule>',]
[warehouse_id => '<warehouse_id>',]
[db_name => '<db_name>',]
[user_name => '<user_name>',]
[retry_count => '<retry_count>',]
[starts_time => '<starts_time>',]
[ends_time => '<ends_time>',]
[interval_text => '<interval_text>']
);
At least one of the schedule and interval_text parameters must be specified to declare the scheduling plan of the task.
Parameter details are listed in Parameters.
Modify a scheduled task: hologres.hg_alter_cron_job
Modify a registered cron job with hologres.hg_alter_cron_job. Syntax:
SELECT hologres.hg_alter_cron_job(
job_name => '<job_name>',
command => '<command>',
comment => '<comment>',
schedule => '<schedule>',
warehouse_id => '<warehouse_id>',
db_name => '<db_name>',
retry_count => '<retry_count>',
active => '<active>',
starts_time => '<starts_time>',
ends_time => '<ends_time>',
interval_text => '<interval_text>'
);
hologres.hg_alter_cron_job requires all parameters. Pass every field, including unchanged ones, or the call fails. To reset a field to its default, pass NULL.
The active parameter is unique to hologres.hg_alter_cron_job. Set it to true to enable the job, or false to pause scheduling while retaining the registration. Other parameters match those in Register a scheduled task.
Delete a scheduled task: hologres.hg_unregister_cron_job
Delete a cron job with hologres.hg_unregister_cron_job. Syntax:
SELECT hologres.hg_unregister_cron_job('<job_name>');
Deleting a job does not interrupt running tasks, but no further tasks are scheduled.
View scheduled tasks: hg_user_cron_jobs / hg_user_cron_tasks
Query registered cron jobs (not yet executed) with the hologres.hg_user_cron_jobs view:
SELECT * FROM hologres.hg_user_cron_jobs;
Query execution history and errors with the hologres.hg_user_cron_tasks view:
SELECT * FROM hologres.hg_user_cron_tasks;
Regular users see only their own jobs and tasks. Superusers see all users' jobs and tasks.
Parameters
The following table describes the parameters of hologres.hg_register_cron_job and hologres.hg_alter_cron_job. active is supported only by hologres.hg_alter_cron_job.
|
Parameter |
Type |
Required |
Description |
|
job_name |
text |
Yes |
The task name. Maximum 128 bytes. Only letters, digits, and underscores are allowed. Duplicate |
|
command |
text |
Yes |
The SQL command to execute. Wrap the command with |
|
comment |
text |
No |
The task description. The default value is |
|
schedule |
text |
No |
The cron expression. Invalid expressions return an |
|
warehouse_id |
int |
No |
The warehouse ID for executing |
|
db_name |
text |
No |
The database in which |
|
user_name |
text |
No |
The user that executes |
|
retry_count |
int |
No |
The maximum number of retries on failure. Valid values: 0 to 10. Default: |
|
active |
boolean |
Yes (required only for hg_alter_cron_job) |
Whether the job is enabled. |
|
starts_time |
text |
No |
The earliest time for task scheduling. Jobs scheduled before |
|
ends_time |
text |
No |
The latest time for task scheduling. Jobs scheduled after |
|
interval_text |
text |
No |
When |
Examples
Example 1: Run a data import every 5 minutes
Import data from table a to table b every 5 minutes. You can use either schedule or interval_text.
Method 1: Using schedule (cron expression)
SELECT hologres.hg_register_cron_job(
job_name => 'job_import_data',
command => 'INSERT INTO b SELECT * FROM a;',
schedule => '0 */5 * * * ?'
);
Method 2: Using interval_text
SELECT hologres.hg_register_cron_job(
job_name => 'job_import_data',
command => 'INSERT INTO b SELECT * FROM a;',
interval_text => '5 minutes'
);
Example 2: Run TRUNCATE every hour within a specified time range
During April 2026, run TRUNCATE on table tbl in the test_db database at the top of every hour, using resources on warehouse 1 and retrying up to 5 times on failure.
SELECT hologres.hg_register_cron_job(
job_name => 'job_truncate_tbl',
comment => 'Scheduled TRUNCATE',
schedule => '0 0 */1 * * ?',
command => $$TRUNCATE tbl$$,
warehouse_id => 1,
db_name => 'test_db',
retry_count => 5,
starts_time => '2026-04-01 00:00:00+08',
ends_time => '2026-04-30 23:59:59+08'
);
Cron expressions
The schedule parameter accepts a cron expression. Hologres uses a 7-field format (including seconds and year), unlike the standard 5-field Unix cron. The fields are:
Second Minute Hour Day-of-Month Month Day-of-Week Year (optional)
Hologres cron expressions follow the Java (Quartz) style, not the Unix 5-field format. The Quartz format adds Second and Year fields. When using an online cron generator, select Java (Quartz) to ensure compatibility.
Common examples:
|
Expression |
Description |
|
|
Runs every hour. |
|
|
Runs every day at 00:00. |
|
|
Runs every Monday at 00:00. |
|
|
Runs on the 1st day of each month at 00:00. |
|
|
Runs every 5 minutes. |
Use online tools to generate cron expressions. Select the Java (Quartz) format.
FAQ
How do I troubleshoot a scheduled task that fails to run?
-
Query the
hologres.hg_user_cron_tasksview for execution records and error details. -
Check whether the SQL statement has syntax errors.
-
Check whether the user specified by
user_namehas the required permissions.
What should I do if a scheduled task misses a scheduling cycle?
When concurrency resources are exhausted or a task overruns its next scheduled time, take the following steps:
-
Adjust the scheduling interval to prevent task pile-up.
-
Optimize SQL performance to reduce per-execution runtime.
-
Evaluate the concurrent task volume to stay within the default 100 concurrency limit.
How do I pause a scheduled task?
Set active to false in hologres.hg_alter_cron_job to pause a cron job. Set active to true to resume it.
hologres.hg_alter_cron_job requires all parameters. When pausing a task, pass every field (including unchanged ones), not just active.
SELECT hologres.hg_alter_cron_job(
job_name => 'job_import_data',
command => 'INSERT INTO b SELECT * FROM a;',
comment => 'Data import task',
schedule => '0 */5 * * * ?',
warehouse_id => -1,
db_name => 'mydb',
retry_count => 0,
active => false,
starts_time => NULL,
ends_time => NULL,
interval_text => NULL
);