Monitoring Credit Usage with Budgets

Budgets enable account-level monitoring and notification of Snowflake credit usage for a group of specific Snowflake objects.

Budgets Overview

A budget defines a monthly spending limit on the compute costs for a Snowflake account or a custom group of Snowflake objects. When the spending limit is projected to be exceeded, a daily notification email is sent to the email addresses designated to receive budget notifications.

Note

Budgets requires the 2023_06 Bundle. This bundle is currently enabled by default in all accounts. If your account is in a region that supports Budgets, and you have explicitly disabled the bundle, Budgets will not be available until you enable the bundle.

Account Budget and Custom Budgets

To start using budgets in Snowflake, activate the account budget. The account budget monitors spending for all supported objects in the account. To get notifications for the budget, set up the spending limit and specify email addresses to receive notifications.

You can also create custom budgets to monitor the spending limits for a specific group of supported objects. You can create a custom budget in any database and schema. Like the account budget, you must set the spending limit and the notification email addresses in order to receive notification emails.

Spending Limit and Time Interval

The spending limit is expressed in Snowflake credits and is used for alerting and notifications purposes only. The spending limit is set for the time interval of one calendar month.

The time interval starts at 12:00AM UTC on the first day of the month and ends at 11:59PM UTC on the last day of the month. If a budget is created after the first day of the month, the first monitoring interval is the period until the last day of the current month, then is reset on the first of the following month.

If you activate your account budget after the first of the month, data starting from the beginning of the month is backfilled and used to determine if you are going to exceed your spending limit for the month.

If you create a custom budget after the first of the month, historical data for the month is not backfilled. Forecasting for future spend is based on the credit usage in the days only after the budget is enabled.

Note

If you create a custom budget after the first of the month, you might exceed your budget for the first month. In a partial month, credit usage before the budget is created is not backfilled for custom budgets and might result in incorrect forecasting. Subsequent months will correctly forecast credit usage based on spending history.

Supported Objects

The list of supported objects all contribute to the spending limit for the account budget. For a custom budget, you can select specific objects to monitor.

The following objects are supported for monitoring by a budget:

  • Tables

  • Materialized views

  • Schemas

  • Databases

  • Warehouses

  • Pipes

  • Tasks

Supported Serverless Features

Budgets monitors the serverless feature credit usage for the supported objects contained in a budget. The following serverless features are supported:

Serverless Feature

Object

AUTO_CLUSTERING

Table

MATERIALIZED_VIEW

Table

PIPE

Pipe

QUERY_ACCELERATION

Warehouse

SEARCH_OPTIMIZATION

Table

SERVERLESS_TASK

Task

SNOWPIPE_STREAMING

Pipe

WAREHOUSE_METERING

Warehouse

WAREHOUSE_METERING_READER

Warehouse

Notifications

A budget sends a daily alert notification when current spending is on track to exceed the spending limit based on time-series forecasting. To receive automatic alert notifications, you must:

  • Set a spending limit for the budget.

  • Set up email notifications for the budget.

The following is an example of a notification email:

Example Budgets Email

Budget Roles and Privileges

You can grant roles and privileges to a custom role to grant the ability to create new budgets, modify an existing budget, and monitor a budget.

Required Roles and Privileges to Create Budgets

Note

Only a user with the ACCOUNTADMIN role can activate the account budget.

You can use a custom role to create custom budgets in your account. The custom role must be granted:

  • The SNOWFLAKE database role SNOWFLAKE.BUDGET_CREATOR.

  • The CREATE SNOWFLAKE.CORE.BUDGET privilege on the schema in which to create the budget.

For example, create a budget_admin role and grant the required role and privileges to create custom budgets in schema budgets_db.budgets_schema:

CREATE ROLE budget_admin;

GRANT DATABASE ROLE SNOWFLAKE.BUDGET_CREATOR TO ROLE budget_admin;

GRANT USAGE ON SCHEMA budgets_db.budgets_schema TO ROLE budget_admin;

GRANT CREATE SNOWFLAKE.CORE.BUDGET ON SCHEMA budgets_db.budgets_schema
  TO ROLE budget_admin;
Copy

Application Roles to Manage the Account Budget

You can grant the following application roles to a custom role in your account to modify or monitor the account budget.

Application Role

Description

BUDGET_VIEWER

Enables a role to view budget usage data.

BUDGET_ADMIN

Enables a role to modify the properties of a budget including spending limit, the list of email addresses to receive notifications, and the mute notifications setting.

Examples

Note

Only a user with the ACCOUNTADMIN role can execute the following examples.

