Schedule materialized view refreshes#

Starburst control plane can refresh an Iceberg materialized view on a schedule. You set the schedule in SQL, in the same way as a traditional SEP cluster. See Automatic refresh. Control plane runs the refresh as a background query, and it uses your routing rules to pick the cluster group that runs it.

Requirements#

Scheduled refreshes need the following:

  • Control plane in managed mode with Starburst access control.

  • The smart load balancing statement queue turned on. See Smart load balancing.

  • Background work turned on in the config.properties file of control plane:

    control-plane.enabled=true
    statement-queue.enabled=true
    background-work.enabled=true
    

    Control plane does not start if background-work.enabled is true and statement-queue.enabled is false.

  • Clusters that run in managed mode, with deployment.mode=MANAGED. Do not set starburst.jobs.enabled on these clusters. The job scheduler of a cluster cannot run in managed mode, and the cluster does not start if the property is set. See Connect a cluster to control plane.

  • An Iceberg catalog.

Create and manage a schedule#

Set the refresh_schedule and refresh_schedule_timezone properties on the materialized view. A view can have only one schedule.

To create a view with a schedule that runs every day at 02:30 New York time:

CREATE MATERIALIZED VIEW iceberg.sales.daily_totals
WITH (
  refresh_schedule = '30 2 * * *',
  refresh_schedule_timezone = 'America/New_York'
)
AS
SELECT ...;

To change or remove the schedule, set the properties on the existing view:

-- Change the schedule
ALTER MATERIALIZED VIEW iceberg.sales.daily_totals
SET PROPERTIES refresh_schedule = '0 * * * *';

-- Use the default time zone of control plane
ALTER MATERIALIZED VIEW iceberg.sales.daily_totals
SET PROPERTIES refresh_schedule_timezone = DEFAULT;

-- Remove the schedule
ALTER MATERIALIZED VIEW iceberg.sales.daily_totals
SET PROPERTIES refresh_schedule = DEFAULT;

A schedule that has no time zone uses the value of background-work.default-timezone, which is UTC by default.

The refresh runs with the role that created the view with the refresh_schedule property. This role must have the privileges to refresh the view. If it does not, the refresh fails.

To turn off scheduled refreshes for a catalog, set iceberg.scheduled-materialized-view-refresh-enabled=false in the catalog. The default is true. When it is false, the refresh_schedule properties do not exist in that catalog.

Choose the cluster group for refreshes#

Control plane routes a scheduled refresh with your routing rules. The refresh has the source scheduled-mv-refresh and client tags. A rule can match the source with system.request.source, and a client tag with system.request.clientTag. If no rule matches, the refresh goes to the default cluster group. See How routing works and Create routing rules.

To send every scheduled refresh to one cluster group, set background-work.materialized-view-refresh.routing-group.explicit-override to the name of the group. Control plane then skips the routing rules for refreshes. If you do not set the property, the routing rules decide.

If the refreshes are large, give them their own cluster group, so that they do not compete with the queries of your users.

Configuration properties#

Set the following properties in the config.properties file of control plane. All of them are optional. To turn on scheduled refreshes, set background-work.enabled=true.

Property

Description

Default

background-work.default-timezone

The time zone for schedules that do not set one. Use a Java ZoneId, such as America/New_York, or system-default.

UTC

background-work.materialized-view-refresh.routing-group.explicit-override

The cluster group that runs every scheduled refresh. Control plane sends the refreshes to this group before it evaluates the routing rules. If you do not set it, the routing rules decide.

Not set

background-work.history-retention

How long control plane keeps the refresh history.

90d

background-work.history-retention.max-entries-per-work

The maximum number of history entries that control plane keeps for each materialized view.

1000

background-work.max-concurrent-work-per-account

The maximum number of background jobs that run at the same time on one control plane instance. Control plane has a single account.

30