Manage default configurations

This document describes how to create and retrieve default configuration settings at an organization or project level.

To help manage jobs, you can configure default settings within BigQuery. Settings that use this service are configured at an organization or project level but can be overridden at the session or job level. You can configure default settings in combination with related organizational policies to enforce default behavior.

Pricing

There is no additional charge to use the BigQuery configuration service. For more information, see pricing.

Default configurations

You can specify default configurations for the following settings:

  • default_time_zone: The default time zone to use in time zone-dependent SQL functions, when a time zone is not specified as an argument. This configuration does not apply to time-unit column partitioned tables (which use UTC as the time zone), the Storage Transfer Service schedule transfers, or loading data with the bq command-line tool. For more information, see time zones.
  • default_kms_key_name: The default Cloud Key Management Service key for encrypting table data, including temporary or anonymous tables. For more information, see Customer-managed Cloud KMS keys.
  • default_query_job_timeout_ms: The default time after which a query job times out, including the time the job is queued and the time spent running. The timeout period must be between five minutes and six hours.
  • default_interactive_query_queue_timeout_ms: The default amount of time, in milliseconds, that an interactive query is queued. If unset, the default is six hours. The minimum value is 1 millisecond. The maximum value is 48 hours. To turn off interactive query queueing, set the value to -1.
  • default_batch_query_queue_timeout_ms: The default amount of time, in milliseconds, that a batch query is queued. If unset, the default is 24 hours. The minimum value is 1 millisecond. The maximum value is 48 hours. To turn off batch query queueing, set the value to -1.

Create default configurations

This section describes how to create a configuration.

Required permissions

To create a configuration, you need the bigquery.config.update Identity and Access Management (IAM) permission. The predefined IAM role roles/bigquery.admin includes the permissions that you need to create a configuration.

For more information on IAM roles and permissions in BigQuery, see Predefined roles and permissions.

Configure default settings

You can configure the default settings at the organization or project level by using the following SQL statements. When you create the configuration, you must specify the region where it applies. You can only use one region for each statement.

Configure organization settings

To configure organization settings, use the ALTER ORGANIZATION SET OPTIONS DDL statement. The following example sets the default time zone to America/Chicago, the default Cloud KMS key to a user-defined key, the default query timeout to 30 minutes, the default interactive query queue timeout to 10 minutes, and the default batch query queue timeout to 20 minutes:

ALTER ORGANIZATION
SET OPTIONS (
  `REGION.default_time_zone `= 'America/Chicago',
  -- Ensure all service accounts under the organization have permission to KMS_KEY
  `REGION.default_kms_key_name` = KMS_KEY,
  `REGION.default_query_job_timeout_ms` = 1800000,
  `REGION.default_interactive_query_queue_timeout_ms` = 600000,
  `REGION.default_batch_query_queue_timeout_ms` = 1200000);

Replace the following:

  • REGION: the region associated with your project or organization. For example, region-us or region-europe-west6.
  • KMS_KEY: a user-defined Cloud KMS key. For more information about Cloud KMS keys, see Customer-managed Cloud KMS keys.

The following example clears all organization-level default settings:

ALTER ORGANIZATION
SET OPTIONS (
  `REGION.default_time_zone` = NULL,
  `REGION.default_kms_key_name` = NULL,
  `REGION.default_query_job_timeout_ms` = NULL,
  `REGION.default_interactive_query_queue_timeout_ms` = NULL,
  `REGION.default_batch_query_queue_timeout_ms` = NULL);

Configure project settings

To configure project settings, use the ALTER PROJECT SET OPTIONS DDL statement. The ALTER PROJECT SET OPTIONS DDL statement optionally accepts the project_id variable. If the project_id is not specified, it defaults to the current project where the query runs. The following example sets the default time zone to America/Los_Angeles, the default Cloud KMS key to an example key, the default query timeout to 1 hour, the default interactive query queue timeout to 10 minutes, and the default batch query queue timeout to 20 minutes:

ALTER PROJECT project_id
SET OPTIONS (
  `REGION.default_time_zone` = 'America/Los_Angeles',
  -- Ensure all service accounts under the project have permission to KMS_KEY
  `REGION.default_kms_key_name` = KMS_KEY,
  `REGION.default_query_job_timeout_ms` = 3600000,
  `REGION.default_interactive_query_queue_timeout_ms` = 600000,
  `REGION.default_batch_query_queue_timeout_ms` = 1200000);

The following example clears all project-level default settings. The default settings use any organization-level default settings, if they exist. Otherwise, all default settings are set to the global default.

ALTER PROJECT project_id
SET OPTIONS (
  `REGION.default_time_zone` = NULL,
  `REGION.default_kms_key_name` = NULL,
  `REGION.default_query_job_timeout_ms` = NULL,
  `REGION.default_interactive_query_queue_timeout_ms` = NULL,
  `REGION.default_batch_query_queue_timeout_ms` = NULL);

Project-level configurations override organization-level configurations. Project-level configurations can in turn be overridden by session-level configurations, which can be overridden by job-level configurations.

Retrieve configuration values

You can view the default configuration settings for an organization or project by viewing the information schema. There are three different views to query:

It may take a few minutes for new configurations to become effective and reflected within the INFORMATION_SCHEMA view.

Required permissions

To retrieve configuration values, you need the bigquery.config.get IAM permission.

Each of the following predefined IAM roles includes the permissions that you need to get the configuration from the INFORMATION_SCHEMA view:

  • roles/bigquery.jobUser
  • roles/bigquery.dataEditor
  • roles/bigquery.dataUser

For more information on IAM roles and permissions in BigQuery, see Predefined roles and permissions.

Examples

To view the configurations under an organization in the us region, run the following query:

SELECT * FROM region-us.INFORMATION_SCHEMA.ORGANIZATION_OPTIONS;

To view the effective configurations under your default project in the us region, run the following query:

SELECT * FROM region-us.INFORMATION_SCHEMA.EFFECTIVE_PROJECT_OPTIONS;

To view the configurations under your default project in the us region, run the following query:

SELECT * FROM region-us.INFORMATION_SCHEMA.PROJECT_OPTIONS;