Monitoring Windows Azure SQL Database Using Dynamic Management Views

5 out of 7 rated this helpful - Rate this topic

Microsoft Windows Azure SQL Database enables a subset of dynamic management views to diagnose the performance problems, which might be caused by blocked or long-running queries, resource bottlenecks, poor query plans, and so on. This topic provides information on how to detect common performance problems by using the dynamic management views in Windows Azure SQL Database.

Windows Azure SQL Database partially supports three categories of dynamic management views:

  • Database-related dynamic management views.
  • Execution-related dynamic management views.
  • Transaction-related dynamic management views.

For a list of fully supported dynamic management views in Windows Azure SQL Database, see System Views (Windows Azure SQL Database). For detailed information on dynamic management views, see Dynamic Management Views and Functions (Transact-SQL) in SQL Server Books Online.

Permissions

In Windows Azure SQL Database, querying a dynamic management view requires VIEW DATABASE STATE permissions. The VIEW DATABASE STATE permission returns information about all objects within the current database.

To grant the VIEW DATABASE STATE permission to a specific database user, run the following query:

 
GRANT VIEW DATABASE STATE TO database_user;

In an instance of on-premise SQL Server, dynamic management views return server state information. In Windows Azure SQL Database, they return information regarding your current logical database only.

Note
When executing the sys.dm_exec_requests and sys.dm_exec_sessions views, if the user has VIEW DATABASE STATE permission on the database, the user will see all executing sessions on the database; otherwise, the user will see only the current session.

Calculating Database Size

You are billed for the edition and the capacity of your SQL Databases. If the size of your database reaches its MAXSIZE you will receive an error code 40544. You cannot insert or update data, or create new objects (such as tables, stored procedures, views, and functions) unless you update the MAXSIZE of your database or delete data. For more information, see Accounts and Billing in Windows Azure SQL Database. The sys.dm_db_partition_stats view returns page and row-count information for every partition in the database, which can be used to calculate database size.

The following query returns the size of your database (in megabytes):

 
-- Calculates the size of the database. 

SELECT SUM(reserved_page_count)*8.0/1024

FROM sys.dm_db_partition_stats; 

GO

The following query returns the size of individual objects (in megabytes) in your database:

 
-- Calculates the size of individual database objects. 

SELECT sys.objects.name, SUM(reserved_page_count) * 8.0 / 1024

FROM sys.dm_db_partition_stats, sys.objects 

WHERE sys.dm_db_partition_stats.object_id = sys.objects.object_id 

GROUP BY sys.objects.name; 

GO

Monitoring Connections

You can use the sys.dm_exec_connections (Windows Azure SQL Database) view to retrieve information about the connections established to a specific SQL Database server and the details of each connection. In addition, the sys.dm_exec_sessions view is helpful when retrieving information about all active user connections and internal tasks.

The following query retrieves information on the current connection:

-- monitor connections
SELECT
e.connection_id,
s.session_id,
s.login_name,
s.last_request_end_time,
s.cpu_time
FROM
sys.dm_exec_sessions s
INNER JOIN sys.dm_exec_connections e
ON s.session_id = e.session_id
GO

Monitoring Query Performance

Slow or long running queries can consume significant system resources. This section demonstrates how to use dynamic management views to detect a few common query performance problems. For detailed information, see Troubleshooting Performance Problems in SQL Server 2005 article on Microsoft TechNet.

Finding Top N Queries

The following example returns information about the top five queries ranked by average CPU time. This example aggregates the queries according to their query hash, so that logically equivalent queries are grouped by their cumulative resource consumption.

-- Find top 5queries
SELECT TOP 5 query_stats.query_hash AS "Query Hash",
SUM(query_stats.total_worker_time) / SUM(query_stats.execution_count) AS "Avg CPU Time",
MIN(query_stats.statement_text) AS "Statement Text"
FROM
(SELECT QS.*,
SUBSTRING(ST.text, (QS.statement_start_offset/2) + 1,
((CASE statement_end_offset
WHEN -1 THEN DATALENGTH(st.text)
ELSE QS.statement_end_offset END
- QS.statement_start_offset)/2) + 1) AS statement_text
FROM sys.dm_exec_query_stats AS QS
CROSS APPLY sys.dm_exec_sql_text(QS.sql_handle) as ST) as query_stats
GROUP BY query_stats.query_hash
ORDER BY 2 DESC;
GO

Monitoring Blocked Queries

Slow or long-running queries can contribute to excessive resource consumption and be the consequence of blocked queries. The cause of the blocking can be poor application design, bad query plans, the lack of useful indexes, and so on. You can use the sys.dm_tran_locks view to get information about the current locking activity in your SQL Database. For example code, see sys.dm_tran_locks (Transact-SQL) in SQL Server Books Online.

Monitoring Query Plans

An inefficient query plan also may increase CPU consumption. The following example uses the sys.dm_exec_query_stats view to determine which query uses the most cumulative CPU.

