如何识别 SQL Azure 中的死锁?

发布于 2024-12-13 08:37:21 字数 426 浏览 2 评论 0 原文

我有一个由两个实例组成的 Windows Azure 角色。有时,事务会失败,并出现带有以下文本的 SqlException

事务(进程 ID N)在锁资源上与另一个进程发生死锁,并被选为死锁牺牲品。重新运行事务。

现在我已经用谷歌搜索了一段时间并阅读了 这篇文章是关于使用 SQL Server 日志识别死锁的。

问题是...

我该如何在 SQL Azure 中做到这一点?我使用什么工具来访问 SQL Azure 的内部并获取足够的数据?

I have a Windows Azure role that consists of two instances. Once in a while a transaction will fail with an SqlException with the following text

Transaction (Process ID N) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

Now I've Googled for a while and read this post about identifying deadlocks using SQL Server logs.

The problem is...

How do I do it in SQL Azure? What tools do I use to access the internals of SQL Azure and getting enough data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陪我终i 2024-12-20 08:37:22

SQL Azure 的监控比 SQL Server 受到更多限制,但您可以更方便地查看这些工具:

http://social.technet.microsoft.com/wiki/contents/articles/troubleshoot-and-optimize-queries-with-sql-azure.aspx

Monitoring of SQL Azure is more limited than SQL Server, but the tools are becoming more available for you to look underneath:

http://social.technet.microsoft.com/wiki/contents/articles/troubleshoot-and-optimize-queries-with-sql-azure.aspx

两相知 2024-12-20 08:37:22

在 SQL Azure 数据库中的“Master”数据库上运行以下查询,

select * from sys.event_log where event_type='deadlock' and database_name='<Databasename>';

此查询存在性能问题,如果超时请尝试以下操作,

SELECT *
,CAST(event_data AS XML).value('(/event/@timestamp)[1]', 'datetime2') AS TIMESTAMP
, CAST(event_data AS XML).value('(/event/data[@name="error"]/value)[1]', 'INT') AS error
,CAST(event_data AS XML).value('(/event/data[@name="state"]/value)[1]', 'INT') AS STATE
,CAST(event_data AS XML).value('(/event/data[@name="is_success"]/value)[1]', 'bit') AS is_success
,CAST(event_data AS XML).value('(/event/data[@name="database_name"]/value)[1]', 'sysname') AS database_name
FROM sys.fn_xe_telemetry_blob_target_read_file('dl', NULL, NULL, NULL)
WHERE object_name = 'database_xml_deadlock_report'

第二个查询包含与正在执行的进程相关的 XML 格式的数据。祝你好运!

Run the following query on "Master" database in SQL Azure db,

select * from sys.event_log where event_type='deadlock' and database_name='<Databasename>';

There was a performance issue with this query, if it gets timed out try following,

SELECT *
,CAST(event_data AS XML).value('(/event/@timestamp)[1]', 'datetime2') AS TIMESTAMP
, CAST(event_data AS XML).value('(/event/data[@name="error"]/value)[1]', 'INT') AS error
,CAST(event_data AS XML).value('(/event/data[@name="state"]/value)[1]', 'INT') AS STATE
,CAST(event_data AS XML).value('(/event/data[@name="is_success"]/value)[1]', 'bit') AS is_success
,CAST(event_data AS XML).value('(/event/data[@name="database_name"]/value)[1]', 'sysname') AS database_name
FROM sys.fn_xe_telemetry_blob_target_read_file('dl', NULL, NULL, NULL)
WHERE object_name = 'database_xml_deadlock_report'

Second query has data in XML format relating to the processes being executed. Good luck!

心碎无痕… 2024-12-20 08:37:22

现在,Azure SQL 数据库支持两种获取死锁 xml 报告的方法。您可以使用database_xml_deadlock_report事件创建一个db范围的XE会话来自己跟踪它们,或者您可以修改先前答案中的sys.fn_xe_telemetry_blob_target_read_file调用以使用“dl”而不是“el”。死锁现在被路由到自己的文件,而不是与登录事件混合在一起。

这篇 MSDN 文章包含最新的信息。

Now Azure SQL database supports two ways to get deadlock xml reports. You can create a db-scoped XE session with the database_xml_deadlock_report event to track them yourself, or you can modify the sys.fn_xe_telemetry_blob_target_read_file call from the earlier answer to use 'dl' instead of 'el'. Deadlocks are now routed to their own file instead of being mixed in with login events.

This MSDN article has the latest information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文