监视 SQL 实例的阻塞的会话。
正在阻塞的会话监视器检测是否存在正在阻塞的情况。
当一个会话持有一个特定资源的锁而第二个会话尝试获取同一资源上的相冲突锁类型时,则会出现阻塞。对于采用基于锁的并发机制的任何关系数据库管理系统(RDBMS)而言,阻塞是不可避免的。但是,阻塞过多可能导致性能问题。
当锁定和阻塞增长到严重影响系统性能时,通常是以下原因之一造成的:
某个会话持有对一组资源的锁,从不释放它们。通常的原因有:
已取消的查询未回滚
孤立事务
某个会话(由 session_id 或 "SPID" 标识)在超长时间内持有对一组资源的锁,而不释放它们。通常的原因有:
长时间运行的事务
缺少合适的索引
锁定提示使用不当
与不合理应用程序设计有关的其他问题
终止位于阻塞链的头的会话
缩短事务时间
创建合适的索引
使用锁定提示。请参阅 SQL Server 联机丛书
使用基于行版本控制的隔离级别
配置 SQL Server 设置(内存设置、锁定超时等)
更改此特定数据库或所有数据库的监视器上的阈值
或者,如果对于数据库无需考虑阻塞的会话:
禁用此特定数据库或所有数据库的此监视器
另请参阅:“ INF: 理解和解决 SQL Server 阻塞问题”
Target | Microsoft.SQLServer.2008.DBEngine | ||
Parent Monitor | System.Health.PerformanceState | ||
Category | PerformanceHealth | ||
Enabled | False | ||
Alert Generate | True | ||
Alert Severity | Error | ||
Alert Priority | High | ||
Alert Auto Resolve | True | ||
Monitor Type | Microsoft.SQLServer.2008.DBEngine.BlockedSPIDs | ||
Remotable | True | ||
Accessibility | Public | ||
Alert Message |
| ||
RunAs | Default |
<UnitMonitor ID="Microsoft.SQLServer.2008.DBEngine.BlockedSPIDsMonitor" Accessibility="Public" Enabled="false" Target="SQL2008Core!Microsoft.SQLServer.2008.DBEngine" ParentMonitorID="SystemHealth!System.Health.PerformanceState" Remotable="true" Priority="Normal" TypeID="Microsoft.SQLServer.2008.DBEngine.BlockedSPIDs" ConfirmDelivery="false">
<Category>PerformanceHealth</Category>
<AlertSettings AlertMessage="Microsoft.SQLServer.2008.DBEngine.BlockedSPIDsMonitor.AlertMessage">
<AlertOnState>Error</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>High</AlertPriority>
<AlertSeverity>Error</AlertSeverity>
<AlertParameters>
<AlertParameter1>$Data/Context/Property[@Name='BlockedSPIDList']$</AlertParameter1>
<AlertParameter2>$Target/Property[Type="SQL!Microsoft.SQLServer.ServerRole"]/InstanceName$</AlertParameter2>
<AlertParameter3>$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$</AlertParameter3>
</AlertParameters>
</AlertSettings>
<OperationalStates>
<OperationalState ID="Blocked" MonitorTypeStateID="Blocked" HealthState="Error"/>
<OperationalState ID="NotBlocked" MonitorTypeStateID="NotBlocked" HealthState="Success"/>
</OperationalStates>
<Configuration>
<ConnectionString>$Target/Property[Type="SQL!Microsoft.SQLServer.DBEngine"]/ConnectionString$</ConnectionString>
<IntervalSeconds>300</IntervalSeconds>
<SyncTime/>
<WaitMinutes>1</WaitMinutes>
<NumberBlockedSPIDs>1</NumberBlockedSPIDs>
<TimeoutSeconds>300</TimeoutSeconds>
<InstanceName>$Target/Property[Type="SQL!Microsoft.SQLServer.ServerRole"]/InstanceName$</InstanceName>
<ComputerName>$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$</ComputerName>
</Configuration>
</UnitMonitor>