Monitor materialized views

You can monitormaterialized viewby using tools that include information schema and log monitoring.

To create a list of materialized views, seeList materialized views.

Materialized view information schema view

To discover materialized views, query theINFORMATION_SCHEMA.TABLESview. To retrieve the properties of amaterialized view, query theINFORMATION_SCHEMA.TABLE_OPTIONS view.

Materialized views are not listed in theINFORMATION_SCHEMA.VIEWS viewstable.

Monitor automatic refresh

This section describes how to viewrefresh details for materialized views.

View last refresh status

To retrieve the current status of materialized views, call thetables.get method, or query theINFORMATION_SCHEMA.MATERIALIZED_VIEWS view.

For example:

SELECTtable_name,last_refresh_time,refresh_watermark,last_refresh_statusFROM`DATASET`.INFORMATION_SCHEMA.MATERIALIZED_VIEWS;

If the value forlast_refresh_status is notNULL, the last automaticrefresh job failed. Manual refresh requests are not reflected here. Changes tobase tables can invalidate a materialized view definition, resulting in an errorduring automatic refresh. For more information, seeIncrementalupdates. Forexample, if a column that is referenced by the materialized view gets droppedfrom the base table, thelast_refresh_status field returns aninvalidQuery error. For more information, seeErrormessages.

List automatic refresh jobs

To list materialized view automatic refresh jobs, call thejobs.listmethod. To retrieve details aboutthe jobs, call thejobs.getmethod. You can also query theINFORMATION_SCHEMA.JOBS_BY_* views toretrieve job details. Automatic refresh jobs contain thematerialized_view_refreshprefix within thejob ID andare started by a BigQuery administrator account.

For example:

SELECTjob_id,total_slot_ms,total_bytes_processed,materialized_view_statistics.materialized_view[SAFE_OFFSET(0)].rejected_reasonASfull_refresh_reasonFROM`region-us.INFORMATION_SCHEMA.JOBS_BY_PROJECT`WHEREjob_idLIKE'%materialized_view_refresh_%'LIMIT10;

To monitor the cost of refresh jobs and adjust the automatic refresh interval ifneeded, view thetotal_bytes_processed andtotal_slot_ms fields.

For example, if the ingestion rate in the base tables is relatively small, itmakes sense to refresh the view less often. If the underlying datachanges quickly, it makes sense to refresh more often.

If the base tables ingest data at predefined points in time, such as by using anightly extract, transform, and load (ETL) pipeline, consider taking control ofthe materialized view maintenance schedule as follows:

  1. Disable automatic refresh.

  2. Perform a manual refresh,either as part of the ETL pipeline, or by configuring a scheduled query atspecific times of the day.

Table truncation, partition truncation, partitionexpiration, andUPDATE,DELETE, andMERGE data manipulation language (DML)statements on a base table can all invalidate their materialized views. If thematerialized view is partitioned, the modified partitions are invalidated;otherwise, the entire materialized view is invalidated. Therefore, you might want to batch your DML statements and perform the manualrefresh at the end of your query.

For more information on pricing for materialized views, seematerialized viewspricing.

Monitor failed materialized views refresh

You can create automation to monitor failed materialized view refreshes andsend alerts usingBigQuery audit logs inCloud Logging.BigQuery creates log entries for materialized views refresh jobs,including failures.Logs Explorer in the Google Cloud console helps you retrieve, view, and analyze log entries.These entries are stored inlog buckets,which are the containers that Cloud Logging uses to store your log data.

To create a metric and an alert, follow these steps:

Console

Follow these steps to create a log-based metric that sends an alert whenmore than three materialized view refreshes fail in a 10-minute interval.

Create a log-based metric

  1. To set up Logs Explorer, follow the instructions inView and analyze logs.
  2. In Logs Explorer, confirm that theShow query setting is toggled on.

    When you use the Google Cloud console, the scope of theproject is the single project that is selected inthe Google Cloud console project picker. To learn how to addadditional projects, seeAdd projects to a metricsscope.

  3. In theQuery pane, paste the following query to capture all failedautomatic materialized view refresh jobs in the current project'slogging scope:

    severity:"ERROR"protoPayload.metadata.jobChange.after:"DONE"protoPayload.metadata.jobChange.job.jobConfig.queryConfig.query=~"CALL BQ.REFRESH_MATERIALIZED_VIEW\('.*'\)"protoPayload.resourceName=~".*materialized_view_refresh_[\w]"
  4. ClickRun query.

  5. ClickActions, and then selectCreate metric.

  6. To create an alert based on the number of errors, for themetric type selectCounter and enter aLog-based metricname andDescription for your metric. TheUnits field canbe left blank.

  7. To define your metric filter in theFilter selection section,apply the following settings:

    • Use theSelect project or log bucket menu to choose whether themetric counts the log entries in your Google Cloud project or onlythose log entries in a specific log bucket.

    • Create a filter that collects only the log entries that you want tocount in your metric using thelogging query language.You can also use regular expressions to create your metric's filters.

    • To see which log entries match your filter, clickPreview logs.

  8. ClickAdd label.

  9. Enter a uniqueLabel name andDescription to help you identifyyour metric. LeaveLabel type asString, the default.

  10. ForField name, enter the following string:

    protoPayload.metadata.jobChange.job.jobConfig.queryConfig.query
  11. ForRegular expression, enter the following string:

    CALLBQ.REFRESH_MATERIALIZED_VIEW\('(.*)'\)
  12. ClickDone and clickCreate metric.