-- Monitor query plans
SELECT
highest_cpu_queries.plan_handle,
highest_cpu_queries.total_worker_time,
q.dbid,
q.objectid,
q.number,
q.encrypted,
q.[text]
FROM
(SELECT TOP 50
qs.plan_handle,
qs.total_worker_time
FROM
sys.dm_exec_query_stats qs
ORDER BY qs.total_worker_time desc) AS highest_cpu_queries
CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS q
ORDER BY highest_cpu_queries.total_worker_time desc

See Also

[Windows Azure] Monitoring SQL Database Using Dynamic Management Views的更多相关文章

  1. [Windows Azure] Managing SQL Database using SQL Server Management Studio

    Managing Windows Azure SQL Database using SQL Server Management Studio You can use Windows Azure SQL ...

  2. [Windows Azure] Windows Azure Storage & SQL Database

    http://channel9.msdn.com/Series/Windows-Azure-Storage-SQL-Database-Tutorials Windows Azure offers mu ...

  3. [Windows Azure] Learn SQL Reporting on Windows Azure (9-Step Tutorial)

    Learn SQL Reporting on Windows Azure (9-Step Tutorial) 4 out of 4 rated this helpful - Rate this top ...

  4. [转帖]System Dynamic Management Views

    System Dynamic Management Views https://docs.microsoft.com/en-us/sql/relational-databases/system-dyn ...

  5. [Windows Azure] Walkthrough to Configure System Center Management Pack for Windows Azure Fabric Preview for SCOM 2012 SP1 (with a MetricsHub Bonus)

    The wait is finally over. This is a huge update to the Azure Management Pack over the one that was r ...

  6. Azure 上SQL Database(PaaS)Time Zone时区问题处理(进阶篇)

    通常ISV在面对本地客户时对时间相关的处理,一般都时区信息都是不敏感的.但是现在云的世界里为了让大家把时间处理的方式统一起来,云上的服务都是以UTC时间为准的,现在如果作为一个ISV来说就算你面对的客 ...

  7. Azure 上SQL Database(PaaS)Time Zone时区问题处理

    在Azure上面的PaaS时间都是以UTC时间为准(云的世界里基本上都是以UTC时间为标准的),所以以前在本地SQL Server上面常用的GetDate()方法会碰到问题,在中国获取的时间会被当前时 ...

  8. [Windows Azure] Guidelines for Connecting to Windows Azure SQL Database

    Guidelines for Connecting to Windows Azure SQL Database 6 out of 12 rated this helpful - Rate this t ...

  9. [Windows Azure] How to Create and Configure SQL Database

    How to Create and Configure SQL Database In this topic, you'll step through logical server creation ...

随机推荐

  1. 基于全注解的SpringMVC+Spring4.2+hibernate4.3框架搭建

    概述 从0到1教你搭建spring+springMVC+hibernate整合框架,基于注解. 本教程框架为基于全注解的SpringMVC+Spring4.2+hibernate4.3,开发工具为my ...

  2. 【JS】移动端 好用的分享插件 soshm.js

    参考链接:https://www.cnblogs.com/milo-wjh/p/6796082.html 对于qq内置浏览器分享功能处理:https://www.cnblogs.com/xuzheng ...

  3. Linux-LVS为何不能完全替代DNS轮询

    转自:链接 上一篇文章“一分钟了解负载均衡的一切”引起了不少同学的关注,评论中大家争论的比较多的一个技术点是接入层负载均衡技术,部分同学持这样的观点: 1)nginx前端加入lvs和keepalive ...

  4. HDU 4302 Holedox Eating (STL + 模拟)

    Holedox Eating Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  5. TripleDES之C#和PHP之间加密解密

    在C#常用加密解密一文中,介绍了几个加密解密方法,其中有个如何使用对称加密算法DES,此次说下DES的升级版,TripleDES. DES和TripleDES之间的关系可以参考下面的博文. 对称加密D ...

  6. no OPENSSL_Applink错误的解决方法

    原文链接: http://www.cnblogs.com/sdnyzhl/archive/2012/12/11/2813210.html 自己按照openssl中介绍的编译,安装openssl,其间编 ...

  7. 跟我学SharePoint 2013视频培训课程—— 版本控制以及内容审批(14)

    课程简介 第14天,怎样在SharePoint 2013中启用版本控制以及内容审批 视频 SharePoint 2013 交流群 41032413

  8. JetBrains PyCharm专业版激活

    PyCharm最新2018激活码 激活时选择License server 填入 http://idea.imsxm.com 然后点击Active即可 PS:在线激活有一个过期时间,这个时间一过就必须再 ...

  9. labview中小黑点,小红点

    小黑点:在labview中每一个小黑点就代表了一次内存的分配,通过小黑点可以帮助我们分析数据变量的内存拷贝情况

  10. Web用户控件开发--分页控件

    分页是Web应用程序中最常用到的功能之一,在ASP.NET中,虽然自带了一些可以分页的数据控件,但其分页功能并不尽如人意.本文对于这些数据控件的假分页暂且不表,如有不明白的同学请百Google度之. ...