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
Solved

DeadLocks!

Posted on 2015-01-13
9
126 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 250 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 69

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 48

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 250 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

828 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