sql server2005 阻塞问题
本帖最后由 wd324361 于 2014-03-14 18:04:41 编辑
SQLSERVER2005 在删除表中数据时,比如delete from Table1 with (rowlock) where 流水号='xxx',会出现阻塞的问题,
利用Profiler捕捉的信息如下,请高手指点下,到底是哪里出问题了
<blocked-process-report monitorLoop="144641">
<blocked-process>
<process id="process4ae73d8" taskpriority="0" logused="0" waitresource="KEY: 10:72057683372146688 (eb0086ae232f)" waittime="342016" ownerId="81858935" transactionname="DELETE" lasttranstarted="2014-03-14T17:57:32.497" XDES="0x272ec4d8" lockMode="U" schedulerid="16" kpid="2136" status="suspended" spid="80" sbid="0" ecid="23" priority="0" transcount="0" lastbatchstarted="2014-03-14T17:57:32.497" lastbatchcompleted="2014-03-14T17:57:32.497" hostname="4FI2D174HPDZCLD" hostpid="6088" isolationlevel="read committed (2)" xactid="81858935" currentdb="10" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
<executionStack>
<frame line="1" stmtstart="36" sqlhandle="0x02000000abeff10354f0a777ec35d7f9eef8c66718008ddf"/>
<frame line="1" sqlhandle="0x020000007644693a81988cebe0f7abbe5412e69714ef45d5"/>
<frame line="1" sqlhandle="0x000000000000000000000000000000000000000000000000"/>
</executionStack>
<inputbuf>
</inputbuf>
</process>
</blocked-process>
<blocking-process>
<process status="sleeping" spid="76" sbid="0" ecid="0" priority="0" transcount="1" lastbatchstarted="2014-03-14T16:46:09.833" lastbatchcompleted="2014-03-14T16:46:09.833" hostname="FVAXGY4K4OLRPL3" hostpid="15444" loginname="sa" isolationlevel="read committed (2)" xactid="81342392" currentdb="10" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128570">
<executionStack/>
<inputbuf>
select * from Table2 with (nolock) where 姓名='User' and 模块='质量单据录入'
</inputbuf>
</process>
</blocking-process>
</blocked-process-report>
------解决方案--------------------spid=76的是加上了with(nolock) 照里不会阻塞其他线程,也不会被其他线程所阻塞的。
------解决方案--------------------spid为 76的阻塞了spid为80的会话,但很有意思的是,spid 76虽然上面显示是select with(nolock),但是显示事务数为1,说明,这个语句在一个事务中,而且会话的事务还没提交,这个事务应该是在select语句之前,有update或者delete语句加上了x锁,而没有及时提交事务,于是阻塞了spid 80这个会话。
而spid 80的会话,没有显示具体的语句
------解决方案--------------------你的delete被select 操作block了,因为数据在读,默认情况下不能delete,只能等select完才能delete,只有本会话,准确莱索是本事务,也就是spid=76的才能加上X锁或者u锁,spid=80不能强制抢占