【问题标题】:How can I tell when a Local Subscription from a Push is used/done?如何判断何时使用/完成来自推送的本地订阅?
【发布时间】:2011-04-01 19:37:15
【问题描述】:

我们有许多本地订阅,供应商每天早上使用这些订阅向我们推送数据。我们正在寻找更多关于何时发生这种情况的信息,特别是何时完成使用 T-SQL。

我试过了:

exec sp_replmonitorsubscriptionpendingcmds 'SQL03', 'RSSPA_Common', 'RSSPA_Common_ORA_Tran', 
    'FBHBGISSQL01', 'RSSPA_Fish', 0

但收到此消息:

Msg 21482, Level 16, State 1, Procedure sp_replmonitorsubscriptionpendingcmds, Line 32
sp_replmonitorsubscriptionpendingcmds can only be executed in the "distribution" database.

我如何知道该订阅何时被使用?

【问题讨论】:

    标签: sql sql-server-2005 tsql replication


    【解决方案1】:

    由于监控是在分销商处处理的(您似乎无权访问),您可以尝试解决方法。第一个假设您拥有复制数据库的 DDL 权限。

    向其中一个复制表添加触发器,例如最后一个完成更新的表,这可能是最大的表。这将产生开销,因此请保持触发器简单。设计触发器以更新简单表中的时间戳,并使用 SQL 代理作业来监控该表,当时间戳过时 1 小时后启动另一个进程或发送通知。

    create table Repl_Monitor (
        LastUpdate datetime not null
        );
    GO
    insert into Repl_Monitor(LastUpdate)
    select GETDATE(); --seed record
    GO 
    
    create trigger trg_Repl_Monitor
    on dbo.[<replicated table to be montiored>]
    for update, insert, delete
    as
    update Repl_Monitor
    set LastUpdate = GETDATE()
    GO
    

    如果每日推送包含大量插入/删除记录,则另一种解决方法是每分钟监视 sysindexes 中的“行”,然后在“行”计数在一段时间后停止波动时通知.

    select top 1 rows from sysindexes
    where id = OBJECT_ID('tableName')
    and rows > 0
    

    这样做的好处是开销可以忽略不计,但不如触发器准确。

    干杯!

    【讨论】:

    • 谢谢。我将把它归档,因为我们已经调整了我们的自动流程以稍后运行,但我们可能需要再次这样做。
    猜你喜欢
    • 2018-05-03
    • 2012-04-14
    • 2012-10-06
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    • 2013-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多