Custom budgets¶
Custom budgets let you monitor compute costs for a custom group of objects. You can specify which objects you want to monitor in two ways:
Add a tag to the budget. All objects that have the specified tag/value pair are monitored by the budget.
Add each object to the budget individually.
The same budget can track objects added individually and added using tags. If an object is included in the budget for more than one reason (for example, it was added individually and has the specified tag/value pair), its credit usage counts only once against the budget’s spending limit.
When you add an object to a custom budget, the budget monitors all compute costs for the object, including background maintenance operations and serverless features. For example, if you add a table to a custom budget, and the table has automatic clustering enabled, the budget monitors credit usage for the background maintenance for automatic clustering.
Supported objects for custom budgets¶
You can create a custom budget to monitor the following types of Snowflake objects:
Object |
Monitored costs |
---|---|
Alerts |
Serverless alerts are monitored by the account budget. To monitor the credit usage for an alert that executes using a user-managed warehouse, you must add the warehouse to the budget. For more information about the costs of alerts, see Understanding the costs of alerts. |
Apps . (Snowflake Native Apps) |
The behavior of budgets for objects that are created and owned by an Snowflake Native App depends on whether you add the app directly or by adding a tag.
|
Compute pool |
Compute pool usage for Snowpark Container Services. For more information, see Compute pool cost. |
Databases |
When you add a database to a budget, all supported objects that the database contains are also automatically added. The budget monitors credit usage for the following objects and serverless features:
|
Materialized views |
Background maintenance for the materialized view. For more information, see Materialized Views Cost. |
Schemas |
When you add a schema to a budget, all supported objects that the schema contains are also automatically added. The budget monitors the credit usage for schema objects as described above. |
Pipes |
Resource consumption for loading data using Snowpipe. For more information, see Snowpipe costs. |
Tables |
Background maintenance operations for automatic clustering and search optimization if they are enabled on the table. |
Tasks |
Serverless tasks are monitored by a custom budget. To monitor the credit usage for a task that executes using a user-managed warehouse, you must add the warehouse to the budget. For more information, see Task costs. |
Warehouses |
Compute resources for query execution, web interface, and other features (see Virtual warehouse credit usage), serverless tasks, and cloud services compute. |
For more information, see Add or remove tags from a custom budget.
Create a custom budget¶
The next sections explain how to create a custom budget:
You can create a custom budget using Snowsight or by executing SQL statements.
Create a custom role to create budgets¶
You can use a custom role to create budgets in your account. For a full list of privileges and roles that must be granted to a role to create a custom budget, see Budgets roles and privileges.
The following example creates a role named budget_owner
role and grants the required role and privileges to create custom
budgets in the schema budgets_db.budgets_schema
. The example must be executed using the ACCOUNTADMIN role:
USE ROLE ACCOUNTADMIN;
CREATE ROLE budget_owner;
GRANT USAGE ON DATABASE budgets_db TO ROLE budget_owner;
GRANT USAGE ON SCHEMA budgets_db.budgets_schema TO ROLE budget_owner;
GRANT DATABASE ROLE SNOWFLAKE.BUDGET_CREATOR TO ROLE budget_owner;
GRANT CREATE SNOWFLAKE.CORE.BUDGET ON SCHEMA budgets_db.budgets_schema
TO ROLE budget_owner;
If you want to enable a role other than the budget owner to modify a custom budget’s settings, you can create a custom role with modify privileges. For more information, see Create a custom role to manage a custom budget.
Use Snowsight to create a custom budget¶
Note
If the account budget is not activated or has been deactivated, you can’t use Snowsight to create custom budgets. However, you can create custom budgets using SQL.
Sign in to Snowsight.
Select Admin » Cost Management.
Select Budgets.
Enter a Budget name.
Select the database and schema in which to create your budget.
Enter the Spending limit.
Enter the email addresses to receive notifications.
Note
Each email address added for budget notifications must be verified. The notification email setup fails if any email address in the list is not verified.
Select + Tag & resources, then add the tags and resources that you want to add to the custom budget.
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.
If you are directly adding individual objects, you can only add an object to one custom budget. In this case, if an object is currently included in one custom budget and you add that object to a second custom budget, Budgets removes the object from the first custom budget without issuing a warning. This behavior does not apply to using tags to add objects to budgets; an object with one or more tags can be included in multiple custom budgets if you are using tags to add the object to the budgets.
After you create and set up a custom budget, you can create a custom role to enable non-account administrators to monitor budget resources and usage. For more information, see Create a custom role to monitor a custom budget.
Use SQL commands to create a custom budget¶
Create a custom budget and then set the spending limit and notification email addresses.
Note
To create a custom budget, you must use a role with the required privileges to create a budget.
To modify a custom budget, you must use a role with the required privileges to modify a budget.
Review the existing budgets in your account:
Note
The following statement returns the budgets for which you have access privileges. Only a user with the ACCOUNTADMIN role can see all the budgets in the account.
SELECT SYSTEM$SHOW_BUDGETS_IN_ACCOUNT();
Create budget
my_budget
inbudgets_db.budgets_schema
using the CREATE BUDGET command:USE SCHEMA budgets_db.budgets_schema; CREATE SNOWFLAKE.CORE.BUDGET my_budget();
Set the monthly spending limit. For example, set the spending limit to 500 credits per month:
CALL my_budget!SET_SPENDING_LIMIT(500);
Set up notifications for the budget so that you receive notifications when your credit usage is expected to exceed your spending limits.
After you create and set up a custom budget, you can create a custom role to enable non-account administrators to monitor budget resources and usage. For more information, see Create a custom role to monitor a custom budget.
To add objects to your new budget, see Add or remove objects from a custom budget.
Create a custom role to manage a custom budget¶
To monitor and modify a custom budget, you can grant privileges and instance roles to a custom role. For a full list of privileges and roles that must be granted to a role to modify a custom budget, see Budgets roles and privileges.
Custom role example¶
Grant the custom role budget_admin
the ability to monitor and modify the budget my_budget
in schema
budgets_db.budgets_schema
:
Note
You need OWNERSHIP privilege on the custom budget to execute the following examples.
Grant the required privileges and instance role to custom role
budget_admin
for budgetmy_budget
in schemabudgets_db.budgets_schema
:GRANT USAGE ON DATABASE budgets_db TO ROLE budget_admin; GRANT USAGE ON SCHEMA budget_db.budgets_schema TO ROLE budget_admin; GRANT SNOWFLAKE.CORE.BUDGET ROLE budgets_db.budgets_schema.my_budget!ADMIN TO ROLE budget_admin; GRANT DATABASE ROLE SNOWFLAKE.USAGE_VIEWER TO ROLE budget_admin;
Grant the APPLYBUDGET privilege on objects and tags to be added to or removed from a custom budget. This step is required for each object or tag to be added or removed.
For example, to enable the role
budget_admin
to add databasedb1
to custom budgetmy_budget
, execute the following statements:GRANT USAGE ON DATABASE db1 TO ROLE budget_admin; GRANT APPLYBUDGET ON DATABASE db1 TO ROLE budget_admin;
Add or remove objects from a custom budget¶
You can add or remove objects from a custom budget using Snowsight or SQL.
Note
To add or remove objects from a custom budget, you must use a role with the required privileges on the budget and the object. For more information, see Create a custom role to manage a custom budget.
Use Snowsight to add or remove objects from a custom budget¶
Sign in to Snowsight.
Select Admin » Cost Management.
Select Budgets.
Select the budget to edit.
Select + Tags & resources, then select the objects you want to add to the custom budget.
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.
If you are directly adding individual objects, you can only add an object to one custom budget. In this case, if an object is currently included in one custom budget and you add that object to a second custom budget, Budgets removes the object from the first custom budget without issuing a warning. This behavior does not apply to using tags to add objects to budgets; an object with one or more tags can be included in multiple custom budgets if you are using tags to add the object to the budgets.
Select Done.
Use SQL commands to add or remove objects from a custom budget¶
The role used to add or remove an object from a budget must have the APPLYBUDGET privilege on the object. For more information, see the examples in the Create a custom role to manage a custom budget section.
To review the list of objects already in the custom budget, call the budget’s
<budget_name>!GET_LINKED_RESOURCES method. For example, to see the list of objects in the budget
my_budget
in the budgets_db.budgets_schema
schema, execute the following statement:
CALL budgets_db.budgets_schema.my_budget!GET_LINKED_RESOURCES();
The statement returns the following output:
+-------------+-----------------+-----------+-------------+---------------+
| RESOURCE_ID | NAME | DOMAIN | SCHEMA_NAME | DATABASE_NAME |
|-------------+-----------------+-----------+-------------+---------------|
| 326 | DB1 | DATABASE | NULL | NULL |
| 157 | MY_WH | WAREHOUSE | NULL | NULL |
+-------------+-----------------+-----------+-------------+---------------+
Note
The list does not include:
Objects that were added automatically (for example, compute pools and warehouses created and owned by a Snowflake Native App).
Objects that were added when a tag was added to the budget.
Objects must be added to or removed from a budget by reference.
You can add table
t1
to budgetmy_budget
by using the following steps:Grant the APPLYBUDGET privilege on the table to the role
budget_admin
by executing the following statement:GRANT APPLYBUDGET ON TABLE t1 TO ROLE budget_admin;
Pass a reference for table
t1
to the ADD_RESOURCE instance method by executing the following statement:CALL budgets_db.budgets_schema.my_budget!ADD_RESOURCE( SELECT SYSTEM$REFERENCE('TABLE', 't1', 'SESSION', 'applybudget'));
The SYSTEM$REFERENCE function creates a reference for a TABLE object,
t1
, with the APPLYBUDGET privilege granted on the table. This enables the budget to monitor the specified object in your account. 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, the third parameter can be either ‘SESSION’ or ‘CALL’).Note
If you want to add a Snowflake Native App to a budget, when you call SYSTEM$REFERENCE, specify
'DATABASE'
(not'APPLICATION'
) for theobject_type
argument.For a full list of objects and privileges, see Supported object types and privileges for references.
Note
If you are directly adding individual objects, you can only add an object to one custom budget. In this case, if an object is currently included in one custom budget and you add that object to a second custom budget, Budgets removes the object from the first custom budget without issuing a warning. This behavior does not apply to using tags to add objects to budgets; an object with one or more tags can be included in multiple custom budgets if you are using tags to add the object to the budgets.
You can remove the database
db1
from the budgetmy_budget
by using the following steps:Grant the APPLYBUDGET privilege on the database to the role
budget_admin
by executing the following statement:GRANT APPLYBUDGET ON DATABASE db1 TO ROLE budget_admin;
Remove the database by passing a reference to the REMOVE_RESOURCE instance method:
CALL budgets_db.budgets_schema.my_budget!REMOVE_RESOURCE( SELECT SYSTEM$REFERENCE('DATABASE', 'db1', 'SESSION', 'applybudget'));