Bigquery observability

From google/skills · View interactive version

Bigquery observability is an AI agent skill from the GitHub repository google/skills. Provides data-retrieval best practices, tool selection guidance, and performant SQL query syntax for BigQuery telemetry across INFORMATION_SCHEMA, Cloud Monitoring, and the REST API. Use when the telemetry to fetch is already known, selecting telemetry tools, writing performant INFORMATION_SCHEMA qu

How to use this skill

Skill file

BigQuery Observability

Attribution

MUST READ: Before executing any gcloud, REST API, or MCP command, you

MUST read Usage Attribution. For commands executed

directly in the terminal (never in generated scripts, Terraform, or user code),

prefix gcloud with

CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:bigquery-observability)"

and append agent-skills/1.0 (skill:bigquery-observability) to User-Agent headers.

Tool Selection

<!-- mdformat off -->

| Tool | Primary Use Cases | Strengths & Capabilities | When to Avoid / Limitations |

| --- | --- | --- | --- |

| INFORMATION_SCHEMA (I_S) | Historical analysis, cohort comparison (normalized_literals), discovery of fast/slow windows, reservation/project timelines, multi-job aggregates, cost/billing tracing. | Flexible SQL querying across JOBS, JOBS_TIMELINE, and RESERVATIONS; supports custom time windows and grouping. | Avoid for high-frequency real-time polling or single-job point-lookups (can consume slots and take seconds to execute). |

| REST API (jobs.api / reservation.api) | Single-job point-lookup, real-time stage bottleneck diagnosis, automated pipeline status checks, reservation/capacity commitment configuration inspection (reservations.get, reservations.list). | Zero-SQL overhead, fast REST/CLI point-lookups (bq show -j, bq show --reservation), instant access to performanceInsights, queryPlan, and structural metadata. | Avoid for aggregate analysis across thousands of jobs, cross-project historical comparison, or system timeline aggregations. |

| Cloud Monitoring (Metrics Explorer / Charts) | Real-time alerting, fleet-wide dashboards, continuous slot utilization tracking, high-level SLA/SLO monitoring. | Out-of-the-box charts for slot utilization, query throughput, PENDING queue depth, and execution latency; low-latency alerting without running queries. | Avoid for SQL-level debugging, individual query text inspection, or stage-level execution detail. |

<!-- mdformat on -->

Prerequisites & Environment Setup

Before retrieving telemetry or running observability queries, ensure the

Google Cloud environment and project are configured:

  1. Google Cloud SDK: Ensure the

Google Cloud SDK is installed

and configured.

  1. Project Selection: Set the active Google Cloud project:

```bash

gcloud config set project {project_id}

```

  1. API Enablement: Ensure the BigQuery and Cloud Monitoring APIs are

enabled:

```bash

gcloud services enable bigquery.googleapis.com monitoring.googleapis.com

```

  1. Authentication: Authenticate the environment:

gcloud auth application-default login

GOOGLE_APPLICATION_CREDENTIALS="/path/to/key.json"

  1. Billing & IAM Roles:

{project_id}.

fallback (bq ls -j, bq show -j), and reading

PROJECT_OPTIONS (pair with read roles below to query

INFORMATION_SCHEMA).

(JOBS_BY_USER, JOBS_TIMELINE_BY_USER, SESSIONS_BY_USER)

and submitting queries (supersedes roles/bigquery.jobUser).

and storage metadata (TABLES, COLUMNS, TABLE_STORAGE,

TABLE_STORAGE_USAGE_TIMELINE, SCHEMATA,

SCHEMATA_OPTIONS).

Querying project-, folder-, or organization-level jobs at

the matching resource scope, and reservation, capacity

commitment, and assignment telemetry on the reservations

administration project.

RECOMMENDATIONS and INSIGHTS views (dataset IAM

recommendations also require iam.roles.get/list and

bigquery.datasets.getIamPolicy).

  1. Companion Skills Installation:

This skill is part of a 3-pillar operations suite (bigquery-observability,

bigquery-optimization, bigquery-troubleshooting). If any companion skill

is not yet installed in your environment, install the full suite:

```bash

npx skills add google/skills --skill bigquery-observability --skill bigquery-optimization --skill bigquery-troubleshooting

```

Workflow

  1. Single-Job Point-Lookup (Zero-SQL Overhead): For single-job slowness or

inspection, always prioritize the REST API or CLI (bq show -j) first. It

provides zero-SQL overhead and fast point-lookups for internal stage

bottlenecks (performanceInsights, queryPlan, shuffle spill).

```bash

bq show --location={location} -j {project_id}:{job_id}

```

  1. Diagnostic Transition Logic: If no job-level issues are found (e.g. no

clear internal bottlenecks), the investigation should transition to

system-level INFORMATION_SCHEMA queries (such as JOBS_TIMELINE or

RESERVATIONS_TIMELINE) to check for broader issues like slot contention,

queueing delay, or noisy neighbors.

Best Practices for Writing `INFORMATION_SCHEMA` Queries

