Bird
Raised Fist0
Snowflakecloud~5 mins

Credit usage monitoring in Snowflake - Commands & Configuration

Choose your learning style10 modes available
Introduction
Snowflake charges based on credits used for compute resources. Monitoring credit usage helps control costs and avoid surprises on your bill.
When you want to track how many credits your team or project is using daily.
When you need to set alerts before your credit usage exceeds budget limits.
When you want to analyze which warehouses consume the most credits.
When you want to optimize warehouse sizes or schedules based on usage patterns.
When you want to report credit usage to management regularly.
Commands
Select the warehouse to run queries that will check credit usage.
Terminal
USE WAREHOUSE COMPUTE_WH;
Expected OutputExpected
Warehouse changed.
Query the last 7 days of credit usage per warehouse to see daily consumption.
Terminal
SELECT WAREHOUSE_NAME, SUM(CREDITS_USED) AS TOTAL_CREDITS, DATE_TRUNC('day', START_TIME) AS DAY FROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY WHERE START_TIME >= DATEADD(day, -7, CURRENT_TIMESTAMP()) GROUP BY WAREHOUSE_NAME, DAY ORDER BY DAY DESC;
Expected OutputExpected
WAREHOUSE_NAME | TOTAL_CREDITS | DAY COMPUTE_WH | 12.5 | 2024-06-20 COMPUTE_WH | 10.0 | 2024-06-19 ANALYTICS_WH | 8.0 | 2024-06-20 ANALYTICS_WH | 7.5 | 2024-06-19
Get total credits used across all warehouses in the last 7 days for overall cost monitoring.
Terminal
SELECT SUM(CREDITS_USED) AS WEEKLY_CREDITS FROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY WHERE START_TIME >= DATEADD(day, -7, CURRENT_TIMESTAMP());
Expected OutputExpected
WEEKLY_CREDITS 38.0
Calculate average daily credit usage per warehouse over the last 30 days to identify heavy users.
Terminal
SELECT WAREHOUSE_NAME, AVG(CREDITS_USED) AS AVG_DAILY_CREDITS FROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY WHERE START_TIME >= DATEADD(day, -30, CURRENT_TIMESTAMP()) GROUP BY WAREHOUSE_NAME ORDER BY AVG_DAILY_CREDITS DESC;
Expected OutputExpected
WAREHOUSE_NAME | AVG_DAILY_CREDITS COMPUTE_WH | 11.2 ANALYTICS_WH | 7.8
Key Concept

If you remember nothing else from this pattern, remember: querying the WAREHOUSE_METERING_HISTORY view lets you track credit usage over time to control costs.

Common Mistakes
Querying credit usage without filtering by recent dates.
This returns all historical data, which can be huge and slow, making it hard to see current usage.
Always filter by a recent time window like the last 7 or 30 days to get relevant data.
Not grouping credit usage by warehouse or day.
This hides which warehouses or days used the most credits, making it hard to optimize.
Group by warehouse and day to see detailed usage patterns.
Summary
Use the SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY view to monitor credit usage.
Filter queries by recent dates to focus on current usage and avoid large data scans.
Group results by warehouse and day to identify usage patterns and optimize costs.

Practice

(1/5)
1. What is the main purpose of monitoring credit usage in Snowflake?
easy
A. To control and optimize Snowflake costs
B. To increase the number of warehouses automatically
C. To backup data to external storage
D. To improve query performance by caching

Solution

  1. Step 1: Understand credit usage concept

    Credit usage monitoring tracks how many credits Snowflake consumes, which directly affects billing.
  2. Step 2: Identify the goal of monitoring

    The goal is to control and optimize costs by understanding usage patterns.
  3. Final Answer:

    To control and optimize Snowflake costs -> Option A
  4. Quick Check:

    Credit monitoring = Cost control [OK]
Hint: Credit usage monitoring helps manage costs effectively [OK]
Common Mistakes:
  • Confusing credit monitoring with performance tuning
  • Thinking it automatically scales warehouses
  • Assuming it backs up data
2. Which Snowflake view provides detailed credit usage information for warehouses?
easy
A. INFORMATION_SCHEMA.TABLES
B. ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY
C. ACCOUNT_USAGE.LOGIN_HISTORY
D. SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY

Solution

  1. Step 1: Identify views related to credit usage

    ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY tracks credit consumption by warehouses.
  2. Step 2: Exclude unrelated views

    INFORMATION_SCHEMA.TABLES shows table info, LOGIN_HISTORY tracks logins, QUERY_HISTORY tracks queries but not credit usage.
  3. Final Answer:

    ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY -> Option B
  4. Quick Check:

    Warehouse credit data = WAREHOUSE_METERING_HISTORY [OK]
Hint: Warehouse credit data is in WAREHOUSE_METERING_HISTORY view [OK]
Common Mistakes:
  • Choosing QUERY_HISTORY which tracks queries, not credits
  • Confusing LOGIN_HISTORY with credit usage
  • Selecting INFORMATION_SCHEMA views unrelated to credits
