SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Using T-SQL to Verify Tables Row Counts in Transactional Replication


Using T-SQL to Verify Tables Row Counts in Transactional Replication

Author
Message
Thanh Ngay Nguyen
Thanh Ngay Nguyen
SSC-Enthusiastic
SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)

Group: General Forum Members
Points: 154 Visits: 480
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... :-)
bill.galashan
bill.galashan
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
Points: 27 Visits: 114
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.
oraculum
oraculum
Say Hey Kid
Say Hey Kid (663 reputation)Say Hey Kid (663 reputation)Say Hey Kid (663 reputation)Say Hey Kid (663 reputation)Say Hey Kid (663 reputation)Say Hey Kid (663 reputation)Say Hey Kid (663 reputation)Say Hey Kid (663 reputation)

Group: General Forum Members
Points: 663 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
Attachments
dist_list.bmp (69 views, 1.00 MB)
Andy Warren
Andy Warren
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: Moderators
Points: 25703 Visits: 2746
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
mhotek-836094
mhotek-836094
SSC Journeyman
SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)SSC Journeyman (77 reputation)

Group: General Forum Members
Points: 77 Visits: 61
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
tina.t.kurtluyan
tina.t.kurtluyan
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 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.
Thanh Ngay Nguyen
Thanh Ngay Nguyen
SSC-Enthusiastic
SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)

Group: General Forum Members
Points: 154 Visits: 480
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(*).
Thanh Ngay Nguyen
Thanh Ngay Nguyen
SSC-Enthusiastic
SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)

Group: General Forum Members
Points: 154 Visits: 480
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.
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)

Group: General Forum Members
Points: 67523 Visits: 18570
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

Thanh Ngay Nguyen
Thanh Ngay Nguyen
SSC-Enthusiastic
SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)SSC-Enthusiastic (154 reputation)

Group: General Forum Members
Points: 154 Visits: 480
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 )

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search