1
---
2
name: bigquery-observability
3
metadata:
4
version: "1.2.3"
5
category: BigDataAndAnalytics
6
publisher: google
7
description: >-
8
Provides data-retrieval best practices, tool selection guidance, and
9
performant SQL query syntax for BigQuery telemetry across INFORMATION_SCHEMA,
10
Cloud Monitoring, and the REST API. Use when the telemetry to fetch is already
11
known, selecting telemetry tools, writing performant INFORMATION_SCHEMA
12
queries, retrieving telemetry for diagnosing single-job performance
13
bottlenecks, investigating slot contention, job concurrency and queue latency,
14
analyzing reservation capacity, utilization and autoscaling saturation, or
15
auditing capacity-based and on-demand compute and storage resource billable
16
usage. Don't use for root-cause diagnosis or symptom troubleshooting when the
17
cause is unknown (use bigquery-troubleshooting first), or for writing or
18
optimizing business logic SQL (use bigquery-optimization).
19
---
20
21
# BigQuery Observability
22
23
## Attribution
24
25
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
26
MUST read [Usage Attribution](references/attribution.md). For commands executed
27
directly in the terminal (never in generated scripts, Terraform, or user code),
28
prefix `gcloud` with
29
`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:bigquery-observability)"`
30
and append `agent-skills/1.0 (skill:bigquery-observability)` to `User-Agent` headers.
31
32
## Tool Selection
33
34
<!-- mdformat off -->
35
36
| Tool | Primary Use Cases | Strengths & Capabilities | When to Avoid / Limitations |
37
| --- | --- | --- | --- |
38
| **`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). |
39
| **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. |
40
| **`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. |
41
42
<!-- mdformat on -->
43
44
## Prerequisites & Environment Setup
45
46
Before retrieving telemetry or running observability queries, ensure the
47
Google Cloud environment and project are configured:
48
49
1. **Google Cloud SDK**: Ensure the
50
[Google Cloud SDK](https://cloud.google.com/sdk/docs/install) is installed
51
and configured.
52
2. **Project Selection**: Set the active Google Cloud project:
53
54
```bash
55
gcloud config set project {project_id}
56
```
57
58
3. **API Enablement**: Ensure the BigQuery and Cloud Monitoring APIs are
59
enabled:
60
61
```bash
62
gcloud services enable bigquery.googleapis.com monitoring.googleapis.com
63
```
64
65
4. **Authentication**: Authenticate the environment:
66
* CLI queries and `bq` commands: `gcloud auth login`
67
* SDKs and automated client tools:
68
`gcloud auth application-default login`
69
* Service accounts: Set
70
`GOOGLE_APPLICATION_CREDENTIALS="/path/to/key.json"`
71
72
5. **Billing & IAM Roles**:
73
* Verify an active Google Cloud Billing account is attached to
74
`{project_id}`.
75
* Ensure appropriate IAM roles:
76
* `roles/bigquery.jobUser`: Submitting queries, own-job CLI
77
fallback (`bq ls -j`, `bq show -j`), and reading
78
`PROJECT_OPTIONS` (pair with read roles below to query
79
`INFORMATION_SCHEMA`).
80
* `roles/bigquery.user`: Querying user-scoped telemetry
81
(`JOBS_BY_USER`, `JOBS_TIMELINE_BY_USER`, `SESSIONS_BY_USER`)
82
and submitting queries (supersedes `roles/bigquery.jobUser`).
83
* `roles/bigquery.metadataViewer`: Inspecting table, dataset,
84
and storage metadata (`TABLES`, `COLUMNS`, `TABLE_STORAGE`,
85
`TABLE_STORAGE_USAGE_TIMELINE`, `SCHEMATA`,
86
`SCHEMATA_OPTIONS`).
87
* `roles/bigquery.resourceViewer` or `roles/bigquery.admin`:
88
Querying project-, folder-, or organization-level jobs at
89
the matching resource scope, and reservation, capacity
90
commitment, and assignment telemetry on the reservations
91
administration project.
92
* `roles/recommender.viewer` (optional): Querying
93
`RECOMMENDATIONS` and `INSIGHTS` views (dataset IAM
94
recommendations also require `iam.roles.get`/`list` and
95
`bigquery.datasets.getIamPolicy`).
96
* `roles/monitoring.viewer`: Reading Cloud Monitoring metrics.
97
98
6. **Companion Skills Installation**:
99
This skill is part of a 3-pillar operations suite (`bigquery-observability`,
100
`bigquery-optimization`, `bigquery-troubleshooting`). If any companion skill
101
is not yet installed in your environment, install the full suite:
102
103
```bash
104
npx skills add google/skills --skill bigquery-observability --skill bigquery-optimization --skill bigquery-troubleshooting
105
```
106
107
## Workflow
108
109
1. **Single-Job Point-Lookup (Zero-SQL Overhead):** For single-job slowness or
110
inspection, always prioritize the REST API or CLI (`bq show -j`) first. It
111
provides zero-SQL overhead and fast point-lookups for internal stage
112
bottlenecks (`performanceInsights`, `queryPlan`, shuffle spill).
113
114
```bash
115
bq show --location={location} -j {project_id}:{job_id}
116
```
117
118
2. **Diagnostic Transition Logic:** If no job-level issues are found (e.g. no
119
clear internal bottlenecks), the investigation should transition to
120
system-level `INFORMATION_SCHEMA` queries (such as `JOBS_TIMELINE` or
121
`RESERVATIONS_TIMELINE`) to check for broader issues like slot contention,
122
queueing delay, or noisy neighbors.
123
124
## Best Practices for Writing `INFORMATION_SCHEMA` Queries
125
126
Every query against a BigQuery `INFORMATION_SCHEMA` view must be qualified with
127
either a **region qualifier** or a **dataset qualifier**, optionally prefixed by
128
a **project qualifier**.
129
130
### Qualification Syntax & Scope Matching
131
132
1. **Region-Qualified Syntax:**
133
134
```googlesql
135
`{project_id}`.`region-{region}`.INFORMATION_SCHEMA.{view}
136
```
137
138
*Example:* `` `my-project`.`region-us`.INFORMATION_SCHEMA.JOBS``
139
140
*Applies to:* Regional telemetry views (`JOBS*`, `JOBS_TIMELINE*`,
141
`RESERVATIONS*`, `CAPACITY_COMMITMENTS*`, `TABLE_STORAGE*`,
142
`STREAMING_TIMELINE*`). The client query execution location MUST match the
143
`region-{region}` qualifier (or BigQuery throws: `Not found: Table
144
{project_id}:region-{region}.INFORMATION_SCHEMA.{view} was not found in
145
location {location}`).
146
147
2. **Dataset-Qualified Syntax:**
148
149
```googlesql
150
`{project_id}`.`{dataset_id}`.INFORMATION_SCHEMA.{view}
151
```
152
153
*Example:* `` `my-project`.`analytics`.INFORMATION_SCHEMA.TABLES``
154
155
*Applies to:* Dataset-scoped views (`PARTITIONS`, `SEARCH_INDEXES`,
156
`SEARCH_INDEX_COLUMNS`, `SEARCH_INDEX_OPTIONS`,
157
`SEARCH_INDEX_COLUMN_OPTIONS`, `VECTOR_INDEXES`, `VECTOR_INDEX_COLUMNS`,
158
`VECTOR_INDEX_OPTIONS`, `TABLE_CONSTRAINTS`, `KEY_COLUMN_USAGE`;
159
`SEARCH_INDEXES_BY_ORGANIZATION` uses `region-`). Never use `region-` with
160
`PARTITIONS`, dataset-level `SEARCH_INDEX*` views (which fail with
161
`Not found`), or `VECTOR_INDEX*` views (which silently return 0 rows);
162
prefer `{dataset_id}` for `TABLE_CONSTRAINTS` and `KEY_COLUMN_USAGE` per
163
public documentation.
164
165
3. **Dual-Scoped Views:** Views like `TABLES`, `TABLE_OPTIONS`,
166
`TABLE_SNAPSHOTS`, `COLUMNS`, `COLUMN_FIELD_PATHS`, `VIEWS`,
167
`MATERIALIZED_VIEWS`, `ROW_ACCESS_POLICIES`, `ROUTINES`, `ROUTINE_OPTIONS`,
168
and `PARAMETERS` can be qualified with either `{dataset_id}` or
169
`region-{region}` depending on whether dataset or region-wide analysis is
170
required.
171
172
4. **Project Qualifier (`{project_id}`):** Optional. If omitted, queries
173
default to the project in which the query is executing. Specifying a project
174
qualifier on organization-level views (e.g. `JOBS_BY_ORGANIZATION`) has no
175
impact on results.
176
177
### Principle of Least Privilege & Scope Selection
178
179
When constructing `INFORMATION_SCHEMA` queries, **always select the scope and
180
view variant with the least IAM permission requirement** that satisfies the
181
analytical need:
182
183
1. **User-Level over Project-Level (`_BY_USER`):** When diagnosing queries or
184
sessions executed by the current user, use `_BY_USER` (e.g. `JOBS_BY_USER`,
185
`SESSIONS_BY_USER`). This requires only `bigquery.jobs.list` (granted via
186
`roles/bigquery.user`), avoiding the need for `bigquery.jobs.listAll` or
187
`roles/bigquery.admin`. If `JOBS_BY_USER` also returns `403 Access Denied`
188
(e.g. when the caller only holds `roles/bigquery.jobUser`, which grants
189
`bigquery.jobs.create` but not `bigquery.jobs.list`), fall back to
190
`bq ls -j -n {max_results} {project_id}` for a zero-compute CLI job listing.
191
2. **Dataset-Level over Region/Project-Level:** When querying table metadata,
192
columns, or views for a specific dataset, qualify with `{dataset_id}` rather
193
than `region-{region}` when project-level metadata access is restricted.
194
Dataset-scoped queries require permissions only on that target dataset.
195
3. **Project-Level over Org/Folder-Level (`_BY_PROJECT`):** Always start with
196
project-scoped views before escalating to `_BY_FOLDER` or
197
`_BY_ORGANIZATION`. Folder and organization queries require broad folder/org
198
IAM permissions (`bigquery.jobs.listAll` or `bigquery.tables.list` at the
199
Org/Folder node).
200
* **Admin Project vs. Query Running Project:** When investigating inside a
201
**Query Running Project**, `JOBS_BY_PROJECT` (and
202
`JOBS_TIMELINE_BY_PROJECT`) captures that project's query stats.
203
However, in BigQuery Editions, reservations and commitments
204
(`RESERVATIONS*`, `CAPACITY_COMMITMENTS*`, `ASSIGNMENTS*`) live in an
205
**Admin Project** whose `JOBS_BY_PROJECT` view typically has no query
206
running stats. When starting from an admin project or aggregating
207
workload across all projects sharing a reservation, query
208
`JOBS_BY_ORGANIZATION` (or `JOBS_TIMELINE_BY_ORGANIZATION`) filtered by
209
`reservation_id` (`{admin_project_id}:{location}.{reservation_name}`;
210
note multi-region locations use uppercase `US` or `EU`, or compare with
211
`LOWER(reservation_id)`).
212
4. **Metadata Roles over Data Roles:** For table and storage introspection,
213
prefer `roles/bigquery.metadataViewer` (which provides `bigquery.tables.get`
214
and `bigquery.tables.list`) over `roles/bigquery.dataViewer` or
215
`roles/bigquery.dataOwner` when data read access (`bigquery.tables.getData`)
216
is not needed. (Note: `INFORMATION_SCHEMA.PARTITIONS` uniquely requires
217
`bigquery.tables.getData`).
218
219
### Execution Guardrails & Query Invariants
220
221
* **Mandatory Partition & Time Filtering:** Always filter on `creation_time`
222
(e.g., `creation_time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 3
223
DAY)`) or `usage_date` to avoid full metadata table scans.
224
* **Script Wrapper Exclusion:** Add `AND (statement_type != 'SCRIPT' OR
225
statement_type IS NULL)` when aggregating compute spend to avoid
226
double-counting parent scripts and child jobs.
227
* **Column Pruning:** Never use `SELECT *` against `INFORMATION_SCHEMA`; only
228
project required columns.
229
* **Dry Run & Cost Estimation:** Use a dry run (`bq query --dry_run
230
--use_legacy_sql=false "{query}"` or API `dryRun=true`) before executing
231
complex queries, multi-view joins, or large scans to validate syntax and
232
estimate `totalBytesProcessed` at zero cost.
233
* **Empty Regional Scope (0 Rows):** If the execution location matches the
234
qualifier, but the project has no datasets or jobs in that region, the query
235
succeeds and returns **0 rows**. Never assume 0 rows means 0 usage—always
236
verify the target dataset locations.
237
* **Non-Hierarchical Region Scope:** Region qualifiers are not hierarchical.
238
Multi-regions do not encompass single regions (e.g. `region-us` returns only
239
multi-region `US` metadata and does not include single regions like
240
`region-us-central1`).
241
* **No Multi-Region Aggregation in SQL:** Region qualifiers cannot be joined
242
cross-region in a single query (e.g. `region-us` cannot join `region-eu`).
243
* **Uncached Execution & Minimum Scan Size:** `INFORMATION_SCHEMA` query
244
results are never cached. On-demand queries incur a minimum of 10 MB of data
245
processing charges per execution.
246
247
## Domain References & SQL Queries
248
249
### Telemetry Query Guides
250
251
* **On-Demand Compute: Billed Bytes**
252
(`references/compute_ondemand_billable.md`): Authoritative Golden CTE
253
(`bytes_billed_cte`), timezone-aligned billing date extraction (PST8PDT),
254
BQML CREATE_MODEL 50x multiplier rules, script wrapper deduplication, and
255
row-level security (RLS) masking checks.
256
* **Capacity Compute: Billable Slots & Commitments**
257
(`references/compute_capacity_billable.md`): Query templates for auditing
258
billable capacity hours across 1-Year/3-Year commitments, uncovered baseline
259
PAYG slots, and dynamic autoscaling hours.
260
* **Storage Footprints & Usage (Bytes Stored)**
261
(`references/storage_footprints.md`): Storage snapshot queries, compression
262
ratio calculations, Time Travel / Fail-Safe churn, daily average GiB
263
time-integrals, billing model evaluation, and search index coverage.
264
265
### Performance & Troubleshooting Guides
266
267
* **Job Performance Queries** (`references/job_performance_queries.md`):
268
Queries for evaluating individual and aggregate job performance, stage
269
bottleneck flags, comparable jobs via normalized literals
270
(`query_info.query_hashes.normalized_literals`), BI Engine acceleration,
271
metadata cache (cmeta) acceleration, search index usage, materialized view
272
rewrite usage, and execution variance outliers.
273
* **Resource Contention Queries**
274
(`references/resource_contention_queries.md`): Queries for diagnosing slot
275
contention, queue latency, per-minute concurrency/queue timelines, and
276
1-second reservation slot saturation.
277
* **Capacity & Configuration Queries**
278
(`references/capacity_and_configuration_queries.md`): Queries for evaluating
279
second-by-second baseline/max capacity ceilings, autoscaling saturation
280
timelines, and auditing configuration changes
281
(`RESERVATION_CHANGES_BY_PROJECT`, `ASSIGNMENT_CHANGES_BY_PROJECT`).
282
283
### Schema Dictionaries (Column Definitions & Units)
284
285
* **Compute & Capacity Schema Dictionary** (`references/schema_compute.md`):
286
Complete column dictionary, physical units, and least-privilege IAM roles
287
for all compute, job, session, reservation, capacity commitment, assignment,
288
and BI Engine views (`JOBS*`, `JOBS_TIMELINE*`, `SESSIONS_BY_USER`,
289
`SESSIONS_BY_PROJECT`, `RESERVATIONS*`, `RESERVATION_CHANGES*`,
290
`RESERVATIONS_TIMELINE*`, `CAPACITY_COMMITMENTS*`,
291
`CAPACITY_COMMITMENT_CHANGES*`, `ASSIGNMENTS*`, `ASSIGNMENT_CHANGES*`,
292
`BI_CAPACITIES`, `BI_CAPACITY_CHANGES`).
293
* **Storage & Data Catalog Schema Dictionary**
294
(`references/schema_storage.md`): Complete column dictionary, physical
295
units, and least-privilege IAM roles for all table storage, partition,
296
column, snapshot, dataset, constraint, and replication views
297
(`TABLE_STORAGE*`, `TABLE_STORAGE_USAGE_TIMELINE*`, `TABLES`,
298
`TABLE_OPTIONS`, `COLUMNS`, `COLUMN_FIELD_PATHS`, `PARTITIONS`, `VIEWS`,
299
`MATERIALIZED_VIEWS`, `TABLE_SNAPSHOTS`, `TABLE_CONSTRAINTS`,
300
`KEY_COLUMN_USAGE`, `SCHEMATA`, `SCHEMATA_OPTIONS`, `SCHEMATA_REPLICAS*`,
301
`SCHEMATA_LINKS`, `SHARED_DATASET_USAGE`).
302
* **Platform, Governance & Ingestion Schema Dictionary**
303
(`references/schema_others.md`): Complete column dictionary, physical units,
304
and least-privilege IAM roles for all remaining views including Access
305
Control (`OBJECT_PRIVILEGES`, `ROW_ACCESS_POLICIES`), Streaming Ingestion
306
(`STREAMING_TIMELINE*`, `WRITE_API_TIMELINE*`), Configuration Options
307
(`PROJECT_OPTIONS`, `PROJECT_OPTIONS_CHANGES`, `EFFECTIVE_PROJECT_OPTIONS`,
308
`ORGANIZATION_OPTIONS`, `ORGANIZATION_OPTIONS_CHANGES`), Insights &
309
Recommendations (`RECOMMENDATIONS*`, `INSIGHTS*`), and Indexes/BI
310
Engine/Routines (`SEARCH_INDEXES*`, `SEARCH_INDEX_COLUMNS`,
311
`SEARCH_INDEX_OPTIONS`, `VECTOR_INDEXES`, `VECTOR_INDEX_COLUMNS`,
312
`VECTOR_INDEX_OPTIONS`, `BI_CAPACITIES`, `BI_CAPACITY_CHANGES`, `ROUTINES`,
313
`ROUTINE_OPTIONS`, `PARAMETERS`).
314