Monitoring SQL Replication Latency

When working with SQL Server replication, you don’t have a whole lot of options for monitoring the latency of the replication. You’ve got the SQL Server Replication Monitor, and that’s basically it.

Well there is another option. You can manually run the code that the replication monitor uses to get those values that it displays.

To run it for a single publication, which is how the replication monitor uses the procedure you’d run it like this.

exec [distribution].sys.sp_replmonitorhelpsubscription @publisher = N’MyPublisher’, @publisher_db = N’MyDatabase’, @publication = ‘MyPublication’, @mode = 0, @exclude_anonymous = 0, @refreshpolicy = N’0′

But that only gives you data for the single publication for the single database. Any (or all) of the @Publisher, @publisher_db and @publication values can be null making them wildcard values. When this is done it’ll give you the information for all the publications, publishers and databases that match the wildcard. Below you can see that I’ll pulling the values for every publication which is monitored by the distributor.

exec [distribution].sys.sp_replmonitorhelpsubscription @publisher = NULL, @publisher_db = NULL, @publication = NULL, @mode = 0, @exclude_anonymous = 0, @refreshpolicy = N’0′, @publication_type=0

Now if I had a monitoring application I could have it run this stored procedure and look for values where the latency column is more than some value, say 120 seconds.



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Trust DCAC with your data

Your data systems may be treading water today, but are they prepared for the next phase of your business growth?