Skip to content
Back to skills

Bigquery Cost Audit

ASecurity

Audit Google BigQuery spend with read-only INFORMATION_SCHEMA queries and turn the results into ranked, priced fixes. Use this whenever someone asks why their BigQuery bill is high or went up, wants to cut BigQuery costs, is deciding between on-demand and slots (Editions, reservations, autoscaling), between logical and physical storage billing, or suspects repeated dashboard or scheduled queries, time travel, or forgotten backup tables are costing money. Also use it when they paste JOBS or TA...

  • 5 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added December 1, 2026
ai-agentsgobashsqlgcpsecurity

Security analysis

A100/100

Pro scans all 6 files and shows the line behind each finding

Scanned December 1, 2026

npx -y skills add costory-io/finops-skills --skill bigquery-cost-audit --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Bigquery Cost Audit?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Bigquery Cost Audit
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/costory-io-bigquery-cost-audit/badge)](https://www.skillsdirectory.com/skills/costory-io-bigquery-cost-audit)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: bigquery-cost-audit
description: Audit Google BigQuery spend with read-only INFORMATION_SCHEMA queries and turn the results into ranked, priced fixes. Use this whenever someone asks why their BigQuery bill is high or went up, wants to cut BigQuery costs, is deciding between on-demand and slots (Editions, reservations, autoscaling), between logical and physical storage billing, or suspects repeated dashboard or scheduled queries, time travel, or forgotten backup tables are costing money. Also use it when they paste JOBS or TABLE_STORAGE output and ask what it means, even if they never say "audit".
---

# BigQuery cost audit

The GCP invoice says what BigQuery cost, not which query, table or workload drove it. Four metadata-only checks on INFORMATION_SCHEMA usually find most of the waste:

| # | Check | What it finds | SQL |
|---|-------|---------------|-----|
| 1 | Repeated queries | The same SQL rerun by dashboards, schedules, tools | `sql/01-repeated-queries.sql` |
| 2 | Logical vs physical storage | Datasets on the wrong storage billing model | `sql/02-storage-billing-model.sql` |
| 3 | On-demand vs slots | Workloads cheaper on a reservation (or the reverse) | `sql/03-on-demand-vs-slots.sql` |
| 4 | Backup-looking tables | Copies kept "just in case" that time travel already covers | `sql/04-backup-tables.sql` |

Everything here is read-only. The fixes (ALTER statements) change billing, so present them; run them only if the user explicitly asks.

## 1. Set up

Ask for, or discover:
- **Project(s)**: the project that runs the jobs (checks 1, 3) and the one that owns the tables (checks 2, 4). They are often different.
- **Region**: the `region-xx` qualifier where the data lives (`region-eu`, `region-us`, `region-europe-west1`...). `bq ls --format=json --project_id=P` shows each dataset's location.
- **Prices**: list prices differ by region and edition. Defaults below are pay-as-you-go list prices (US column rechecked on 2026-11-30). Tell the user to confirm on https://cloud.google.com/bigquery/pricing and to swap in negotiated rates if they have any.

| USD | EU multi-region | US multi-region |
|-----|-----------------|-----------------|
| On-demand, per TiB scanned | 6.25 | 6.25 |
| Standard edition, per slot-hour | 0.044 | 0.04 |
| Enterprise edition, per slot-hour | 0.066 | 0.06 |
| Logical storage active / long-term, per GiB-month | 0.02 / 0.01 | 0.02 / 0.01 |
| Physical storage active / long-term, per GiB-month | 0.044 / 0.022 | 0.04 / 0.02 |

Before running anything, check these, because they are the usual failures:
- **Permissions**: `bigquery.jobs.listAll` on the job project (e.g. BigQuery Resource Viewer) for JOBS; `bigquery.tables.list` for TABLE_STORAGE.
- **TABLE_STORAGE is off by default** on newer projects. Checks 2 and 4 fail until someone runs `ALTER PROJECT \`P\` SET OPTIONS (\`region-eu.enable_info_schema_storage\` = TRUE)` (or `ALTER ORGANIZATION`). History takes about a day to backfill. This is a settings change: ask first.
- **Cost of the audit itself**: cents to a few dollars. JOBS views on a busy project scan several GB per query (12 GB seen on a real project, about $0.07), so a 1 GB cap is too tight; the runner defaults to 20 GB. On-demand has a 10 MB minimum per INFORMATION_SCHEMA query; on capacity it uses slots.
- **Keep the audit out of the audited project**: run the jobs from a sandbox project (`BILLING_PROJECT=sandbox scripts/run_check.sh ...`) while the SQL reads `prod.region-xx.INFORMATION_SCHEMA`. Job records and cost then land in the sandbox. Needs read access to the prod views from that identity.
- **Query text is sensitive**: check 1 returns past SQL, which can contain customer IDs or emails. Do not paste it into reports verbatim; describe or redact.
- **Several projects**: checks 2-4 have `_BY_ORGANIZATION` variants (`TABLE_STORAGE_BY_ORGANIZATION`, `JOBS_BY_ORGANIZATION`); then add `project_id` to every grouping key. Check 1 needs `JOBS_BY_PROJECT` because the org view does not expose query text.

Run a check with the bundled runner, which fills placeholders and caps bytes billed:

```bash
scripts/run_check.sh 01 my-project eu           # check 1, EU prices
scripts/run_check.sh 03 my-project us > c3.csv  # check 3, US prices
```

Or read the `.sql` file, replace `{{PROJECT}}`, `{{REGION}}` and the price placeholders yourself, and run it in the console or with `bq query --nouse_legacy_sql`.

## 2. Read the results

The numbers are easy to misread. These rules are the point of the skill.

### Check 1: repeated queries
- Sort by total cost, not cost per run: a cheap query run 2,000 times beats an expensive one run once.
- Frequent is not expensive by itself. If the top group bills cents, say so and move on: no materialization project for $0.16.
- The dollar column is the on-demand list-price equivalent of bytes billed. For jobs that ran on a reservation it is not what they cost; look at `slot_hours` instead.
- `cache_hits` near zero: `CURRENT_TIMESTAMP()`/`CURRENT_DATE()` in the SQL, or a source table written between runs, disables the cache.
- Same result every run: materialize once (scheduled table or materialized view) and point the dashboard there. Typical culprits: Looker Studio auto refresh on a wall screen, a 15-minute schedule on daily data, an internal tool querying on every page load.
- Large scans on partitioned tables: check partition pruning. `require_partition_filter = TRUE` rejects unfiltered queries but does not cap a wide filter; per-user daily quotas and `maximum_bytes_billed` do.
- Rows sharing a `query_start` may be the same workload with different literals. Read the full SQL before merging them.

### Check 2: logical vs physical storage
- Logical bills uncompressed bytes, time travel and fail-safe included. Physical bills compressed bytes at a higher rate per GiB (2x logical in the US multi-region, 2.2x in the EU multi-region, different again in single regions), plus time travel and fail-safe at the active physical rate.
- So the break-even compression ratio with no history equals that price ratio: about 2x in the US multi-region, 2.2x in the EU multi-region; elsewhere divide the region's physical price by its logical price. The trap is churn: `MERGE`, `UPDATE`, `DELETE` and nightly `CREATE OR REPLACE` keep old blocks for the time-travel window (7 days default, down to 2) plus 7 days of fail-safe.
- Decide with the two forecast cost columns, not with `churn_ratio` alone. A dataset can have more history than live data and still be far cheaper on physical.
- Look at `current_model` first. A "saving" on a dataset already on PHYSICAL is not a saving.
- Fix: `ALTER SCHEMA ds SET OPTIONS (storage_billing_model = 'PHYSICAL')`. After a switch you wait 14 days to switch back; billing reflects it in about 24 hours.
- Churny but still worth physical: `ALTER SCHEMA ds SET OPTIONS (max_time_travel_hours = 48)`, if 2 days of recovery is acceptable (fail-safe stays 7 days).
- The model is per dataset. Append-only logs next to heavily rewritten tables: split the dataset first.
- TABLE_STORAGE is a current snapshot: the output is a forecast holding usage constant. For invoice reconciliation use `TABLE_STORAGE_USAGE_TIMELINE` (daily, a few days behind) or the billing export.

### Check 3: on-demand vs slots
- Decide per workload, not per project. One project often mixes scan-heavy, low-CPU jobs (integrity checks, simple aggregates, selective filters) that win on slots with CPU-heavy joins that lose.
- Break-even: on-demand price per TiB divided by slot-hour price. EU Standard: 6.25 / 0.044 ≈ **142 slot-hours per TiB**; Enterprise ≈ 95. Below that, slots are cheaper before rounding overhead. Slots already paid for (baseline, commitments) are cheaper still to fill.
- Autoscaling scales in 50-slot steps and, by default, bills per second with a one-minute minimum per scale-up. Fluid scaling is an opt-in per reservation that removes the one-minute minimum, which makes slots much better for short, bursty jobs. Ask which one applies (or recommend opting in) before estimating. If they decided on-demand vs slots more than a year ago, re-check.
- Editions differ in features, not only price: check that Standard covers what they need before defaulting to Enterprise, and do not claim security features (CMEK, VPC Service Controls) require Enterprise unless you have checked the current editions page.
- The query's slot estimate adds a deliberately pessimistic allowance (one extra 50-slot block per running job). A workload just under the break-even ratio can still be cheaper on-demand: compare the dollar columns.
- Workloads are first-pass groups (destination table, else the user). Validate them with referenced tables, labels or SQL patterns before routing anything. Small workloads (under $10 on-demand over 30 days) are filtered out.
- Routing: two execution projects (one assigned to a reservation, one on-demand) and run each workload in the right one. Assign only `QUERY` jobs to the reservation: load and extract jobs are free on the shared pool and only consume reservation slots under a `PIPELINE` assignment.
- Validate shortlisted workloads in a trial reservation (billed capacity and latency) before calling it a saving.
- Commitments: two kinds exist. Spend-based BigQuery CUDs (1 or 3 years, Standard and Enterprise editions) take about 10% or 20% off pay-as-you-go (US list: Standard $0.036 / $0.032, Enterprise $0.054 / $0.048 per slot-hour). Resource (slot) commitments on Enterprise and Enterprise Plus take about 20% or 40% off (US Enterprise $0.048 / $0.036). Some consumption-model discounts need an opt-in. A slot commitment bills every hour whether used or not. Price a proposed baseline both ways (slots x 730 h x rate), compare with measured hourly slot usage (`JOBS_TIMELINE` or `RESERVATIONS_TIMELINE`), and commit only to the level that is busy nearly all the time; autoscaling covers the rest.
- Empty result: either no on-demand workload passed $10 in 30 days, or the project already runs on a reservation (the query keeps on-demand jobs only). Say which, and in the second case the question becomes reservation sizing (baseline vs autoscaling max), not on-demand vs slots.
- Pick the right project: the one that runs the jobs, not the reservation admin project or the one that only stores tables. An almost empty result usually means the wrong project.

### Check 4: backup-looking tables
- A name match is a candidate, not proof. Check owner, last write, reads and retention requirements before deleting. A table written yesterday is not forgotten.
- Date-suffixed names are excluded on purpose: GA4 and other exports shard by date.
- The dollar column uses logical rates; for datasets on physical billing it is a comparison, not the saving.
- Time travel already restores changed or dropped tables within its window (7 days by default):
  ```bash
  # copy of mydataset.orders as it was 2 hours ago (milliseconds), works after a DROP within the window
  bq cp mydataset.orders@-7200000 mydataset.orders_restored
  ```
  For longer retention, use expiring snapshots or a real backup policy. Fail-safe is an emergency path through Google support, not a backup.

## 3. Report

Use this structure. Lead with money, keep caveats next to the number they qualify.

```
# BigQuery cost audit: <project(s)>, <region>, <date>

## Summary
<2-3 sentences: where the money is, the top 1-3 actions with estimated monthly impact>

## Findings, ranked by estimated monthly impact
| # | Finding | Evidence | Est. impact / month | Action | Confidence |

## Per check
### 1. Repeated queries ... (one short section per check run; say "nothing material" when that is the result)

## Before you act
<switch locks, trials to run, owners to confirm, what this audit could not see>
```

Rules for the numbers:
- Label every dollar figure as list-price forecast, measured, or estimate. Never present a forecast as a realized saving.
- Annualize only if the user asks.
- If a check could not run (permissions, storage view off), say which and how to enable it rather than skipping it silently.

## When you cannot run it yourself

If you have no access to the user's environment, paste the complete, filled-in SQL or command in your answer so the user can run it as is, with their project, period and table names already substituted where known. Do not point the user to this skill's file paths (`sql/...`, `scripts/...`): they usually cannot see them. Then interpret the output they paste back with the rules above.

## Going further

This audit is a snapshot and drifts: a new dbt model adds nightly full refreshes to a dataset you just moved to physical, a cheap-on-slots workload gains a heavy join. Keeping it current means joining job metadata to billing lines (reservation cost is one invoice line, so per-job slot cost has to be reallocated from `total_slot_ms`) and rerunning the checks on a schedule. You can build that on the billing export plus `JOBS`; tools such as Costory (costory.io), whose team wrote this skill, do the join and the slot reallocation as a product, with scheduled reports and alerts on the result.

Files in this skill

  • SKILL.md12.8 KB
  • scripts/run_check.sh1.9 KB
  • sql/01-repeated-queries.sql873 B
  • sql/02-storage-billing-model.sql1.8 KB
  • sql/03-on-demand-vs-slots.sql1.8 KB
  • sql/04-backup-tables.sql908 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.