Every query against a BigQuery INFORMATION_SCHEMA view must be qualified with

either a region qualifier or a dataset qualifier, optionally prefixed by

a project qualifier.

Qualification Syntax & Scope Matching

  1. Region-Qualified Syntax:

```googlesql

{project_id}.region-{region}.INFORMATION_SCHEMA.{view}

```

Example: ` my-project.region-us.INFORMATION_SCHEMA.JOBS`

Applies to: Regional telemetry views (JOBS*, JOBS_TIMELINE*,

RESERVATIONS*, CAPACITY_COMMITMENTS*, TABLE_STORAGE*,

STREAMING_TIMELINE*). The client query execution location MUST match the

region-{region} qualifier (or BigQuery throws: `Not found: Table

{project_id}:region-{region}.INFORMATION_SCHEMA.{view} was not found in

location {location}`).

  1. Dataset-Qualified Syntax:

```googlesql

{project_id}.{dataset_id}.INFORMATION_SCHEMA.{view}

```

Example: ` my-project.analytics.INFORMATION_SCHEMA.TABLES`

Applies to: Dataset-scoped views (PARTITIONS, SEARCH_INDEXES,

SEARCH_INDEX_COLUMNS, SEARCH_INDEX_OPTIONS,

SEARCH_INDEX_COLUMN_OPTIONS, VECTOR_INDEXES, VECTOR_INDEX_COLUMNS,

VECTOR_INDEX_OPTIONS, TABLE_CONSTRAINTS, KEY_COLUMN_USAGE;

SEARCH_INDEXES_BY_ORGANIZATION uses region-). Never use region- with

PARTITIONS, dataset-level SEARCH_INDEX* views (which fail with

Not found), or VECTOR_INDEX* views (which silently return 0 rows);

prefer {dataset_id} for TABLE_CONSTRAINTS and KEY_COLUMN_USAGE per

public documentation.

  1. Dual-Scoped Views: Views like TABLES, TABLE_OPTIONS,

TABLE_SNAPSHOTS, COLUMNS, COLUMN_FIELD_PATHS, VIEWS,

MATERIALIZED_VIEWS, ROW_ACCESS_POLICIES, ROUTINES, ROUTINE_OPTIONS,

and PARAMETERS can be qualified with either {dataset_id} or

region-{region} depending on whether dataset or region-wide analysis is

required.

  1. Project Qualifier ({project_id}): Optional. If omitted, queries

default to the project in which the query is executing. Specifying a project

qualifier on organization-level views (e.g. JOBS_BY_ORGANIZATION) has no

impact on results.

Principle of Least Privilege & Scope Selection

When constructing INFORMATION_SCHEMA queries, **always select the scope and

view variant with the least IAM permission requirement** that satisfies the

analytical need:

  1. User-Level over Project-Level (_BY_USER): When diagnosing queries or

sessions executed by the current user, use _BY_USER (e.g. JOBS_BY_USER,

SESSIONS_BY_USER). This requires only bigquery.jobs.list (granted via

roles/bigquery.user), avoiding the need for bigquery.jobs.listAll or

roles/bigquery.admin. If JOBS_BY_USER also returns 403 Access Denied

(e.g. when the caller only holds roles/bigquery.jobUser, which grants

bigquery.jobs.create but not bigquery.jobs.list), fall back to

bq ls -j -n {max_results} {project_id} for a zero-compute CLI job listing.

  1. Dataset-Level over Region/Project-Level: When querying table metadata,

columns, or views for a specific dataset, qualify with {dataset_id} rather

than region-{region} when project-level metadata access is restricted.

Dataset-scoped queries require permissions only on that target dataset.

  1. Project-Level over Org/Folder-Level (_BY_PROJECT): Always start with

project-scoped views before escalating to _BY_FOLDER or

_BY_ORGANIZATION. Folder and organization queries require broad folder/org

IAM permissions (bigquery.jobs.listAll or bigquery.tables.list at the

Org/Folder node).

Query Running Project, JOBS_BY_PROJECT (and

JOBS_TIMELINE_BY_PROJECT) captures that project's query stats.

However, in BigQuery Editions, reservations and commitments

(RESERVATIONS*, CAPACITY_COMMITMENTS*, ASSIGNMENTS*) live in an

Admin Project whose JOBS_BY_PROJECT view typically has no query

running stats. When starting from an admin project or aggregating

workload across all projects sharing a reservation, query

JOBS_BY_ORGANIZATION (or JOBS_TIMELINE_BY_ORGANIZATION) filtered by

reservation_id ({admin_project_id}:{location}.{reservation_name};

note multi-region locations use uppercase US or EU, or compare with

LOWER(reservation_id)).

  1. Metadata Roles over Data Roles: For table and storage introspection,

prefer roles/bigquery.metadataViewer (which provides bigquery.tables.get

and bigquery.tables.list) over roles/bigquery.dataViewer or

roles/bigquery.dataOwner when data read access (bigquery.tables.getData)

