Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Using T-SQL to Verify Tables Row Counts in Transactional Replication Expand / Collapse
Author
Message
Posted Thursday, August 5, 2010 12:05 AM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, October 18, 2014 11:53 AM
Points: 18, Visits: 418
Comments posted to this topic are about the item Using T-SQL to Verify Tables Row Counts in Transactional Replication

Hi Experts!

I would like to thank you for your comments surrounding this topic. Of course there are many ways to achieve the rowcount verification and I totally agree with your methods described below. My script was originally written for purpose of documenting our current transactional replication setup. It later evolved into rowcount verification. So I thought since I've read many of your articles and made use many of your scripts, I here contribute my tiny part back to the community. Again I appreciate for your comments. It's just few hours since my article got posted, I've learnt a great deal from your idea and comments...
Post #964002
Posted Thursday, August 5, 2010 12:47 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, August 22, 2014 1:48 AM
Points: 13, Visits: 104
While this works it is on the basis that the row count at the subscriber is supposed to be the same as the publisher. I have seen many cases where vertical and horizontal filtering is used on publications and the table at the subscriber is therefore significantly different from the publisher both in columns and in row count.

Have you looked at tracer tokens. These are simple to use and give very quick indication of any latency which can be investigated further and with the use of the underlying stored procedures very easy to set up to generate email alerts. There is also the dmv sys.dm_os_performance_counters which can be used to monitor latency and throughput.

These two features available within SQL Server are in fact simpler to use than your TSQL script and less of an overhead for very busy replication systems.
Post #964017
Posted Thursday, August 5, 2010 3:01 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, October 3, 2012 6:35 AM
Points: 97, Visits: 501
I have put something similar in place a couple of years ago.. I do a simple count on Publisher tables, and a count at the destination, then query to find differences (plus some extended formulas for certain tables), this is then emailed to the team responsible for the clone database (reporting) as attached.

This is all done as sequence of tasks within the replication jobs...





Oraculum

  Post Attachments 
dist_list.bmp (35 views, 1.33 MB)
Post #964073
Posted Thursday, August 5, 2010 6:28 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: Moderators
Last Login: Yesterday @ 2:45 PM
Points: 6,794, Visits: 1,906
Why not use the built in validation? It has options to do a fast count as well as a checksum, and it understands whatever filters are in place.

Andy
SQLAndy - My Blog!
Connect with me on LinkedIn
Follow me on Twitter
Post #964195
Posted Thursday, August 5, 2010 7:03 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, September 11, 2014 9:25 AM
Points: 11, Visits: 58
My thoughts exactly... Uh...Why don't you use the article and publication validation that ships with the product and has been there for multiple versions?

sp_article_validation allows you to do both a rowcount and a rowcount+checksum
sp_publication_validation just runs sp_article_validation for all articles in the publication

Both account for filtering. The reason that they both have a checksum option is because it is possible for the row counts to be the same, but the data is still out of synch.

If you are running replication on SQL Server 2005 and higher, tracer tokens tell you precisely what you throughput is. How fast a single article is sending data is completely irrelevant, because the replication engine doesn't transmit on an article by article basis. It transmits in batches for the entire publication. So, the throughput of one article is affected by every other article in the publication. As long as you are posting tracer tokens are regular intervals, then when things fall behind, you can use the tracer tokens to tell that your subscriber is caught up to the publisher as of an exact time of the day.

Additionally, the replication monitor will show you how many rows are still pending at any given time for each publication. It will also use the most recent throughput numbers (either from a tracer token or a batch that was just replicated) to compute "how long until I catch up".

There is a special set of validation procedures for merge replication, but tracer tokens are only valid for transactional replication.

While it's a nice academic exercise, I wouldn't use anything except the built in validation procedures + tracer tokens.


Michael Hotek
President - Champion Valley Software, Inc.
http://www.ChampionValleySoftware.com
Post #964220
Posted Thursday, August 5, 2010 10:02 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, August 5, 2010 9:54 AM
Points: 1, Visits: 1
What if sysindexes table does not have the most up to date counts? I have trouble with getting the accurate table row counts on sysindexes table. Would your script work on such cases? There are no built in tools in SQL 2000 I believe to check the accuracy of replication.
Post #964431
Posted Thursday, August 5, 2010 10:31 AM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, October 18, 2014 11:53 AM
Points: 18, Visits: 418
Hi tina.t.kurtluyan

Counting rows in sysindexes is much faster than counting rows in the actual table. However, because sysindexes is lazily updated, the rowcount may not be accurate. If that's the case, you may need to use a full COUNT(*).
Post #964469
Posted Thursday, August 5, 2010 10:43 AM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, October 18, 2014 11:53 AM
Points: 18, Visits: 418
Hi bill.galashan

you're abso correct. My script only works when all data from table is relicated. If data fiterring is used, it of course will cause diff in rowcounts between pub and sub. I forgot to mention it in the article. Thanks.
Post #964478
Posted Thursday, August 5, 2010 12:09 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 8:35 AM
Points: 17,854, Visits: 15,800
I like the concept. I have a concern about usability in later versions of SQL server. The scripts should be updated to not use the deprecated system objects and start using the dmv's that started shipping with SQL 2005.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Post #964582
Posted Thursday, August 5, 2010 1:24 PM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, October 18, 2014 11:53 AM
Points: 18, Visits: 418
Good point, Jason. Thanks!

Instead of using dbo.sysindexes, sys.partitions can be used to obtain the rowcount

SELECT ( SCHEMA_NAME(o.schema_id) + '.' + OBJECT_NAME(o.object_id) ) AS TblName,
p.rows AS RowCnt
FROM sys.partitions AS p
INNER JOIN sys.objects AS o ON p.object_id = o.object_id
WHERE o.type_desc = 'USER_TABLE'
AND p.index_id IN ( 0, 1 )
Post #964659
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse