The goal
Most SQL warehouses are sized once, at creation, by guesswork. The result is either a Large warehouse running one dashboard query at a time, or a Small one that spills to disk and queues every Monday morning. The two settings fix different problems:
| Setting | What it changes | Fixes |
|---|---|---|
| Cluster size (2X-Small to 4X-Large) | Compute per cluster, so speed of each individual query | Slow single queries, disk spill, large scans and joins |
| Max clusters | How many clusters can run at once | Queries queuing because too many run concurrently |
| Min clusters | Clusters kept warm while the warehouse runs | Scale-up delay at predictable peaks |
| Auto stop | Idle time before the warehouse stops | Paying for idle compute |
Rule of thumb: spill and long execution mean size up; queueing means scale out. Doing the opposite costs money and does not help. This post shows how to measure both from system tables before you touch the settings.
Tip
You need
SELECTonsystem.queryandsystem.compute. If those tables are empty or denied, enable the schemas first (see the system tables access post).
1. Record the current configuration
databricks warehouses list --output json | \
jq -r '.[] | [.id, .name, .warehouse_type, .enable_serverless_compute, .cluster_size, .min_num_clusters, .max_num_clusters, .auto_stop_mins] | @tsv'
Save the output. You will want it for the rollback and to compare cost before and after.
2. Is the warehouse queueing? (scale-out signal)
waiting_at_capacity_duration_ms is time a query waited because every cluster was busy. waiting_for_compute_duration_ms is time waiting for compute to start or scale up.
SELECT date_trunc('hour', start_time) AS hour,
count(*) AS queries,
percentile(waiting_at_capacity_duration_ms, 0.95) / 1000 AS p95_queued_s,
percentile(waiting_for_compute_duration_ms, 0.95) / 1000 AS p95_compute_wait_s,
percentile(execution_duration_ms, 0.95) / 1000 AS p95_exec_s
FROM system.query.history
WHERE compute.warehouse_id = '<warehouse-id>'
AND start_time > now() - INTERVAL 14 DAYS
GROUP BY 1
ORDER BY p95_queued_s DESC
LIMIT 48;
How to read it:
- p95 queued in seconds at peak hours: raise
max_num_clusters, but only after step 4 confirms the warehouse actually hit its max. - p95 compute wait high at the first hour of the day: the warehouse is cold-starting or scaling. Serverless starts much faster than pro or classic; alternatively raise
min_num_clustersfor that window or schedule a warm-up query. - Neither high, but users still complain: the problem is per-query speed. Go to step 3.
3. Are queries spilling or just big? (size-up signal)
SELECT statement_id,
executed_by,
execution_duration_ms / 1000 AS exec_s,
read_bytes / 1e9 AS read_gb,
spilled_local_bytes / 1e9 AS spilled_gb,
left(statement_text, 100) AS sql
FROM system.query.history
WHERE compute.warehouse_id = '<warehouse-id>'
AND start_time > now() - INTERVAL 7 DAYS
AND execution_status = 'FINISHED'
ORDER BY spilled_local_bytes DESC
LIMIT 25;
Then summarise how widespread spill is:
SELECT count(*) AS queries,
count_if(spilled_local_bytes > 0) AS spilling_queries,
round(100 * count_if(spilled_local_bytes > 0) / count(*), 1) AS pct_spilling,
percentile(execution_duration_ms, 0.5) / 1000 AS p50_exec_s,
percentile(execution_duration_ms, 0.95) / 1000 AS p95_exec_s
FROM system.query.history
WHERE compute.warehouse_id = '<warehouse-id>'
AND start_time > now() - INTERVAL 7 DAYS;
| Finding | Action |
|---|---|
| Many queries spill, from many users | Increase cluster size by one step |
| Two or three queries spill, always the same SQL | Fix those queries (filters, joins, file layout) or give them their own warehouse |
No spill, long execution, huge read_gb | Data layout problem: pruning, clustering, statistics. A bigger size only partially helps |
| No spill, short execution, slow for users | Look at queueing (step 2) or client-side fetch time, not size |
Open the query profile for the worst offenders before resizing. A missing filter on a fact table looks like a sizing problem but isn't one.
4. Did the warehouse actually reach max clusters?
system.compute.warehouse_events logs starts, stops and scaling. Event type names can change over time; check with SELECT DISTINCT event_type in your workspace.
SELECT event_time, event_type, cluster_count
FROM system.compute.warehouse_events
WHERE warehouse_id = '<warehouse-id>'
AND event_time > now() - INTERVAL 14 DAYS
AND event_type IN ('SCALED_UP', 'SCALED_DOWN', 'STARTING', 'STOPPED')
ORDER BY event_time DESC
LIMIT 200;
How often and for how long did it sit at max?
WITH ev AS (
SELECT event_time, cluster_count,
lead(event_time) OVER (ORDER BY event_time) AS next_time
FROM system.compute.warehouse_events
WHERE warehouse_id = '<warehouse-id>'
AND event_time > now() - INTERVAL 14 DAYS
)
SELECT cluster_count,
round(sum(timestampdiff(SECOND, event_time, coalesce(next_time, now()))) / 3600, 1) AS hours
FROM ev
GROUP BY cluster_count
ORDER BY cluster_count;
- Hours at
cluster_count = max_num_clustersthat line up with queueing from step 2: raising max will help. - Never reaches max but queries still queue: concurrency is not the bottleneck. Look for a few long queries holding slots (see the runaway queries post) and set
STATEMENT_TIMEOUT. - Mostly at 1 cluster with max set to 10: max is harmless (you only pay for clusters that run), but min may be too high. Check
min_num_clusters.
5. Change the settings
warehouses edit replaces the editable settings, so start from the current definition and change only what you need:
WH=<warehouse-id>
databricks warehouses get $WH --output json | \
jq '{name, cluster_size, min_num_clusters, max_num_clusters, auto_stop_mins,
enable_photon, enable_serverless_compute, warehouse_type, spot_instance_policy, tags}
| .max_num_clusters = 4' > wh-edit.json
databricks warehouses edit $WH --json @wh-edit.json
databricks warehouses get $WH --output json | jq '{cluster_size, min_num_clusters, max_num_clusters, auto_stop_mins}'
Warning
Changing
cluster_sizeon a running warehouse restarts its clusters. Running queries can fail and dashboards show errors until it is back. Make size changes outside business hours, or announce them. Changing max clusters does not restart running clusters.
Caution
Each step up in cluster size costs more DBUs per hour per cluster, and max clusters multiplies that at peak. Check the current DBU rates for your warehouse type and size before changing both at once, and set a budget alert.
For pro and classic warehouses, more clusters or bigger sizes also consume Azure vCPU quota in your subscription. Check regional quota before raising max, or scaling fails at exactly the moment you need it.
6. Verify after a week
Rerun steps 2 and 3 for the seven days after the change and compare cost:
SELECT date(usage_date) AS day, round(sum(usage_quantity), 1) AS dbus
FROM system.billing.usage
WHERE usage_metadata.warehouse_id = '<warehouse-id>'
AND usage_date > current_date() - INTERVAL 21 DAYS
GROUP BY 1
ORDER BY 1;
Keep the change if p95 queue or execution time dropped meaningfully for the extra DBUs. If not, roll back using the configuration saved in step 1.
Sizing patterns that work
| Workload | Starting point |
|---|---|
| BI dashboards, many users, small queries | Small or Medium size, min 1, max sized from peak queueing; serverless for fast start |
| Ad hoc analysts with heavy joins | Larger size, low max; separate from dashboard warehouse |
| Scheduled ELT in SQL | Dedicated warehouse, short auto stop, size from spill evidence |
| Power BI import refreshes | Dedicated warehouse so refresh bursts don't queue interactive users |
Prevent it next time
- Review steps 2 to 4 monthly for each warehouse; put the queries on a Databricks SQL dashboard.
- Split warehouses by workload type rather than growing one shared warehouse.
- Set
STATEMENT_TIMEOUTso a single bad query cannot hold capacity for hours. - Tag every warehouse with team and cost centre so the cost of a resize is visible to its owner.
- Manage warehouse settings in Terraform or bundles so changes are reviewed and reversible.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get