is not needed. (Note: INFORMATION_SCHEMA.PARTITIONS uniquely requires

bigquery.tables.getData).

Execution Guardrails & Query Invariants

(e.g., `creation_time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 3

DAY)) or usage_date` to avoid full metadata table scans.

statement_type IS NULL)` when aggregating compute spend to avoid

double-counting parent scripts and child jobs.

project required columns.

--use_legacy_sql=false "{query}" or API dryRun=true`) before executing

complex queries, multi-view joins, or large scans to validate syntax and

estimate totalBytesProcessed at zero cost.

qualifier, but the project has no datasets or jobs in that region, the query

succeeds and returns 0 rows. Never assume 0 rows means 0 usage—always

verify the target dataset locations.

Multi-regions do not encompass single regions (e.g. region-us returns only

multi-region US metadata and does not include single regions like

region-us-central1).

cross-region in a single query (e.g. region-us cannot join region-eu).

results are never cached. On-demand queries incur a minimum of 10 MB of data

processing charges per execution.

Domain References & SQL Queries

Telemetry Query Guides

(references/compute_ondemand_billable.md): Authoritative Golden CTE

(bytes_billed_cte), timezone-aligned billing date extraction (PST8PDT),

BQML CREATE_MODEL 50x multiplier rules, script wrapper deduplication, and

row-level security (RLS) masking checks.

(references/compute_capacity_billable.md): Query templates for auditing

billable capacity hours across 1-Year/3-Year commitments, uncovered baseline

PAYG slots, and dynamic autoscaling hours.

(references/storage_footprints.md): Storage snapshot queries, compression

ratio calculations, Time Travel / Fail-Safe churn, daily average GiB

time-integrals, billing model evaluation, and search index coverage.

Performance & Troubleshooting Guides

Queries for evaluating individual and aggregate job performance, stage

bottleneck flags, comparable jobs via normalized literals

(query_info.query_hashes.normalized_literals), BI Engine acceleration,

metadata cache (cmeta) acceleration, search index usage, materialized view

rewrite usage, and execution variance outliers.

(references/resource_contention_queries.md): Queries for diagnosing slot

contention, queue latency, per-minute concurrency/queue timelines, and

1-second reservation slot saturation.

(references/capacity_and_configuration_queries.md): Queries for evaluating

second-by-second baseline/max capacity ceilings, autoscaling saturation

timelines, and auditing configuration changes

(RESERVATION_CHANGES_BY_PROJECT, ASSIGNMENT_CHANGES_BY_PROJECT).

Schema Dictionaries (Column Definitions & Units)

Complete column dictionary, physical units, and least-privilege IAM roles

for all compute, job, session, reservation, capacity commitment, assignment,

and BI Engine views (JOBS*, JOBS_TIMELINE*, SESSIONS_BY_USER,

SESSIONS_BY_PROJECT, RESERVATIONS*, RESERVATION_CHANGES*,

RESERVATIONS_TIMELINE*, CAPACITY_COMMITMENTS*,

CAPACITY_COMMITMENT_CHANGES*, ASSIGNMENTS*, ASSIGNMENT_CHANGES*,

BI_CAPACITIES, BI_CAPACITY_CHANGES).

(references/schema_storage.md): Complete column dictionary, physical

units, and least-privilege IAM roles for all table storage, partition,

column, snapshot, dataset, constraint, and replication views

(TABLE_STORAGE*, TABLE_STORAGE_USAGE_TIMELINE*, TABLES,

TABLE_OPTIONS, COLUMNS, COLUMN_FIELD_PATHS, PARTITIONS, VIEWS,

MATERIALIZED_VIEWS, TABLE_SNAPSHOTS, TABLE_CONSTRAINTS,

KEY_COLUMN_USAGE, SCHEMATA, SCHEMATA_OPTIONS, SCHEMATA_REPLICAS*,

SCHEMATA_LINKS, SHARED_DATASET_USAGE).

(references/schema_others.md): Complete column dictionary, physical units,

and least-privilege IAM roles for all remaining views including Access

Control (OBJECT_PRIVILEGES, ROW_ACCESS_POLICIES), Streaming Ingestion

(STREAMING_TIMELINE*, WRITE_API_TIMELINE*), Configuration Options

(PROJECT_OPTIONS, PROJECT_OPTIONS_CHANGES, EFFECTIVE_PROJECT_OPTIONS,

ORGANIZATION_OPTIONS, ORGANIZATION_OPTIONS_CHANGES), Insights &

Recommendations (RECOMMENDATIONS*, INSIGHTS*), and Indexes/BI

Engine/Routines (SEARCH_INDEXES*, SEARCH_INDEX_COLUMNS,

SEARCH_INDEX_OPTIONS, VECTOR_INDEXES, VECTOR_INDEX_COLUMNS,

VECTOR_INDEX_OPTIONS, BI_CAPACITIES, BI_CAPACITY_CHANGES, ROUTINES,

ROUTINE_OPTIONS, PARAMETERS).

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.