Grant the custom role budget_admin the ability to modify the account budget:

GRANT APPLICATION ROLE SNOWFLAKE.BUDGET_ADMIN TO ROLE budget_admin;
Copy

Grant the custom role budget_monitor the ability to view budget usage data:

GRANT APPLICATION ROLE SNOWFLAKE.BUDGET_VIEWER TO ROLE budget_monitor;
Copy

Instance Roles to Manage Custom Budgets

Each custom budget has instance roles that can be granted to other roles to view or modify the budget:

Instance Role

Description

VIEWER

Enables a role to view budget usage data.

ADMIN

Enables a role to modify the properties of a budget including spending limit, list of email addresses to receive notifications, mute notifications setting, and the objects in the group.

Note

Currently, you can only modify objects in a custom budget using SQL commands.

Examples

Note

Only the role that created the budget instance can execute the following example.

Grant the custom role budget_admin the ability to modify the budget my_budget in schema budgets_db.budgets_schema:

GRANT SNOWFLAKE.CORE.BUDGET ROLE budgets_db.budgets_schema.my_budget!ADMIN
  TO ROLE budget_admin;
Copy

Understanding Cost for Budgets

To support the Budgets feature, Snowflake stores metadata in the SNOWFLAKE database. This metadata is stored in your account even if the account budget is not activated. Storage for this metadata is billed to your account.

When the Budgets feature is enabled, Snowflake runs serverless background tasks (_MEASUREMENT_TASK and _BACKFILL_TASK) that collect credit usage data for the account budget and custom budgets in your account. These tasks are billed to your account.

Data collected by budgets background tasks is stored in the SNOWFLAKE database for the account budget. Storage for the data is billed to your account.

Exploring Costs

You can view costs for serverless tasks using Snowsight or the Account Usage SERVERLESS_TASK_HISTORY View. For more information on viewing costs based on service type, see Exploring Compute Cost.

You can view costs for storage using Snowsight or by querying Account Usage and Organization Usage views. For more information on viewing storage costs, see Exploring Storage Cost.

Enable Budgets for Your Account

To enable budgets for your account, activate the account budget.

Activate the Account Budget

Activate the account budget, set the spending limit for the account, and provide the email addresses to receive notifications when credit usage exceeds the spending limit.

You can activate the account budget by using Snowsight or SQL.

Note

  • Only account administrators can activate the account budget.

  • Once you activate the account budget, you cannot deactivate it.

Activate and Set up the Account Budget Using Snowsight

  1. Sign in to Snowsight.

  2. Select Admin » Usage

  3. Select Budgets.

  4. If prompted, select a warehouse.

  5. In the upper-right corner of the dashboard, select Set up Account Budget.

  6. Enter the target spending limit for the account.

  7. Enter the email addresses to receive notification emails.

    Note

    Each email address added for budget notifications must be verified. The notification email set up fails if any email address in the list is not verified.

  8. Select Finish Setup.

When you add email addresses for notifications using Snowsight, Snowflake creates an email notification integration in a background process and performs the following actions:

  • Creates a new email notification integration named default_budget_notification_integration using the email addresses you entered to receive notification emails.

  • Grants the USAGE privilege on the integration to the SNOWFLAKE application.

Activate and Set up the Account Budget Using SQL

  1. Activate the account budget using the account_root_budget!ACTIVATE method:

    CALL snowflake.local.account_root_budget!ACTIVATE();
    
    Copy
  2. Set the spending limit using the <budget_name>!SET_SPENDING_LIMIT method:

    CALL snowflake.local.account_root_budget!SET_SPENDING_LIMIT(1000);
    
    Copy
  3. Create a NOTIFICATION INTEGRATION with the email addresses to receive budget notifications.

    This step is optional. If you have an existing NOTIFICATION INTEGRATION, skip to the next step.

    CREATE NOTIFICATION INTEGRATION budgets_notification_integration
      TYPE=EMAIL
      ENABLED=TRUE
      ALLOWED_RECIPIENTS=('costadmin@example.com','budgetadmin@example.com');
    
    Copy

    Grant the USAGE privilege on the notification integration:

    GRANT USAGE ON INTEGRATION budgets_notification_integration
      TO APPLICATION snowflake;
    
    Copy

    For more information on creating a NOTIFICATION INTEGRATION, see Creating a Notification Integration.

  4. Set the email notification for the account budget:

    CALL snowflake.local.account_root_budget!SET_EMAIL_NOTIFICATIONS(
       'budgets_notification_integration',
       'costadmin@example.com, budgetadmin@example.com');
    
    Copy