3. What will the following query return?
SELECT WAREHOUSE_NAME, SUM(CREDITS_USED) AS TOTAL_CREDITS FROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY GROUP BY WAREHOUSE_NAME ORDER BY TOTAL_CREDITS DESC;
medium
A. List of warehouses with their current running queries
B. Total credits used by each user in the account
C. Total credits used by each warehouse, sorted from highest to lowest
D. A syntax error due to missing WHERE clause

Solution

  1. Step 1: Analyze the SELECT and GROUP BY

    The query sums credits used grouped by warehouse name.
  2. Step 2: Understand ORDER BY clause

    Ordering by TOTAL_CREDITS DESC sorts warehouses from highest to lowest credit usage.
  3. Final Answer:

    Total credits used by each warehouse, sorted from highest to lowest -> Option C
  4. Quick Check:

    SUM credits by warehouse, ordered DESC = Total credits used by each warehouse, sorted from highest to lowest [OK]
Hint: GROUP BY warehouse sums credits; ORDER BY DESC sorts high to low [OK]
Common Mistakes:
  • Thinking it shows user credit usage
  • Assuming it lists running queries
  • Believing missing WHERE causes syntax error
4. You run this query but get no results:
SELECT WAREHOUSE_NAME, SUM(CREDITS_USED) FROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY WHERE START_TIME > CURRENT_DATE() GROUP BY WAREHOUSE_NAME;

What is the likely cause?
medium
A. Missing GROUP BY clause
B. Syntax error due to missing alias for SUM
C. Incorrect table name used
D. No credit usage recorded today yet

Solution

  1. Step 1: Check the WHERE condition

    Filtering START_TIME > CURRENT_DATE() means only today's data is shown.
  2. Step 2: Consider data availability

    If no credits used today yet, query returns empty result, not error.
  3. Final Answer:

    No credit usage recorded today yet -> Option D
  4. Quick Check:

    Empty result = no data matching date filter [OK]
Hint: Empty results often mean no data matches the filter [OK]
Common Mistakes:
  • Assuming missing alias causes error
  • Thinking table name is wrong
  • Believing GROUP BY is missing
5. You want to monitor credit usage by service type (e.g., WAREHOUSE, CLOUD_SERVICES) for the last 7 days. Which query correctly achieves this?
hard
A. SELECT SERVICE_TYPE, SUM(CREDITS_USED) AS TOTAL_CREDITS FROM SNOWFLAKE.ACCOUNT_USAGE.METERING_HISTORY WHERE START_TIME >= DATEADD(day, -7, CURRENT_DATE()) GROUP BY SERVICE_TYPE ORDER BY TOTAL_CREDITS DESC;
B. SELECT SERVICE_TYPE, SUM(CREDITS_USED) FROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY WHERE START_TIME >= DATEADD(day, -7, CURRENT_DATE()) GROUP BY SERVICE_TYPE;
C. SELECT WAREHOUSE_NAME, SUM(CREDITS_USED) FROM SNOWFLAKE.ACCOUNT_USAGE.METERING_HISTORY WHERE START_TIME >= DATEADD(day, -7, CURRENT_DATE()) GROUP BY WAREHOUSE_NAME;
D. SELECT SERVICE_TYPE, CREDITS_USED FROM SNOWFLAKE.ACCOUNT_USAGE.METERING_HISTORY WHERE START_TIME >= DATEADD(day, -7, CURRENT_DATE());

Solution

  1. Step 1: Identify correct view for service type credit data

    ACCOUNT_USAGE.METERING_HISTORY contains credit usage by service type; WAREHOUSE_METERING_HISTORY is only for warehouses.
  2. Step 2: Check query filters and grouping

    Filtering last 7 days with DATEADD and grouping by SERVICE_TYPE is correct; ordering by total credits helps see highest usage.
  3. Final Answer:

    SELECT SERVICE_TYPE, SUM(CREDITS_USED) AS TOTAL_CREDITS FROM SNOWFLAKE.ACCOUNT_USAGE.METERING_HISTORY WHERE START_TIME >= DATEADD(day, -7, CURRENT_DATE()) GROUP BY SERVICE_TYPE ORDER BY TOTAL_CREDITS DESC; -> Option A
  4. Quick Check:

    Use METERING_HISTORY + SERVICE_TYPE + last 7 days = SELECT SERVICE_TYPE, SUM(CREDITS_USED) AS TOTAL_CREDITS FROM SNOWFLAKE.ACCOUNT_USAGE.METERING_HISTORY WHERE START_TIME >= DATEADD(day, -7, CURRENT_DATE()) GROUP BY SERVICE_TYPE ORDER BY TOTAL_CREDITS DESC; [OK]
Hint: Use METERING_HISTORY view and group by SERVICE_TYPE for service credit usage [OK]
Common Mistakes:
  • Using WAREHOUSE_METERING_HISTORY for service types
  • Not grouping by SERVICE_TYPE
  • Selecting credits without aggregation
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard