Azure SQL Database Documentation

Monitor and Optimize Your Database Performance

Monitoring Azure SQL Database

Effective monitoring of your Azure SQL Database is crucial for ensuring optimal performance, availability, and cost-efficiency. Azure provides a rich set of tools and services to help you gain insights into your database's health and activity.

Key Monitoring Areas

Azure Tools for Monitoring

Azure Monitor

Azure Monitor is the foundational service for collecting, analyzing, and acting on telemetry from your Azure and on-premises environments. For Azure SQL Database, it provides:

Common metrics to monitor include:

You can set up alerts for critical thresholds, such as high CPU utilization or low storage space, to prevent performance degradation or outages.

Query Performance Insight

Query Performance Insight provides an intelligent view of your workload's performance. It helps identify the top resource-consuming queries and allows you to analyze them in detail.

This tool is invaluable for database administrators and developers looking to optimize their SQL queries.

Dynamic Management Views (DMVs)

DMVs offer real-time operational information about the SQL Server instance. You can query them directly to get detailed insights into various aspects of your database.

Some commonly used DMVs for monitoring include:

Example DMV query to find the top 5 most expensive queries:


SELECT TOP 5
    qs.execution_count,
    qs.total_elapsed_time / qs.execution_count AS average_elapsed_time,
    SUBSTRING(st.text, (qs.statement_start_offset/2.0)+1,
        ((CASE qs.statement_end_offset
            WHEN -1 THEN DATALENGTH(st.text)
            ELSE qs.statement_end_offset
         END)-qs.statement_start_offset)/2.0) AS statement_text
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st
ORDER BY qs.total_elapsed_time DESC;
            

Azure SQL Analytics (Log Analytics Solution)

Azure SQL Analytics is a comprehensive solution built on Log Analytics that collects and analyzes telemetry from your Azure SQL databases, SQL Managed Instances, and SQL Servers on Azure VMs. It provides:

To use Azure SQL Analytics, you typically need to configure diagnostic settings on your SQL resources to send logs and metrics to a Log Analytics workspace.

Best Practices for Monitoring

Note: Ensure you have the necessary permissions to access monitoring data in Azure. Typically, roles like Contributor, Owner, or specific monitoring roles are required.
Tip: Consider enabling Query Store for your Azure SQL Database. It automatically captures a history of queries, plans, and runtimes, making performance tuning much easier.