Request a demo

BigQuery cost query · Slots and billing model

Peak and p95 BigQuery slot usage

This query computes slots in use for every second of the last week from JOBS_TIMELINE, then reports the average, 95th percentile and peak per hour. Size autoscaling for the p95, not the peak, and baseline for what runs all the time.

Runs on INFORMATION_SCHEMA metadata only · Columns checked against the Google Cloud docs in November 2026

The query

WITH per_second AS (
  SELECT
    period_start,
    SUM(period_slot_ms) / 1000 AS slots
  FROM `region-us`.INFORMATION_SCHEMA.JOBS_TIMELINE
  WHERE job_creation_time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 8 DAY)
    AND period_start >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)
    AND (statement_type != 'SCRIPT' OR statement_type IS NULL)
  GROUP BY period_start
)
SELECT
  TIMESTAMP_TRUNC(period_start, HOUR)               AS hour,
  COUNT(*)                                          AS busy_seconds,
  ROUND(AVG(slots), 1)                              AS avg_slots_when_busy,
  ROUND(APPROX_QUANTILES(slots, 100)[OFFSET(95)])   AS p95_slots,
  ROUND(MAX(slots))                                 AS peak_slots
FROM per_second
GROUP BY hour
ORDER BY hour;

How it works

Each JOBS_TIMELINE period lasts exactly one second, so the slot milliseconds of all jobs in a period divided by 1,000 is the number of slots in use during that second. The outer query summarizes those seconds per hour with APPROX_QUANTILES.

Seconds with no running jobs have no rows, so avg_slots_when_busy averages only the busy seconds and busy_seconds tells you how many there were. An hour with a high peak but few busy seconds is a burst that autoscaling should absorb; a high p95 across many busy seconds is steady load that a baseline or commitment covers more cheaply.

Output columns

ColumnMeaning
busy_secondsSeconds in the hour with at least one job running.
avg_slots_when_busyAverage slots over the busy seconds only.
p95_slots95th percentile of slots in use per second.
peak_slotsHighest slots in use in any second of the hour.

Permissions and notes

Needs: bigquery.jobs.listAll on the project, for example through the BigQuery Resource Viewer role (roles/bigquery.resourceViewer).

  • (statement_type != 'SCRIPT' OR statement_type IS NULL) drops parent rows of multi-statement queries, which repeat their children's slot time, while keeping load and copy jobs, whose statement type is NULL.
  • A week of per-second rows is a lot of data; keep the window short or add a project_id or reservation_id filter for large estates.

FAQ

Should I set the autoscaling maximum to my peak?

Usually not. Peaks a few seconds long cost little to queue, while a maximum sized for them lets every burst scale up and bill at least a minute per step. The p95 is a better starting point.

What is a good baseline?

Slots you use nearly every second of the day. Baseline slots bill around the clock, so baseline above that floor is idle capacity.

All BigQuery cost queries · Data FinOps playbook · Pricing calculator

Cut BigQuery spend without guessing

Masthead attributes compute and storage cost to every project, user, pipeline and table, finds unused and dead-end tables, and shows where editions or on-demand pricing is cheaper. Mnemonic cut its BigQuery compute cost by 20% within 24 hours of onboarding.