Groups | Blog | Home
all groups > sql server replication > july 2006 >

sql server replication : Replicated subscribers.. Use of nolock


Hassan
7/14/2006 2:54:43 PM
We have our data replicated to a group of read only servers in order to
scale out.

My question is since all the requests to these subscribers are just in the
form of sprocs that do selects, i would like to have all these sprocs use a
nolock hint as I dont think i need to worry about dirty data as every
transaction coming is obviously a committed transaction at the source
...right ?

The reason i want to put the nolock hints is because we see the sprocs run
slow when the distribution agent is inserting rows causing blocking.

Let me know if this is a good wise decision.

Thanks

sullins602
7/15/2006 9:39:25 AM
On my sprocs for reports that mainly just do select I always use the
"NOLOCK" table hint. I've seen queries go from 5 minutes processing
down to 5 seconds. The only catch is that in SQL 2005 simply putting
(NOLOCK) after a table name won't work. You have to use do it like this

select
*
from
table1 with (nolock)

Notice the addition of the keyword "with" before the table hint.

Hope this helps!


[quoted text, click to view]
Paul Ibison
7/15/2006 5:16:23 PM
Hassan,
I suppose the safest way is to use READ COMMITTED SNAPSHOT. If a transaction
fails on the publisher and is rolled back, this will still occur on the
subscriber and NOLOCK will cause dirty reads.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)

Paul Ibison
7/15/2006 6:02:13 PM
Yes - but are dirty reads ever a problem for you? Rollbacks might cause yiu
to read incorrect data.
Cheers,
Paul Ibison

Hassan
7/15/2006 6:18:09 PM
You lost me Paul..

I thought replication starts propogating until the transaction is committed
on the publisher ...am i not right ?

Say if i do a

Begin Tran

Insert tableA values(1)
Insert tableA values(2)
Insert tableA values(3)
....
....
Insert tableA values(1000000)

Commit Tran

So are you saying that even before it completes inserting the 1 million
records, data will start propagating to the subscribers ?

If true, I was not aware of it. I thought it would commit the million rows
and then start replicating.


[quoted text, click to view]

Paul Ibison
7/16/2006 5:57:17 PM
Hassan,

I don't see a problem in the scenario you mentioned. I am thinking
differently - NOLOCK could cause inconsistant data when a transaction on the
subscriber has been partially complete, before the rest of the transaction
completes, in the case of a successful transaction.

Begin Tran

Insert tableA values(1)
Insert tableB values(2)
Point A: Insert tableC values(3)
...
...
Insert tableZ values(1000000)

Commit Tran

Doing a read at point A might be problematic for reports - it all depends on
how the TSQL in the reports go.

The real case I had in mind is a stored procedure that fails and gets rolled
back in a stored procedure - you'll get more problematic dirty reads
occurring this way.

Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)



AddThis Social Bookmark Button