Find out session ID of blocked processes and kill it

Find out session ID with below script:

 

select spid 被锁进程ID,
 blocked 锁进程ID,
 status 被锁状态,
 SUBSTRING(SUSER_SNAME(sid),1,30) 被锁进程登陆帐号,
 SUBSTRING(hostname,1,12) 被锁进程用户机器名称,
 SUBSTRING(DB_NAME(a.dbid),1,10) 被锁进程数据名称,
 cmd 被锁进程命令,
 waittype 被锁进程等待类型,b.text SQL
FROM master..sysprocesses  a
CROSS APPLY sys.dm_exec_sql_text(a.sql_handle) b
WHERE blocked>0 AND spid<>blocked

 

Kill session ID:

 

Kill <session ID>


查询锁源:

select spid 被锁进程ID, blocked 锁进程ID,  status 被锁状态,  SUBSTRING(SUSER_SNAME(sid),1,30) 被锁进程登陆帐号, 
 SUBSTRING(hostname,1,12) 被锁进程用户机器名称,  SUBSTRING(DB_NAME(a.dbid),1,10) 被锁进程数据名称, 
 cmd 被锁进程命令,  b.text SQL  --,waittype 被锁进程等待类型
FROM master..sysprocesses  a 
CROSS APPLY sys.dm_exec_sql_text(a.sql_handle) b
--WHERE blocked>0 AND spid<>blocked 
WHERE blocked=0 AND spid IN(SELECT blocked FROM master..sysprocesses WHERE blocked>0 AND spid<>blocked)


查询被锁对象:

select  distinct request_session_id spid, OBJECT_NAME(resource_associated_entity_id) tableName,resource_associated_entity_id    
from  sys.dm_tran_locks   
where resource_type='OBJECT' 

查询等待类型:

SELECT wait_type ,SUM(wait_time_ms / 1000) AS [wait_time_s]
FROM sys.dm_os_wait_stats DOWS
WHERE wait_type NOT IN ( 'SLEEP_TASK', 'BROKER_TASK_STOP','SQLTRACE_BUFFER_FLUSH', 'CLR_AUTO_EVENT','CLR_MANUAL_EVENT', 'LAZYWRITER_SLEEP' )
GROUP BY wait_type ORDER BY SUM(wait_time_ms) DESC









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值