Monitoring: Account Usage, Query History & Observability
Master Snowflake monitoring with account usage views, query history, and observability best practices.
20+ years shipping high-throughput database systems. Drawn from code that ran under real load.
- ✓Basic knowledge of SQL (SELECT, WHERE, GROUP BY, ORDER BY).
- ✓Access to a Snowflake account with ACCOUNTADMIN or MONITOR USAGE privilege.
- ✓Familiarity with Snowflake warehouses and databases.
- Snowflake provides built-in views like SNOWFLAKE.ACCOUNT_USAGE and INFORMATION_SCHEMA.QUERY_HISTORY for monitoring.
- Use QUERY_HISTORY to analyze past queries, identify slow queries, and track resource consumption.
- Account usage views offer aggregated metrics on storage, credits, and login history.
- Set up alerts and dashboards using Snowflake's observability features or third-party tools.
- Monitor warehouse usage, concurrency, and data transfer to optimize costs and performance.
Think of Snowflake as a giant library where each book is a piece of data. Monitoring is like having a librarian who tracks which books are read most, how long people spend reading, and whether any books are being damaged. You can see who entered the library, what they read, and how much energy (credits) the lights and heating used. This helps you decide if you need more librarians (warehouses) or if some books should be moved to a cheaper shelf.
In the world of cloud data warehousing, Snowflake has emerged as a powerhouse, offering near-infinite scalability and a unique architecture that separates storage and compute. But with great power comes great responsibility—and cost. Without proper monitoring, your Snowflake account can quickly become a black hole for credits, with runaway queries and idle warehouses burning through your budget. This is where Snowflake's built-in observability features come to the rescue.
Snowflake provides a rich set of views and functions under the SNOWFLAKE.ACCOUNT_USAGE schema and INFORMATION_SCHEMA that give you unprecedented visibility into your account's health, performance, and usage patterns. Whether you're a data engineer trying to optimize a slow ETL pipeline, a platform admin tracking cost allocation across teams, or a developer debugging a sudden spike in query latency, these tools are indispensable.
In this tutorial, you'll learn how to query account usage views to monitor storage, credits, and login history. You'll dive deep into query history to identify slow or expensive queries, understand warehouse utilization, and set up proactive alerts. We'll also cover real-world debugging scenarios, including a production incident where a missing warehouse led to a major outage. By the end, you'll have a production-ready monitoring toolkit to keep your Snowflake environment running smoothly and cost-effectively.
Introduction to Snowflake Monitoring Views
Snowflake exposes several system-defined schemas that provide comprehensive monitoring data. The two most important are:
- SNOWFLAKE.ACCOUNT_USAGE: Contains views with aggregated historical data (up to 365 days) for storage, credits, queries, logins, and more. Data is typically delayed by up to 2 hours.
- INFORMATION_SCHEMA: Contains views like QUERY_HISTORY that provide near real-time data (usually within minutes) for the current session or account.
QUERY_HISTORY: Details of all queries executed.WAREHOUSE_METERING_HISTORY: Credit consumption per warehouse.STORAGE_USAGE: Storage usage per database.LOGIN_HISTORY: Successful and failed login attempts.SESSIONS: Active sessions.
To access these views, you need the appropriate privileges (e.g., MONITOR USAGE on the account). Let's start by exploring the account usage schema.
Querying Query History for Performance Analysis
The QUERY_HISTORY view is your go-to for understanding what queries are running, how long they take, and how many resources they consume. You can filter by time range, warehouse, user, and more. Key columns include:
QUERY_ID: Unique identifier.QUERY_TEXT: The SQL executed.EXECUTION_TIME: Time in milliseconds.BYTES_SCANNED: Amount of data read.CREDITS_USED: Credits consumed (for serverless features).WAREHOUSE_NAME: Warehouse used.START_TIME,END_TIME.
Let's find the top 10 slowest queries in the last 24 hours.
BYTES_SCANNED with high EXECUTION_TIME often indicates missing filters or full table scans. Consider clustering or partitioning.Monitoring Warehouse Credit Consumption
Warehouses consume credits based on their size and runtime. The WAREHOUSE_METERING_HISTORY view provides hourly credit usage per warehouse. You can use this to track costs and identify idle warehouses. Let's see which warehouses consumed the most credits yesterday.
Tracking Storage Usage and Growth
Storage costs can sneak up on you. The STORAGE_USAGE view shows the average daily storage (in bytes) for each database, including compressed data, fail-safe, and time travel. Use DATABASE_STORAGE_USAGE_HISTORY for historical trends. Let's find the top 5 databases by storage.
Analyzing Login and Session History
Security and access monitoring are critical. LOGIN_HISTORY records all login attempts (success/failure), while SESSIONS shows currently active sessions. Use these to detect unauthorized access or troubleshoot connection issues. Let's find failed login attempts in the last week.
Building a Monitoring Dashboard with Snowflake Views
To operationalize monitoring, you can create a dashboard using Snowsight (Snowflake's web interface) or export data to a BI tool. Here's a sample query that combines multiple views into a single health check report.
Using INFORMATION_SCHEMA for Near Real-Time Monitoring
When you need up-to-the-minute data, INFORMATION_SCHEMA views like QUERY_HISTORY_BY_SESSION are your friend. They reflect data within minutes. For example, to see queries currently running or recently completed for your session.
The Phantom Warehouse: When Auto-Suspend Didn't Suspend
- Always double-check warehouse settings after any deployment that modifies them.
- Set up automated alerts on credit consumption anomalies (e.g., >20% daily increase).
- Use ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY to track warehouse credit usage over time.
- Implement a policy that warehouses must have auto-suspend enabled (except for rare exceptions with approval).
- Regularly audit warehouse configurations using SHOW WAREHOUSES and compare with expected settings.
SELECT query_id, query_text, execution_time, bytes_scanned FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY WHERE query_id = '<query_id>';SELECT * FROM TABLE(INFORMATION_SCHEMA.QUERY_HISTORY_BY_SESSION(RESULT_LIMIT => 10)) ORDER BY START_TIME DESC;| File | Command / Code | Purpose |
|---|---|---|
| explore_views.sql | SELECT view_name FROM SNOWFLAKE.ACCOUNT_USAGE.VIEWS; | Introduction to Snowflake Monitoring Views |
| slow_queries.sql | SELECT | Querying Query History for Performance Analysis |
| warehouse_credits.sql | SELECT | Monitoring Warehouse Credit Consumption |
| storage_usage.sql | SELECT | Tracking Storage Usage and Growth |
| login_history.sql | SELECT | Analyzing Login and Session History |
| health_check.sql | SELECT | Building a Monitoring Dashboard with Snowflake Views |
| recent_queries.sql | SELECT | Using INFORMATION_SCHEMA for Near Real-Time Monitoring |
Key takeaways
Common mistakes to avoid
5 patternsRelying solely on ACCOUNT_USAGE for real-time alerts
Not filtering by time range in QUERY_HISTORY
Assuming credits_used in QUERY_HISTORY reflects warehouse cost
Ignoring storage costs from time travel and fail-safe
Not using role-based access for monitoring views
Interview Questions on This Topic
How would you identify the top 5 most expensive queries in terms of credits in the last week?
CURRENT_TIMESTAMP()), group by query_id, and sum credits_used. Order by total credits descending and limit 5.Frequently Asked Questions
20+ years shipping high-throughput database systems. Drawn from code that ran under real load.
That's Snowflake. Mark it forged?
3 min read · try the examples if you haven't