dwhat

Free tool · Snowflake

Audit a Snowflake CSV export, privately, in your browser

Run one query on your account's usage history, download the result as CSV and choose the file below. This page works out the last 30 days of compute credits by user, dbt model and dashboard, the days that spiked, and the 20 most expensive queries with fix hints — without an account, a credential, or the file leaving your computer.

Nothing is uploaded. The file is read by this page's own JavaScript and the audit is drawn in the page; there is no request that sends it anywhere, which your browser's network tab will confirm. Close the tab and it is gone. dwhat counts visits to this page and nothing else.

What it prices, and what it does not

1. Export the query history

Export query
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())
  1. Run it in a Snowsight worksheet, on any warehouse. It reads SNOWFLAKE.ACCOUNT_USAGE, which needs ACCOUNTADMIN or a role granted the SNOWFLAKE database roles USAGE_VIEWER (for QUERY_ATTRIBUTION_HISTORY) and GOVERNANCE_VIEWER (for QUERY_HISTORY). It is a query like any other, billed to that warehouse.
  2. Download the results as CSV from the results pane.
  3. One account per export. Snowflake attributes credits to queries up to eight hours late, so the most recent hours may be missing.

2. Choose the file

An export made with the Snowflake query on /audit works too: it is the same query.

3. Optional: why does warehouse compute exceed query cost?

Snowflake bills a warehouse for every second it runs, whether or not a query is running on it.WAREHOUSE_METERING_HISTORY records what each warehouse metered; QUERY_ATTRIBUTION_HISTORY — the export above — splits part of that across the queries that ran. The two never quite agree, and the difference is the compute no query carries. A second export, of the metering, sets them side by side, in this page.

The formula

Unattributed compute = metered compute − credits attributed to queries, by UTC day and warehouse.
It splits in two using Snowflake's own hourly figure, CREDITS_ATTRIBUTED_COMPUTE_QUERIES:idle, per Snowflake = metered − that figure; not in the query export = that figure − the export's credits.

Unattributed compute is not the same as waste. Attribution can be up to 8 hours late, very short queries (around 100 ms or less) and adaptive warehouses are left out of it, and a query that runs across midnight is counted on the day it started. Some idle time is the cost of a warehouse being ready. What this shows is where to look, not what you would save. Cloud services, storage, data transfer and serverless features are billed separately and are in neither export, so they are outside every total here.

Metering export query
SELECT
  TO_VARCHAR(TO_DATE(CONVERT_TIMEZONE('UTC', start_time)), 'YYYY-MM-DD') AS day,
  warehouse_id,
  warehouse_name,
  SUM(credits_used_compute) AS credits_used_compute,
  IFF(COUNT(*) = COUNT(credits_attributed_compute_queries),
      SUM(credits_attributed_compute_queries), NULL) AS credits_attributed_compute_queries,
  TO_VARCHAR(CONVERT_TIMEZONE('UTC', CURRENT_TIMESTAMP()), 'YYYY-MM-DD"T"HH24:MI:SS"Z"') AS exported_at
FROM snowflake.account_usage.warehouse_metering_history
WHERE start_time >= DATEADD(day, -32, CURRENT_TIMESTAMP())
  AND TO_DATE(CONVERT_TIMEZONE('UTC', start_time))
      >= DATEADD(day, -30, TO_DATE(CONVERT_TIMEZONE('UTC', CURRENT_TIMESTAMP())))
  AND TO_DATE(CONVERT_TIMEZONE('UTC', start_time))
      < TO_DATE(CONVERT_TIMEZONE('UTC', CURRENT_TIMESTAMP()))
GROUP BY 1, 2, 3
ORDER BY 1, 3
  1. Run it in the same account, straight after the query export above, and download the results as CSV. It readsWAREHOUSE_METERING_HISTORY, which the same USAGE_VIEWER role can read.
  2. Dates: it adds metering up by UTC day, for the 30 whole UTC days before today. The query export starts and ends partway through a day, so its first and last UTC days are left out, and only days both exports cover in full are compared. Run both after 8:00 UTC, or yesterday is left out too, because its attribution may still be arriving.
  3. Warehouses are matched by warehouse_id, which both exports carry, so a warehouse renamed during the month is still one warehouse. An older query export without that column is matched by name, and a warehouse dropped and created again under the same name is then left out and said to be.

The synthetic example is a made-up pair of exports — three fictional warehouses over eight days — loaded into both steps.

Reconcile this automatically and get spike alerts

Keep it up to date

This is one export, one time. Connected with a read-only account, dwhat reads the history every few hours, adds idle warehouse time from metering, emails you when a day costs much more than usual, and builds a monthly report for finance.

Connect a read-only account for a free auditSee a sample audit first