SQL查询以获取SQL SERVER 2008中的死锁 [英] SQL query to get the deadlocks in SQL SERVER 2008

查看:213
本文介绍了SQL查询以获取SQL SERVER 2008中的死锁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

帮助Sql Server 2008中的死锁

SQLServer自动记录所有死锁。任何人都可以帮助我获得sql查询,它将捕获正在收集的死锁数据,用于最近的事件。

SQLServer automatically logs all deadlocks. Can anyone help me to get sql query which will capture deadlocks data that is being collected, for a recent event.

我使用SQL SERVER 2008 R2进行我的开发活动。

I am using SQL SERVER 2008 R2 for my development activities.

谢谢& regions,
Santosh Kumar Patro

Thanks & Regards, Santosh Kumar Patro

推荐答案

您可以使用死锁图并从日志文件中收集所需的信息。

You can use a deadlock graph and gather the information you require from the log file.

我可以建议的唯一其他方法是通过使用 EXEC SP_LOCK (很快就被弃用), EXEC SP_WHO2 sys.dm_tran_locks

The only other way I could suggest is digging through the information by using EXEC SP_LOCK (Soon to be deprecated), EXEC SP_WHO2 or the sys.dm_tran_locks table.

SELECT  L.request_session_id AS SPID, 
    DB_NAME(L.resource_database_id) AS DatabaseName,
    O.Name AS LockedObjectName, 
    P.object_id AS LockedObjectId, 
    L.resource_type AS LockedResource, 
    L.request_mode AS LockType,
    ST.text AS SqlStatementText,        
    ES.login_name AS LoginName,
    ES.host_name AS HostName,
    TST.is_user_transaction as IsUserTransaction,
    AT.name as TransactionName,
    CN.auth_scheme as AuthenticationMethod
FROM    sys.dm_tran_locks L
    JOIN sys.partitions P ON P.hobt_id = L.resource_associated_entity_id
    JOIN sys.objects O ON O.object_id = P.object_id
    JOIN sys.dm_exec_sessions ES ON ES.session_id = L.request_session_id
    JOIN sys.dm_tran_session_transactions TST ON ES.session_id = TST.session_id
    JOIN sys.dm_tran_active_transactions AT ON TST.transaction_id = AT.transaction_id
    JOIN sys.dm_exec_connections CN ON CN.session_id = ES.session_id
    CROSS APPLY sys.dm_exec_sql_text(CN.most_recent_sql_handle) AS ST
WHERE   resource_database_id = db_id()
ORDER BY L.request_session_id

http://www.sqlmag.com/article/sql-server-profiler/gathering-deadlock-information-with-deadlock-graph

http://weblogs.sqlteam.com/mladenp/archive/2008/04/29/SQL-Server-2005-Get-full-information-about-transaction-locks.aspx

这篇关于SQL查询以获取SQL SERVER 2008中的死锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