May 24, 2006 at 2:27 am
All,
I have regularly this message : Transaction (Process ID 59) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction
If I analyze my code, I can see that issue provide from query 'SELECT'.
I would like to know if I use 'SELECT ... FROM ... WITH (nolock)' is a good idea for to fix this errors ?
Thanks for you help.
degrem_m
Degremont
May 24, 2006 at 2:56 am
It should fix the problem, provided you are prepared to live with the fact that your SELECT might read data from uncommitted transactions that may be rolled back.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
March 17, 2008 at 1:20 am
Hi I am getting same error even using with nolock in select query???
March 17, 2008 at 2:01 am
Hi
Are you sure its the right "select" statement that you have put nolock on. Better check things once again.
"Keep Trying"
March 17, 2008 at 3:06 am
Hi,
Be sure you apply 'WITH NO LOCK' on every table of your FROM clause...
On the other hand, I think you should first find which INSERT/UPDATE statement holds locks for such a long time...
P.
Patrick Duflot
March 17, 2008 at 7:37 am
You could set Isolation Level read Uncommitted for the whole stored proc that has the select that causes dead locks
-Roy
March 17, 2008 at 1:48 pm
Personally I'd recommend finding the cause of the deadlocks and resolving that (usually bad code or bad indexing) rather than putting nolock everywhere. It can have some interesting effects (read uncommitted data, read rows twice, miss rows entirely and the like)
Nolock's basically saying to SQL that you don't mind if the data's not 100% accurate.
Enabling traceflags 1204 or 1222 will write the deadlock graphs into the error log. With that info, you can identify the processes involved in the deadlock, what procs and what queries in the procs they were running at the time. You can also see the deadlock resource. With that information, 8it should be possible to fix the root cause of the deadlocks.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 17, 2008 at 11:07 pm
Hello Gail,
U r absoulately correct about putting Nolock every where is not the best way to avoid the deadlocks becouse it will cause dirty read on the tables where we put Nolock while selecting.But it must be the solution to prevant deadlock condition.
But in my case I have put even with nolock condition for each table what I am using to select data eventhough I am getting the same error in peak hours.That means there is no meaning of using nolock??Is QSL Server 2005 Dynamically select locks irrespective of the hints we used in he sql server.......
Alkesh K.
MCP SQL Server Developer
March 18, 2008 at 9:52 am
Have you checked what the statements are that are involved in the deadlocks?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 18, 2008 at 10:18 am
I'm with Gail here folks. Why not find and fix the problem instead of masking it with NOLOCKs? If you are 100% OK with dirty reads, maybe consider locking hints/local isolation level changes, but I personally have not seen too many occasions where dirty reads are really ideal.
March 18, 2008 at 10:26 am
I'd have to agree. Just about the only thing preventing NOLOCK would be a schema-lock, or something changing your DDL. Do you have something routinely modifying your table structure????
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
March 18, 2008 at 12:44 pm
I agree with the others... find and fix the problem... and, Know this... Setting the Transaction Isolation Level and using WITH (NOLOCK) is NOT a panacea for fixing deadlocks.
We were getting 640 deadlocks per day... the folks before me put WITH (NOLOCK) on every single table name in all the stored procedures and UDF's everywhere... it didn't help because it only works on SELECTs, not Updates, Inserts, or Deletes.
When you find the code that's causing it, post it and maybe we can help.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 19, 2008 at 12:32 am
Matt Miller (3/18/2008)
I'd have to agree. Just about the only thing preventing NOLOCK would be a schema-lock, or something changing your DDL. Do you have something routinely modifying your table structure????
It could be that the deadlocks are from data modifications (update insert, delete), since they will always take locks.
I can't recall ever seeing a deadlock that didn't have al least one data modificaion (or an X locking hint) involved.
akumar: Post the deadlock graph here, and we can help you interpret it.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 19, 2008 at 10:52 pm
I am agree with your view that sm update statements might be present in the batch that will create the deadlock condition but why with nolock on each table in select query will break the deadlock ,because ultimately with nolock will fetch all commited and uncommited
data then why sql server creating deadlock.......????
I will try to get the deadlock graph today for same senarion and put here, might help us to find the reason...
Thanks
Alkesh K.
MCP DB Developer
March 20, 2008 at 8:01 am
Mr. Moden and Gilamonster are correct.
I strongly suggest using sp_who and sp_who2, Activity Monitor, or SQL Server Profiler to see what is blocking.
Then look at the suspect code, I bet you find something that could use some tuning.
If you have to put NOLOCK on all your sps, I'd say there's probably something bad wrong.
WITH NOLOCK is not much of a solution.
Viewing 15 posts - 1 through 15 (of 27 total)
You must be logged in to reply to this topic. Login to reply