Improve company productivity with a Business Account.Sign Up

x
?
Solved

DeadLocks!

Posted on 2015-01-13
9
Medium Priority
?
157 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
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
A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

 
LVL 54

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

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Microsoft provides a rich set of technologies for High Availability and Disaster Recovery solutions.
In this article, we will see two different methods to recover deleted data. The first option will be using the transaction log to identify the operation and restore it in a specified section of the transaction log. The second option is simpler and c…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

606 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