This document covers resource monitors, credit tracking, cost optimization, and storage management in Snowflake. Resource management and cost control represent a significant portion of the Advanced Administrator exam, testing both configuration knowledge and analytical skills with ACCOUNT_USAGE views.
-- Comprehensive resource monitorCREATERESOURCEMONITORproduction_monthlyWITHCREDIT_QUOTA=5000FREQUENCY=MONTHLYSTART_TIMESTAMP='2024-01-01 00:00 UTC'END_TIMESTAMP=NULL-- No end dateTRIGGERSON25PERCENTDONOTIFYON50PERCENTDONOTIFYON75PERCENTDONOTIFYON90PERCENTDOSUSPENDON100PERCENTDOSUSPEND_IMMEDIATE;-- Apply to accountALTERACCOUNTSETRESOURCE_MONITOR=production_monthly;-- Apply to specific warehouseALTERWAREHOUSEanalytics_whSETRESOURCE_MONITOR=production_monthly;
-- Create transient table (no Fail-safe)CREATETRANSIENTTABLEstaging_data(idINTEGER,dataVARIANT,loaded_atTIMESTAMPDEFAULTCURRENT_TIMESTAMP());-- Set Time Travel to 0 for transientALTERTABLEstaging_dataSETDATA_RETENTION_TIME_IN_DAYS=0;
-- Reduce Time Travel for non-critical tablesALTERTABLElogsSETDATA_RETENTION_TIME_IN_DAYS=1;-- Clean up old stagesREMOVE@my_stage/old_data/;-- Drop unused clonesDROPTABLEIFEXISTSdev_copy_customers;-- Monitor storage trendSELECTDATE_TRUNC('month',usage_date)ASmonth,AVG(storage_bytes+stage_bytes+failsafe_bytes)/1024/1024/1024/1024ASavg_total_tbFROMSNOWFLAKE.ACCOUNT_USAGE.STORAGE_USAGEWHEREusage_date>=DATEADD('month',-12,CURRENT_DATE())GROUPBY1ORDERBY1;
-- Create cost center tagCREATETAGcost_centerALLOWED_VALUES'engineering','analytics','finance','marketing';-- Tag warehousesALTERWAREHOUSEeng_whSETTAGcost_center='engineering';ALTERWAREHOUSEanalytics_whSETTAGcost_center='analytics';-- Query costs by tagSELECTtag_valueAScost_center,SUM(credits_used)AStotal_creditsFROMSNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORYwmhJOINSNOWFLAKE.ACCOUNT_USAGE.TAG_REFERENCEStrONwmh.warehouse_name=tr.object_nameANDtr.tag_name='COST_CENTER'WHEREwmh.start_time>=DATE_TRUNC('month',CURRENT_TIMESTAMP())GROUPBYtag_valueORDERBYtotal_creditsDESC;
Resource monitor - an object with a credit quota and triggers that tracks warehouse credit use and can notify or suspend warehouses; only ACCOUNTADMIN can create one.
Account-level resource monitor - the single monitor per account that covers credits for all warehouses together.
NOTIFY - a resource monitor action that sends an alert and leaves warehouses running.
SUSPEND - a resource monitor action that suspends assigned warehouses after running statements finish.
SUSPEND_IMMEDIATE - a resource monitor action that suspends assigned warehouses at once and cancels running statements.
Fail-safe - 7 days of Snowflake-recoverable storage after Time Travel for permanent tables, not available for transient or temporary tables.
Transient table - a table with no Fail-safe and at most 1 day of Time Travel, used for staging data to cut storage cost.
Object tag - a tag such as cost_center set on a warehouse so credit use can be attributed through TAG_REFERENCES.