Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DeadLocks!

Posted on 2015-01-13
9
Medium Priority
?
141 Views
Last Modified: 2015-02-05
I'm having problems with deadlocks and I don't think I should.

I fully understand how a deadlock is caused having a circle of resource requests, so no need to explain that.   Here is my situation..

I have a few parent-child tables that are used for reporting.   A user enters some criteria and a few hundred records are populated into the report tables based on the information entered, the user can then browse the report records created.   All reporting records have a unique report ID for a reporting session.  So each user is only touching those records for that session of reporting

Since every user is only touching records with his own unique report ID, there is no way that someone else's reporting form will access those same records.  They will insert/update records in the same table, but not those records.   So there should never be a dead lock.

So, why am I getting deadlocks and how do I prevent them?

The basic action of the reporting form is to (1) insert records using an insert-select statement (2) update those entered records and (3) delete those records if the user chooses to re-run the report

I was using SQL Server 2005 and now I have gone to 2012 and the problem is worse!
0
Comment
Question by:gdemaria
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 1000 total points
ID: 40547689
Deadlocks are not just on a record. They could be on a page or the entire table.

Maybe you should use dirty reads perhaps. I note that in your 1-2-3 you don't have any actual SELECT statements, so your summary may not be complete.

Try using Extended Events to see if you can track this down - in 2012 EXtended Events is much better than in previous versions,
0
 
LVL 39

Author Comment

by:gdemaria
ID: 40547716
Thanks Phillip - I will Google, Extended Events, I am not familiar with that.

Number (1) indicates an insert based on an insert-select statement.   The updates are also using select statements to complete the updates.

Under what circumstance would SQL Server lock the entire table?  And wouldn't that only for for a short time and once unlocked, the other records and proceed?   Why would that cause a deadlock?
0
 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 40547722
What are the clustering keys on all involved tables?

What are the join and WHERE conditions on those tables?

In the meantime, turn on trace flag 1222 so you can get more detailed on the deadlocking:

DBCC TRACEON ( 1222, -1 )
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 52

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 1000 total points
ID: 40548431
They will insert/update records in the same table, but not those records.   So there should never be a dead lock.
Inserts will cause a table lock and updates can cause at least a page lock so this may justify the dead locks.
As told above you can use dirty reads if that's not a problem. This can be accomplished by using locking hints. Ex.:
SELECT * FROM TableName WITH (NO_LOCK)
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40548453
For Extended Events, have a look at:

http://msdn.microsoft.com/en-GB/library/bb630282.aspx
https://www.youtube.com/watch?v=2cbNXFUdAUg
(This is a video)

If you do Google Extended Events, make sure you are reading about the 2012 (or 2014) version - the 2008R2 version is quite different.
0
 
LVL 39

Author Comment

by:gdemaria
ID: 40548785
I tried to do extended events, but got an error saying I didn't have permission.  I am using Amazon RDS SQL Server Web Edition, it may not be part of that, I have to check with support.

Thanks for the tip on dirty reads,  I don't think that would be a problem because no other process could update the same records.   If I do an insert followed by an update of those just inserted records, the inserted records would be there even though it was a dirty read, right?   Same thing with multiple updates in a row by the same process?

I'm surprised dirty reads is my only route.   Is this a huge flaw of SQL Server?  I used Oracle for years and dead locks were very, very rare.    As I said, the different users/processes never touch the same records so there logically should not be any deadlocks, it seems to be a flaw to lock the entire table - can I tell SQL Server not to do that?
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40548789
> I'm surprised dirty reads is my only route.

It's probably not the only route, but we are trying to diagnose from a distance. That's why I'm suggesting Extended Events or its equivalents to help you diagnose it.
0
 
LVL 39

Author Comment

by:gdemaria
ID: 40548822
Got it Phillip, I will try to get more information if Extended Events are allowed.
Thanks!
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40548828
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question