How Warehouse Credits Work in Snowflake: Simple Explanation
In Snowflake,
warehouse credits measure the compute resources used by virtual warehouses. Credits are consumed based on the warehouse size and the time it runs, including when it is actively processing queries or suspended but still allocated. This billing model helps you control costs by scaling warehouses up or down and pausing them when not in use.Syntax
Snowflake does not have a direct syntax command for warehouse credits, but credits are calculated automatically based on warehouse usage. The key factors are:
- Warehouse Size: Larger warehouses consume more credits per hour.
- Running Time: Credits are charged for the time the warehouse is running or suspended but allocated.
- Credit Rate: Each warehouse size has a fixed credit consumption rate per hour.
You control credits by starting, stopping, or resizing warehouses using commands like ALTER WAREHOUSE and CREATE WAREHOUSE.
sql
CREATE WAREHOUSE my_warehouse WITH WAREHOUSE_SIZE = 'MEDIUM' AUTO_SUSPEND = 300 AUTO_RESUME = TRUE;
Example
This example shows how to create a warehouse and how credits are consumed based on its size and running time.
sql
CREATE WAREHOUSE example_wh WITH WAREHOUSE_SIZE = 'SMALL' AUTO_SUSPEND = 60 AUTO_RESUME = TRUE; -- Start the warehouse ALTER WAREHOUSE example_wh RESUME; -- Run a query SELECT CURRENT_TIMESTAMP(); -- Suspend the warehouse after inactivity ALTER WAREHOUSE example_wh SUSPEND;
Output
CURRENT_TIMESTAMP()
---------------------
2024-06-01 12:00:00.000
Common Pitfalls
Common mistakes when managing warehouse credits include:
- Leaving warehouses running when not in use, which consumes credits unnecessarily.
- Choosing a warehouse size larger than needed, increasing credit consumption.
- Not using
AUTO_SUSPENDandAUTO_RESUMEfeatures to save credits.
Always monitor warehouse usage and adjust size and suspend settings to optimize credit use.
sql
/* Wrong: Warehouse left running indefinitely */ ALTER WAREHOUSE example_wh RESUME; -- No suspend command or AUTO_SUSPEND set /* Right: Use AUTO_SUSPEND to save credits */ ALTER WAREHOUSE example_wh SET AUTO_SUSPEND = 300; ALTER WAREHOUSE example_wh RESUME;
Quick Reference
| Concept | Description |
|---|---|
| Warehouse Size | Determines credits consumed per hour (e.g., X-Small to 6X-Large) |
| Running Time | Credits charged while warehouse is running or suspended but allocated |
| Auto Suspend | Automatically pauses warehouse after inactivity to save credits |
| Auto Resume | Automatically resumes warehouse when a query is submitted |
| Credit Consumption | Calculated as (Warehouse Size Rate) × (Running Time in Hours) |
Key Takeaways
Warehouse credits are consumed based on warehouse size and running time.
Use AUTO_SUSPEND and AUTO_RESUME to minimize unnecessary credit usage.
Larger warehouses consume more credits per hour, so size wisely.
Credits are charged even when warehouses are suspended but still allocated.
Monitor and adjust warehouse settings regularly to control costs.
