Custom Alerts & Notifications in Snowflake
What Are Custom Alerts & Notifications?
Custom Alerts & Notifications in Snowflake allow you to set up automated alerts when specific events or conditions occur in your Snowflake environment.
They are implemented using:
- Tasks (for scheduling checks)
- Procedures (logic for alerting)
- Notifications (via email, Slack, or external tools using Snowflake’s notification integration)
Why Are They Important?
-
✅ Proactive Monitoring
- Get real-time notifications about critical issues (e.g., data anomalies, failed jobs).
-
✅ Improved Data Reliability
- Identify issues before they impact end-users or downstream systems.
-
✅ Compliance & Security
- Alerts for suspicious access or unauthorized activity (e.g., unusual row-level access).
-
✅ Operational Efficiency
- Avoid constant manual monitoring—get notified only when action is needed.
Example SQL for a Basic Alert
1️⃣ Create a notification integration (if sending to email/SNS):
CREATE NOTIFICATION INTEGRATION my_email_notification
TYPE = EMAIL
ENABLED = TRUE
ALLOWED_RECIPIENTS = ('alerts@yourcompany.com');
2️⃣ Create a procedure to check a condition and send an alert:
CREATE OR REPLACE PROCEDURE check_failed_queries()
RETURNS STRING
LANGUAGE JAVASCRIPT
AS
$$
var result = snowflake.execute(
{ sqlText: `
SELECT COUNT(*) AS failed_count
FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
WHERE ERROR_CODE IS NOT NULL
AND START_TIME > DATEADD('MINUTE', -30, CURRENT_TIMESTAMP());
` }
);
result.next();
var failedCount = result.getColumnValue('FAILED_COUNT');
if (failedCount > 10) {
snowflake.execute({
sqlText: `CALL SYSTEM$SEND_EMAIL(
'my_email_notification',
'alerts@yourcompany.com',
'High Query Failure Alert',
'More than 10 failed queries detected in the last 30 minutes.'
)`
});
return 'Alert sent';
}
return 'No alert needed';
$$;
3️⃣ Create a task to run the procedure periodically:
CREATE OR REPLACE TASK failed_query_alert_task
WAREHOUSE = my_warehouse
SCHEDULE = '15 MINUTE'
AS
CALL check_failed_queries();
4️⃣ Start the task:
ALTER TASK failed_query_alert_task RESUME;
Use Case
A Snowflake admin wants to be alerted if more than 10 queries fail within 30 minutes. This helps them respond quickly to potential issues (e.g., ETL failures, permission problems).
Best Practices
- ✅ Use clear thresholds for alerts to avoid false positives.
- ✅ Use descriptive email subjects for easy triage.
- ✅ Integrate with external tools (Slack, ServiceNow, PagerDuty) using webhook notifications if available.
- ✅ Document alert logic for auditing and maintenance.
- ✅ Test alerts in lower environments before deploying to production.
Limitations
❌ No built-in “point-and-click” UI for alerts—you must set up manually using Tasks/Procedures. ❌ Requires careful SQL logic to avoid excessive false positives. ❌ Notification integrations (like email or SNS) require setup by an admin. ❌ Compute resources: Alerts run using warehouses, so they consume credits.
Advantages
- ✅ Proactively identify critical data or performance issues.
- ✅ Reduce manual monitoring effort—automated alerts.
- ✅ Integration with modern alerting systems (e.g., Slack, email, incident management tools).
Disadvantages
❌ Setup can be more complex than out-of-the-box solutions. ❌ Potential for alert fatigue if thresholds are not well-defined. ❌ Can consume compute resources if queries are expensive.
Required Roles
🔑 Requires roles that can create:
- Notification Integrations:
ACCOUNTADMIN - Tasks & Procedures:
SYSADMINor roles withCREATE TASK/CREATE PROCEDUREprivileges.
Impact on Performance Tuning
-
✅ Custom Alerts help:
- Quickly detect warehouse sizing issues (e.g., frequent failures due to small warehouse size).
- Spot performance degradation (e.g., sudden spike in query times).
- Highlight data pipeline bottlenecks (e.g., slow or failed ETL queries).
-
✅ By reacting promptly to alerts, you minimize performance bottlenecks and maintain consistent data delivery.
🚀 Summary
| Feature | Purpose | Key Role Needed | Benefit for Performance Tuning |
|---|---|---|---|
| Custom Alerts & Notifications | Proactive alerting & notifications | ACCOUNTADMIN / SYSADMIN | Quickly catch & fix performance issues, reduce downtime |