Create a Custom Budget

You can create a custom budget to monitor the credit usage of specific objects in your account.

Create a Custom Budget Using Snowsight

  1. Sign in to Snowsight.

  2. Select Admin » Usage

  3. Select Budgets.

  4. In the upper-right corner of the dashboard, select sf-plus-icon-button (Add Budget).

    Note

    If you don’t see the Add Budget icon, you must first activate the account budget.

  5. Enter a Budget name.

  6. Select the database and schema in which to create your budget.

  7. Enter the Spending limit.

  8. Enter the email addresses to receive notifications.

    Note

    Each email address added for budget notifications must be verified. The notification email set up fails if any email address in the list is not verified.

  9. Select Resources to monitor.

    • To add a database, expand Databases to select a database.

    • To add objects in a schema, expand the schema to list available objects. Expand the object category (for example, Tables or Tasks) to select objects.

    • To add a warehouse, expand Warehouses and select a warehouse.

    Note

    When you select a database or schema, all supported objects (for example, tables) contained within the database or schema are also added to the budget.

When you add email addresses for notifications using Snowsight, Snowflake creates or updates an email notification integration named deault_budget_notification_integration in a background process. If the notification integration exists, Snowflake adds any new email addresses you entered to the existing email addresses in the list.

If the notification integration does not exist, Snowflake creates it and grants the USAGE privilege. For details, see the steps outlined in account budget section.

Create a Custom Budget Using SQL

Create a custom budget and then set the spending limit and notification email addresses.

Note

  • The role used to create the budget must be granted the SNOWFLAKE database role BUDGET_CREATOR and the CREATE SNOWFLAKE.CORE.BUDGET privilege. For more information, see Budget Roles and Privileges.

  • To send notifications, the SNOWFLAKE application must be granted the USAGE privilege on the notification integration:

    GRANT USAGE ON INTEGRATION budgets_notification_integration
      TO APPLICATION snowflake;
    
    Copy
  1. Review the existing budgets in your account:

    SELECT SYSTEM$SHOW_BUDGETS_IN_ACCOUNT();
    
    Copy
  2. Create budget my_budget in budgets_db.budgets_schema using the CREATE SNOWFLAKE.CORE.BUDGET command:

    USE SCHEMA budgets_db.budgets_schema;
    
    CREATE SNOWFLAKE.CORE.BUDGET my_budget();
    
    Copy
  3. Set the spending limit to 500 credits per month:

    CALL my_budget!SET_SPENDING_LIMIT(500);
    
    Copy
  4. Set the notification integration and the email addresses:

    Note

    If you do have not already created an email NOTIFICATION INTEGRATION, see the steps in the account budget section to create one.

    CALL my_budget!SET_EMAIL_NOTIFICATIONS('budgets_notification_integration',
                                           'costadmin@example.com');
    
    Copy
  5. To add objects to your custom budget, you must pass a reference to the budget’s ADD_RESOURCE method. For example, to add a table named t1 to the budget named my_budget:

    CALL budgets_db.budgets_schema.my_budget!ADD_RESOURCE(
       SYSTEM$REFERENCE('TABLE', 't1', 'SESSION', 'applybudget'));
    
    Copy

    The SYSTEM$REFERENCE statement creates a reference to a TABLE object, t1, with the APPLYBUDGET privilege granted on the table. The third parameter to the function specifies the scope for the reference, in this case ‘SESSION’ creates a reference with session scope. References passed to the ADD_RESOURCE method for a budget can be created with any transient reference scope (that is to say, the third parameter can be either ‘SESSION’ or ‘CALL’).

  6. Grant the ADMIN instance role to your custom budget_admin role:

    GRANT SNOWFLAKE.CORE.BUDGET ROLE budgets_db.budgets_schema.my_budget!ADMIN
      TO ROLE budget_admin;
    
    Copy

Monitoring Budgets Using Snowsight

Note

Only account administrators can monitor budgets using Snowsight.

You can view current and historical budget spending using the Budgets page in Snowsight.

  1. Sign in to Snowsight.

  2. Select Admin » Usage

  3. Select Budgets.

In the Current Month view for a budget, you can review the credit usage per day up to the current day. You can see whether you might exceed your budget for the month. The bar graph continues to the end of the month with your projected credit usage based on your actual credit usage for the month. The Spending limit line indicates the spending limit at which a budget notification is triggered.

Budgets projected spending graph

Select sf-clock-time-period-icon (months to display) to filter the view by Current Month or longer time periods.

