现在的位置: 首页 > 综合 > 正文

使用Profiler Blocked Process Report & Alert 监控数据库Blocking

2013年08月06日 ⁄ 综合 ⁄ 共 1074字 ⁄ 字号 评论关闭

SQL Server Profiler中提供了一个Blocked Process Report 事件,这个事件可以记录阻塞超过指定的时间的任务,使用这个事件我们可以记录数据库的阻塞信息。

 

下面我们来看一下如何使用Blocked ProcessReport:

 

使用Blocked Process Report需要配置阈值和报告生成频率,使用sp_configure 命令配置 blocked process threshold 选项(以秒为单位进行设置)。 默认情况下,不生成阻塞的进程报告。

 

1.  配置blocked process threshold 阈值:

 

sp_configure 'showadvanced options',1;

GO

--Use RECONFIGURE hint to prevent a restart ofthe SQL Server for changes to take effect

RECONFIGURE;

GO

--Set the blocked process threshold value to 10seconds

sp_configure 'blockedprocess threshold',10;

GO

--Use RECONFIGURE hint to prevent a restart ofthe SQL Server for changes to take effect

RECONFIGURE;

GO

 

2.  打开Profiler选择Blocked Process Report事件:

 

3.   模拟阻塞,打开两个查询界面同时运行:

 

BEGIN TRAN

UPDATE TEST SET NAME='TEST1'

 

4.十秒钟后我们会看到阻塞的信息已经记录到Profiler中了:

 

5.   我们可以将Trace模板保存成脚本然后在数据库上定期运行,这样我们就可以了解数据库的阻塞状态。由于后台检测机制与死锁相同,所以对数据库的影响是非常小的。

 

更多信息参考:Blocked Process Report 事件类:http://msdn.microsoft.com/zh-cn/library/ms191168.aspx

 

另外我们设置Alert,如果Blocking超过一定时间可以发送给DBA。

 

1.   创建Alert:

 

 

2.   设置Response(可以发送给DBA,也可以执行上面产生的脚本,可以及时的帮你捕获Blocking信息)

 

 

关于Blocking还可以自己建Job定期捕获Blocking的状况,语句可以参考:http://blog.csdn.net/smithliu328/article/details/7849290

抱歉!评论已关闭.