SQL Server 2005睡眠SPID阻止另一个SPID

时间:2010-04-28 21:51:33

标签: sql sql-server blocking

我发现许多睡眠过程是我的SQL Server数据库,看起来其中一个睡眠SPID正在阻止另一个进程,而且该进程也被暂停...

有人可以解释一下......

1。)睡眠过程如何阻止另一个过程? 2.)我看到许多睡眠过程......这是正常的吗?

由于

2 个答案:

答案 0 :(得分:4)

锁持有不同的持续时间,但最常见的阻塞锁X锁在交易期间保持不变。由于事务生存期与批处理生存期完全无关,因此拥有一个睡眠SPID来拥有锁是绝对正常的,它只是意味着客户端已启动事务并执行了一些更新。一旦客户端决定继续并向服务器发出命令以提交或回滚事务,阻塞就会消失。

其他频繁锁定是数据库会话锁定,它是使用数据库的连接持有的共享锁定。维护连接的简单操作将保持锁定,但通常这只与尝试获取数据库X锁定的操作冲突,如ALTER DATABASE DDL。

还有更多深奥的案例,比如恢复后持有的两阶段提交锁,但这些可能不是你的问题。您所看到的很可能是用户从SSMS运行某些内容并忘记提交的琐碎案例之一,或者是持有长事务的应用程序,甚至可能是泄漏它们。

答案 1 :(得分:2)

  

1。)睡眠过程如何阻止另一个过程?

睡眠过程正在等待工作。仔细检查是否确实存在阻塞某些事情的睡眠过程,因为这确实不太可能。

  

2。)我看到许多睡眠过程......这是正常的吗?

许多睡眠过程完全正常。例如,来自单个Web服务器的连接池通常会打开10个进程。这非常适合表现。

这是list of process states

Status      Meaning
---------------------------------------------------------------------------------
Background  The SPID is running a background task, such as deadlock detection.
Sleeping    The SPID is not currently executing. This usually indicates that the 
            SPID is awaiting a command from the application.
Running     The SPID is currently running on a scheduler.
Runnable    The SPID is in the runnable queue of a scheduler and waiting to get 
            scheduler time.
Sos_scheduler_yield The SPID was running, but it has voluntarily yielded its 
            time slice on the scheduler to allow another SPID to acquire 
            scheduler time.
Suspended   The SPID is waiting for an event, such as a lock or a latch.
Rollback    The SPID is in rollback of a transaction.
Defwakeup   Indicates that the SPID is waiting for a resource that is in the 
            process of being freed. The waitresource field should indicate the 
            resource in question.