You can compare the Spend (current credit usage) to Interval (time left in the current month) to see if your spending is outpacing your monthly budget.

You can filter the view by selecting Budgets icon Budgets or Resources icon Resources.

  • You can select a custom budget in the Budgets view for details on a specific budget.

  • In the Resources view, you can filter and sort by Service Type, object Name, and Credit Usage.

Limitations

  • Currently, budget notification emails do not specify which account the email notification came from.

  • Instances of the BUDGET class cannot be replicated to target accounts.

  • An account can contain a maximum of 100 custom budgets.

Troubleshooting Creating and Editing Budgets Using SQL

The following scenarios can help you troubleshoot issues that can occur when creating or editing budgets using SQL.

You cannot activate the account budget

There are multiple reasons you might be unable to activate your account budget.

Error

Unknown user-defined function SNOWFLAKE.LOCAL.ACTIVATE

Cause

If your Snowflake account is new, the account budget is not yet available in your account.

Solution

Wait for the account budget to be available in your newly created account. You can activate it once it becomes available.

Error

FAILURE: Uncaught exception of type 'BUDGET_ALREADY_ACTIVATED'
on line X at position X

Cause

The account budget has already been activated.

Solution

You can call the <budget_name>!GET_CONFIG method to view the activation timestamp:

CALL SNOWFLAKE.LOCAL.ACCOUNT_ROOT_BUDGET!GET_CONFIG();
Copy

Error

-20000 (P0001): Uncaught exception of type
'NO_PERMISSION_TO_ACTIVATE_BUDGET' on line X at position X

Cause

Your account does not yet support budgets.

Solution

The Budgets feature is available for preview in all Standard, Enterprise, and Business Critical Edition accounts in AWS regions. Budgets are not available in trial accounts.

If your account is in a supported region and supported edition but you cannot activate your account budget, contact Snowflake Support. Otherwise, support for your region will be available in a future release.

You cannot create a custom budget

There are multiple reasons you might be unable to create a custom budget.

Error

FAILURE: SQL access control error:
Insufficient privileges to operate on class 'BUDGET'

Cause

The role you are using does not have the privileges required to create custom budgets.

Solution

Use a role with the required privileges. See Required Roles and Privileges to Create Budgets.

Error

FAILURE: Uncaught exception of type 'STATEMENT_ERROR' on line 0 at
position -1 : Uncaught exception of type 'UNSUPPORTED_BUDGET_TYPE' on
line X at position X

Cause

You pass arguments to the constructor method to create a budget.

Solution

See CREATE SNOWFLAKE.CORE.BUDGET and edit your create statement.

You cannot activate a custom budget

Error

FAILURE: Uncaught exception of type 'STATEMENT_ERROR' on line 0 at
position -1 : Uncaught exception of type 'UNSUPPORTED_BUDGET_TYPE' on
line X at position X

Cause

You tried to call the ACTIVATE method on a custom budget.

Solution

The ACTIVATE method is only available on the account budget. Once you have created a custom budget, use the <budget_name>!SET_SPENDING_LIMIT and <budget_name>!SET_EMAIL_NOTIFICATIONS methods to configure the budget and start receiving notification emails.

You cannot call methods on the account budget

There are multiple reasons calling a method on the account budget might fail.

Error

-20000 (P0001): Uncaught exception of type
'FUNCTION_NOT_SUPPORTED_FOR_ACCOUNT_ROOT_BUDGET' on line 11
at position 18

Cause

You tried to call any of the following methods on the account budget:

Solution

These methods are not available on the account budget. The account budget monitors all supported objects in the account and objects cannot be added or removed. For more information, see Account Budget and Custom Budgets.

Error

-20000 (P0001): Uncaught exception of type
'ACCOUNT_ROOT_BUDGET_NOT_ACTIVATED' on line X at position X

Cause

You tried to call a method on the account budget before the account budget is activated.

Solution

Activate the account budget.

The budget feature is not available for your account

Errors

FAILURE: SQL compilation error:
Class 'SNOWFLAKE.CORE.BUDGET' does not exist or not authorized.
000002 (0A000): Uncaught exception of type 'STATEMENT_ERROR' on
line 0 at position -1 : Unsupported feature 'TOK_RESOURCE_GROUP'.

Cause

Your account does not yet support budgets.

Solution

The Budgets feature is available for preview in all Standard, Enterprise, and Business Critical Edition accounts in AWS regions. Budgets are not available in trial accounts.

If your account is in a supported region and supported edition, contact Snowflake Support. Otherwise, support for your region will be available in a future release.