Free audit
Connect a read-only account for a free audit
Give dwhat a read-only account on BigQuery or Snowflake. It reads the last 45 days of query history and shows you where the money went: by user, by dbt model, by dashboard, day by day — and the 20 queries that cost the most, with what to change in each.
Need someone else to set up the read-only account? Ask your warehouse admin.
Rather check by hand first? Why did the warehouse bill go up?has the SQL for both warehouses, and the other guides answer one question each.
What the audit shows
- Compute cost for each of the last 45 days, and how much of it was idle warehouse time (Snowflake).
- That cost split by warehouse user, by dbt model and by dashboard.
- The 20 most expensive queries, with identical queries grouped together, and a fix hint where the evidence supports one.
- A monthly report you can print or download as CSV for finance.
After the audit the connection keeps working: it syncs every few hours, and emails you when a day costs much more than usual.
What dwhat can and cannot see
Reads
- Query history: who ran what, when, and what it cost the warehouse.
- The text of each query, cut to 20,000 characters.
- Warehouse metering, on Snowflake.
Cannot
- Read a single row of your tables. The roles below grant no data access.
- Create, change or drop anything.
- Sign in as anyone but the account you create for it.
Credentials are encrypted before they are stored, and never shown again. Query history is kept for 400 days and deleted with the connection. Remove the account on your side and dwhat can read nothing more.
Ask your warehouse admin
Can't create roles and service users yourself? Copy a request for the colleague who can. It links toa page written for them — exactly what dwhat reads, where credentials are kept, how long history is kept, how to revoke access and what it costs — and says what to run and what to tell you. They need no dwhat account.
For BigQuery, the service-account key is a credential: ask for it through your team's approved secret-sharing process, and enter it only in the signed-in connection form — never in the request. For Snowflake, add the connection first: its page has the same request with the setup script and its public key filled in.
Snowflake
Run this as ACCOUNTADMIN. It creates a role that can read account usage and nothing else, a small warehouse for that role, and a service user with no password. dwhat generates the key pair: when you add the connection, the public key is filled into this script for you.
USE ROLE ACCOUNTADMIN; -- A role that can read account usage, and nothing else. CREATE ROLE IF NOT EXISTS DWHAT_READER; GRANT DATABASE ROLE SNOWFLAKE.USAGE_VIEWER TO ROLE DWHAT_READER; GRANT DATABASE ROLE SNOWFLAKE.GOVERNANCE_VIEWER TO ROLE DWHAT_READER; -- Its own X-Small warehouse, suspended after a minute idle, -- so reading the history costs a few minutes of X-Small a day. CREATE WAREHOUSE IF NOT EXISTS DWHAT_XS WAREHOUSE_SIZE = XSMALL AUTO_SUSPEND = 60 AUTO_RESUME = TRUE INITIALLY_SUSPENDED = TRUE; GRANT USAGE ON WAREHOUSE DWHAT_XS TO ROLE DWHAT_READER; -- A service user with no password: it signs in with a key pair only. CREATE USER IF NOT EXISTS DWHAT_READER TYPE = SERVICE DEFAULT_ROLE = DWHAT_READER DEFAULT_WAREHOUSE = DWHAT_XS RSA_PUBLIC_KEY = '<the public key shown on your connection page>'; GRANT ROLE DWHAT_READER TO USER DWHAT_READER;
Cost per query comes from Snowflake's QUERY_ATTRIBUTION_HISTORY, which lags by up to eight hours and leaves out very short queries and idle time. dwhat shows idle time separately, from warehouse metering, so the daily total still matches compute on the invoice. To see that gap before connecting,reconcile warehouse metering with query credits from two CSV exports, in your browser.
Planning a size or schedule? Estimate Snowflake warehouse cost and compare a resize. Weighing a shorter or longer auto-suspend delay? Model both first with theSnowflake auto-suspend calculator.
BigQuery
Create a service account with two roles on the project — BigQuery Resource Viewer to see everybody's jobs, and BigQuery Job User to run the query that reads them — and a JSON key for it. With the gcloud CLI:
PROJECT=your-project-id SA=dwhat-reader@$PROJECT.iam.gserviceaccount.com gcloud iam service-accounts create dwhat-reader \ --project=$PROJECT --display-name="dwhat (read-only)" # Sees everybody's job metadata in the project. No table data. gcloud projects add-iam-policy-binding $PROJECT \ --member="serviceAccount:$SA" --role=roles/bigquery.resourceViewer # Runs the one query that reads that metadata. gcloud projects add-iam-policy-binding $PROJECT \ --member="serviceAccount:$SA" --role=roles/bigquery.jobUser gcloud iam service-accounts keys create dwhat-key.json --iam-account=$SA
dwhat reads INFORMATION_SCHEMA.JOBS_BY_PROJECT for one project and one region. Reading it is a small query of its own, billed to the project like any other — a few a day.
Jobs spread over several projects? See them side by side first with themulti-project cost SQL generator.
Deciding how often a dashboard should refresh before it exists? Estimate it with theBigQuery recurring query cost calculator, which you can also put in an article: embed it.
Weighing on-demand against capacity (slot) pricing? Put the two side by side with theBigQuery on-demand vs capacity break-even worksheet. The audit estimates on-demand compute from your query history; it does not reconcile a capacity invoice.
Want one query to stop before it costs more than a budget? Get the byte ceiling and the code with theBigQuery maximum bytes billed calculator.
Rather not share credentials?
Run one of these yourself, save the result as CSV, and upload it. You get the same audit for those 30 days; it just does not update or alert afterwards.
Rather not upload anything either? Audit the export in your browser —BigQuery on-demand or Snowflake: no account, and the file never leaves it. To explain a change in spend, compare two periods of the same exportbefore and after.
BigQuery export (change region-us to your region)
SELECT
job_id,
FORMAT_TIMESTAMP('%Y-%m-%dT%H:%M:%E3SZ', creation_time) AS creation_time,
user_email,
statement_type,
SUBSTR(query, 1, 20000) AS query,
TO_JSON_STRING(labels) AS labels,
total_bytes_billed,
total_bytes_processed,
total_slot_ms,
TIMESTAMP_DIFF(end_time, start_time, MILLISECOND) AS elapsed_ms,
cache_hit
FROM `region-us`.INFORMATION_SCHEMA.JOBS_BY_PROJECT
WHERE creation_time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
AND job_type = 'QUERY' AND state = 'DONE'
AND IFNULL(statement_type, '') != 'SCRIPT'
AND (IFNULL(total_bytes_billed, 0) > 0 OR IFNULL(total_slot_ms, 0) > 0)Snowflake export
SELECT a.query_id, TO_VARCHAR(a.start_time, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZH:TZM') AS start_time, a.user_name, a.warehouse_name, a.warehouse_id, q.query_type, LEFT(q.query_text, 20000) AS query_text, a.query_tag, q.bytes_scanned, a.credits_attributed_compute, q.total_elapsed_time, q.bytes_spilled_to_remote_storage, q.partitions_scanned, q.partitions_total FROM snowflake.account_usage.query_attribution_history a LEFT JOIN snowflake.account_usage.query_history q ON q.query_id = a.query_id AND q.start_time >= DATEADD(day, -31, CURRENT_TIMESTAMP()) WHERE a.start_time >= DATEADD(day, -30, CURRENT_TIMESTAMP())
Getting dbt models and dashboards attributed
Neither warehouse records which model or dashboard a query came from; the tools leave marks, and dwhat reads them. It recognises dbt's default query comment (and its BigQuery job labels), Looker Studio's job labels, and the comments Looker and Metabase add to their SQL. For anything else, add a dashboard label to the BigQuery job, or set a Snowflake QUERY_TAG such as {"dashboard": "Revenue daily"}. Queries with no mark are shown as unattributed rather than guessed.
Not sure your queries carry a mark? Paste a query, its job labels or its query tag into thequery attribution checker and see what the audit would recognise — in your browser, with no account.