執行以下的儲存過程:
select cast (replace (
replace (
xeventdata.xevent.value ('(data/value)[1]', 'varchar(max)'),
'', ''),
'', '')
as xml) as deadlockgraph
from (select cast (target_data as xml) as targetdata
from sys.dm_xe_session_targets st
join sys.dm_xe_sessions s on s.address = st.event_session_address
where [name] = 'system_health') as data
where xeventdata.xevent.value('@name', 'varchar(4000)') = 'xml_deadlock_report';
得到的結果會以xml的方式返回作為結果集,雙擊可以檢視詳細的結果集
在結果集中會找到「id」方面的節點:,將得到的兩個id放到以下對應的地方可以查出具體發生死鎖的物件
select object_name([object id],[database id])
檢視鎖的詳細:
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
order by l.request_session_id
資料庫發生死鎖的解決思路
1.查詢information schemal庫下的innodb lock表,查詢出lock的trx id 2.查詢information schemal庫下的innodb trx表,找出對應trx id的mysql的thread id 3.根據thread id查詢information sche...
檢視資料庫死鎖程序
回答 use master 必須在master資料庫中建立 goif exists select from dbo.sysobjects where id object id n dbo p lockinfo and objectproperty id,n isprocedure 1 drop pr...
檢視資料庫死鎖的儲存過程SP WHO LOCK
檢視資料庫死鎖的儲存過程sp who lock create procedure sp who lock asbegin declare spid int,bl int,inttransactioncountonentry int,introwcount int,intcountproperties...