We have a number of local Subscriptions that a vendor uses to Push us data every morning. We're looking to have more info about when this happens and specifically when it finishes using T-SQL.
I tried this:
exec sp_replmonitorsubscriptionpendingcmds 'SQL03', 'RSSPA_Common', 'RSSPA_Common_ORA_Tran',
'FBHBGISSQL01', 'RSSPA_Fish', 0
but get this message:
Msg 21482, Level 16, State 1, Proc开发者_StackOverflow中文版edure sp_replmonitorsubscriptionpendingcmds, Line 32
sp_replmonitorsubscriptionpendingcmds can only be executed in the "distribution" database.
How can I tell when this Subscription is being used?
Since the monitoring is handled at the distributor (which you don't seem to have access to) you could try a work-around. The first makes the assumption that you have DDL right's to the replicated database.
Add a trigger to one of the replicated tables, such as the the last one to finish with the updates which is likely the largest one. This will incur an overhead so keep the trigger simple. Design the trigger to update a timestamp in a simple table and used a SQL Agent job to monitor that table and when the timestamp has gone stale for like 1 hour then kick off another process or send a notification.
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
If the daily push is comprised of a lot of inserted/delete records another work-around would be to monitor the "rows" in the sysindexes every minute and then notify once the "rows" count stops fluctuating after a period of time.
select top 1 rows from sysindexes
where id = OBJECT_ID('tableName')
and rows > 0
This has the benefit of a negligible overhead but isn't as accurate as the trigger.
Cheers!
精彩评论