SqlServer 监控发布中未分发的命令数
对于查看未分发的命令数,我们通常这样查看。
然而当服务器有很多发布时,一个个打开查看就很麻烦
当然,如果想用脚本查看就更方便了,运行下面的语句
--查看各发布订阅未分发的命令数和估计时间
SELECT 'EXEC distribution.sys.sp_replmonitorsubscriptionpendingcmds @publisher = N'''
+ a.publisher + ''', @publisher_db = N''' + a.publisher_db
+ ''', @publication = N''' + a.publication + ''', @subscriber = N'''
+ c.name + ''', @subscriber_db = N''' + b.subscriber_db
+ ''', @subscription_type =' + CAST(b.subscription_type AS VARCHAR)
FROM distribution.dbo.MSreplication_monitordata a ( NOLOCK )
INNER JOIN (
SELECT publication_id ,subscriber_id ,subscriber_db ,subscription_type
FROM distribution.dbo.MSsubscriptions (NOLOCK)
GROUP BY publication_id ,subscriber_id ,subscriber_db ,subscription_type
) b ON a.publication_id = b.publication_id
INNER JOIN sys.servers c ( NOLOCK ) ON b.subscriber_id = c.server_id
WHERE a.agent_type = 1
上面自动生成各个发布 未分发的命令的存储过程,执行就能查看各个发布等待分发的命令和估计时间:
EXEC distribution.sys.sp_replmonitorsubscriptionpendingcmds
@publisher = N'发布服务器'
, @publisher_db = N'发布数据库'
, @publication = N'发布名称'
, @subscriber = N'订阅服务器'
, @subscriber_db = N'订阅数据库'
, @subscription_type =0
/***************************************************************************/
/***************************************************************************/
但是,由于监控需要,只想统计所有发布未分发的命令数“ pendingcmdcount”的总和,
本来想用下面这个方法把各个存储过程的返回值插入到临时表,但是没有这种方法!!
CREATE TABLE #countab(pendingcmdcount int,estimatedprocesstime int) INSERT INTO #countab(pendingcmdcount,estimatedprocesstime)
EXEC distribution.sys.sp_replmonitorsubscriptionpendingcmds
@publisher = N'发布服务器'
, @publisher_db = N'发布数据库'
, @publication = N'发布名称'
, @subscriber = N'订阅服务器'
, @subscriber_db = N'订阅数据库'
, @subscription_type =0
上面这个方法也可行,但是只在本地的测试可行。就是创建链接服务器,加到数据库distribution前面。
实际服务器有本地的链接服务器,但是没显示出来,也用不了。虽然可以创建其他命名的,但不想创建太多链接服务器。
于是想到更改系统的存储过程!!~错了,是参考系统存储过程创建一个几乎一样定义的存储过程。
即不需要distribution.sys.sp_replmonitorsubscriptionpendingcmds ,创建类似的dbo.sp_getsubscriptionpendingcmds ,如下
create procedure dbo.sp_getsubscriptionpendingcmds
(
@publisher sysname -- cannot be null
,@publisher_db sysname -- cannot be null
,@publication sysname -- cannot be null
,@subscriber sysname -- cannot be null
,@subscriber_db sysname -- cannot be null
,@subscription_type int
,@pendingcmdcount int output
)
as
begin
set nocount on
declare @retcode int
,@agent_id int
,@publisher_id int
,@subscriber_id int
,@lastrunts timestamp
,@xact_seqno varbinary(16) ,@inactive int = 1
,@virtual int = -1 select @publisher_id = server_id from sys.servers where upper(name) = upper(@publisher)
select @subscriber_id = server_id from sys.servers where upper(name) = upper(@subscriber) select @agent_id = id
from distribution.dbo.MSdistribution_agents
where publisher_id = @publisher_id
and publisher_db = @publisher_db
and publication in (@publication, 'ALL')
and subscriber_id = @subscriber_id
and subscriber_db = @subscriber_db
and subscription_type = @subscription_type ;with dist_sessions (start_time, runstatus, timestamp)
as(
select start_time, max(runstatus), max(timestamp)
from distribution.dbo.MSdistribution_history
where agent_id = @agent_id
group by start_time
)
select @lastrunts = max(timestamp) from dist_sessions where runstatus in (2,3,4); if (@lastrunts is null)
begin
if exists (
select * from distribution.dbo.MSpublications p
inner join distribution.dbo.MSsubscriptions s on p.publication_id = s.publication_id
where p.publisher_id = @publisher_id
and p.publisher_db = @publisher_db
and p.publication = @publication
and p.immediate_sync = 1
and s.status = @inactive and s.subscriber_id = @virtual)
begin
select 'pendingcmdcount' = 0, N'estimatedprocesstime' = 0
return 0
end select @lastrunts = max(timestamp) from distribution.dbo.MSdistribution_history where agent_id = @agent_id
end select @xact_seqno = xact_seqno from distribution.dbo.MSdistribution_history where agent_id = @agent_id and timestamp = @lastrunts select @xact_seqno = isnull(@xact_seqno, 0x0) DECLARE @countab TABLE ( pendingcmdcount int )
insert into @countab (pendingcmdcount)
exec @retcode = distribution.sys.sp_MSget_repl_commands
@agent_id = @agent_id
,@last_xact_seqno = @xact_seqno
,@get_count = 2
,@compatibility_level = 9000000
if (@retcode != 0 or @@error != 0)
return 1 select @pendingcmdcount=pendingcmdcount from @countab return @pendingcmdcount
end
上面的存储过程主要更改3个地方,然后在其他一个数据库运行,页可在distribution运行。
1. 多一个返回参数,@pendingcmdcount int output ,返回未分发的命令数
2. 估计时间不需要,去掉
3. 查询的每个表或内部存储过程加数据库前缀distribution
接下来再用一个存储过程把所有值加起来,给计数器!
新建一个作业,定时每分钟执行,观察性能计数器统计情况。
这样也可以再cacti捕获了!~
SqlServer 监控发布中未分发的命令数的更多相关文章
- Sysstat性能监控工具包中20个实用命令
Sysstat性能监控工具包中20个实用命令 学习mpstat, pidstat, iostat和sar等工具,这些工具可以帮组我们找出系统中的问题.这些工具都包含了不同的选项,这意味着你可以根据不同 ...
- SQLServer 使用sp_repldone标识所有未分发的事务为已分发
原文:SQLServer 使用sp_repldone标识所有未分发的事务为已分发 对于发布数据库的数据大量操作时,会使日志扫描并读取太多,会导致分发堵塞很久.也有一些解决方法,参考 <SqlSe ...
- Replication--查看未分发命令和预估所需时间
当复制有延迟时,我们可以使用复制监视器来查看各订阅的未分发命令书和预估所需时间,如下图: 但是当分发和订阅数比较多的时候,依次查看比较费时,我们可以使用sys.sp_replmonitorsubscr ...
- SQLServer 事务复制中使用脚本添加某个对象的发布
原文:SQLServer 事务复制中使用脚本添加某个对象的发布 -- use [发布库] --添加表:创建项目并将其添加到发布中 exec sp_addarticle @publication = N ...
- SQLSERVER监控复制并使用数据库邮件功能发告警邮件
SQLSERVER监控复制并使用数据库邮件功能发告警邮件 最近熬出病来了,都说IT行业伤不起,不说了,说回今天的正题 正题 上个月月底的时候因为要搬迁机房,需要将一个数据信息数据库先搬到我们的机房,然 ...
- sqlserver关于发布订阅replication_subscription的总结
(转载)sqlserver关于发布订阅replication_subscription的总结 来自 “ ITPUB博客 ” ,原文地址:http://blog.itpub.net/30126024/v ...
- 监控Linux性能的18个命令行工具
监控 Linux 性能的 18 个命令行工具 对于系统和网络管理员来说每天监控和调试Linux系统的性能问题是一项繁重的工作.在IT领域作为一名Linux系统的管理员工作5年后,我逐渐 认识到监控和保 ...
- 使用MySQL中的EXPLAIN解释命令来检查SQL
我们看到许多客户的系统因为SQL及数据库设计的很差所以导致许多性能上的问题,这些问题不好解决,但是可以采用一套简单的策略来检查生产系统,发现并纠正一些共性问题. 很显然,您应该尽最大努力设计出最好的数 ...
- iOS应用发布中的一些细节
iOS应用发布中的一些细节 前言 这几天最大的新闻我想就是巴黎恐怖袭击了,诶,博主每年跨年都那么虔诚地许下“希望世界和平”的愿望,想不到每年都无法实现,维护世界和平这么难,博主真是有心无力啊,其实芸芸 ...
随机推荐
- js匿名自执行函数
匿名自执行函数:没有方法名的函数闭包:闭包是指有权访问另一个函数作用域变量的函数: 通过一个实例来解释: 从网上找到了一个案例,使用了for循环.匿名自执行函数.setTimeout. 案例1: va ...
- matlab 实现 stacked Autoencoder 解决图像分类问题
Train Stacked Autoencoders for Image Classification 1. 加载数据到内存 [train_x, train_y] = digitTrainCellAr ...
- Spring MVC出现POST 400 Bad Request &405 Request method 'GET' not supported
首先描述一下出现错误的情景: 我刚学springmvc,想做一个登录界面的东西.然后试着写了一个controller如下: @RequestMapping(value = "/login&q ...
- ios获取iphone手机设备型号
iPhone6plus和iPhone6在放大模式下也可以获取: 导入: #import "sys/utsname.h" 调用: - (NSString*)deviceString ...
- 在jsp页面里面设置全局引用文件
head.jsp文件 将项目中所需要用到次数比较多的的插件,库等,同意放在一个jsp文件里面,命名为head.jsp文件,相当于一个全局的 <%@ page language="jav ...
- maven Java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
如果你可以确认你的maven Dependencies中已经导入了如下的jar包,那么你就要检查下Deployment Assembly 选中项目 alt+enter,然后查看maven依赖有没有被添 ...
- spring quartz使用多线程并发“陷阱”
定义一个job:ranJob,设置每秒执行一次,设置不允许覆盖并发执行 <bean id="rankJob" class="com.chinacache.www.l ...
- C# await 高级用法
原文:C# await 高级用法 本文告诉大家 await 的高级用法,包括底层原理. 昨天看到太子写了一段代码,我开始觉得他修改了编译器,要不然下面的代码怎么可以编译通过 await "林 ...
- VS2017 Linux 上.NET Core调试
调试Linux 上.NET Core Visual Studio 2017 通过SSH 调试Linux 上.NET Core 应用程序. 本文环境 开发环境:Win10 x64 Visual Stud ...
- C#中的反射总结
= 导航 顶部 什么是反射 为什么要使用反射 C#反射相关的命名空间 通过反射创建类型的实例 通过反射调用类的方法 查看类中成员 查看类的构造函数 查看类中属性 查看类中字段 反射实现的接口 ...