For more information about counter metrics, seeConfigure counter metrics.

Create an alert

Complete the following steps to create an alert policy that specifies theconditions and sends an email when three materialized view refresh jobsfail within a ten-minute period. This option provides added flexibility whenconfiguring an alerting policy. If you create a logs-based metric directly, analert is sent each time a failed materialized view refresh error is present inthe logs.

  1. In the Google Cloud console, go to theLog-based Metrics page.

    Go to the Log-based Metrics

  2. Adjacent to your user-defined logs-based metric formaterialized view refreshes, click

  3. InSelect a metric, select the name of the metric you specifiedpreviously forLog-based metric name.

  4. InAdd filters, add an additional filter to the alertbased on the naming convention of the materialized view defined in theRegular expression field.

    This step is useful if you need to define aseparate notification channel for multiple teams that use the sameproject but are logically divided by the materialized view namingconvention. For more information about alert criteria, seeFilter charted data in "Select metrics when using Metrics Explorer".

    Screenshot showing the add metrics interface with a materialized view filter selected

  5. In theRolling window setting of theTransform data section,specify a value greater than 10 minutes to ensure that multiple logentries matching your filter are counted, and clickNext.

  6. SpecifyThreshold value,3 for example, and optionally, configuretheAlert trigger andThreshold position fields. ClickNext.

  7. Choose a notification channel for alerting.

  8. ClickCreate policy.

When the number of failed materialized view refreshes exceeds your threshold,your notification channel is alerted.

Terraform

You can create a custom metric, alert policy, notification channel, andlogging scope by using Terraform. The following Terraform sample uses a queryto monitor and log each failed materialized view refresh job.

resource"google_logging_metric""failed_mv_refresh_metric"{project=var.project_idname=var.logging_metric_namefilter=trimspace(<<EOTseverity="ERROR"ANDprotoPayload.metadata.jobChange.after="DONE"ANDprotoPayload.metadata.jobChange.job.jobConfig.queryConfig.query=~"CALL BQ.REFRESH_MATERIALIZED_VIEW\('.*'\)"ANDprotoPayload.resourceName=~".*materialized_view_refresh_[\\w]"EOT)metric_descriptor{metric_kind="DELTA"value_type="INT64"unit="1"display_name="Failed Materialized View Refresh Count"labels{key="materialized_view_name"value_type="STRING"description="The name of the materialized view that failed to refresh."}}label_extractors={"materialized_view_name"="REGEXP_EXTRACT(protoPayload.metadata.jobChange.job.jobConfig.queryConfig.query, \"CALL BQ\\.REFRESH_MATERIALIZED_VIEW\\('(.*)'\\)\")"}}

The following sample creates an alert which can be used to send an email whenthe number of failed materialized view refresh jobs exceeds a threshold.

resource"google_monitoring_alert_policy""failed_mv_refresh_alert"{project=var.project_iddisplay_name=var.alert_policy_display_namecombiner="OR"conditions{display_name="Condition: Materialized View Refresh Failure Count Exceeds Threshold"condition_threshold{filter="metric.type=\"logging.googleapis.com/user/${google_logging_metric.failed_mv_refresh_metric.name}\" AND resource.type=\"bigquery_project\""duration="${var.alert_duration_seconds}s"comparison="COMPARISON_GT"threshold_value=var.alert_threshold_countaggregations{alignment_period="${var.alert_rolling_window_seconds}s"per_series_aligner="ALIGN_DELTA"cross_series_reducer="REDUCE_SUM"group_by_fields=[]}trigger{count=1}}}notification_channels=[google_monitoring_notification_channel.email_channel.id,]}

For additional examples, see the following:

For more information about counter metrics, seeLog-based metrics overview.

Monitor materialized view usage

To view the materialized view usage for a query job, you can call thejobs.get method or query theINFORMATION_SCHEMA.JOBS_BY_* view,and view thematerialized_view_statistics field, which provides details about theuse of materialized views by the query, including the following details:

For example:

SELECTjob_id,materialized_view_statisticsFROMregion-US.INFORMATION_SCHEMA.JOBS_BY_PROJECTWHEREjob_id='<my-query-job-id>';

To view the usage of a materialized view over time, query theINFORMATION_SCHEMA.JOBS_BY_* views.

For example, the following query returns a summary of recent query jobs thatuse the target materialized view:

SELECTmv.table_reference.dataset_id,mv.table_reference.table_id,MAX(job.creation_time)latest_job_time,COUNT(job_id)job_countFROMregion-US.INFORMATION_SCHEMA.JOBS_BY_PROJECTjob,UNNEST(materialized_view_statistics.materialized_view)mvWHEREjob.creation_time>TIMESTAMP_SUB(CURRENT_TIMESTAMP,INTERVAL7DAY)ANDmv.table_reference.dataset_id='MY_DATASET'ANDmv.table_reference.table_id='MY_MATERIALIZED_VIEW'ANDmv.chosen=TRUEGROUPBY1,2;

Troubleshoot slow queries with materialized views

If your query uses materialized views and is running slower than expected,do the following:

  1. Verify that the intended materialized views are actually being used by thequery. For detailed instructions, seeMonitor materialized view usage.
  2. Check the freshness of your materialized view.
  3. Review the materialized view definition and the data it references andconsidertechniques to optimize your materialized view usage.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-18 UTC.