Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Job -Stored Procedure Failing

Author  Topic 

dim
Yak Posting Veteran

57 Posts

Posted - 2010-12-20 : 10:47:14
Hi,

I have a SQL server job that comprises of three steps and is schedule to run the job every night and it keeps failing at last step with the error :

sg 1205, Sev 13, State 52, Line 225 : Transaction (Process ID 294) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction. [SQLSTATE 40001]


The error message is taken from the log file for this job.

Basically at this step it is trying to update the destination table with lots of records and probably failing to do so.

The step at which the job fails is execution of a stored procedure.

Please let me know where could I start with debugging the job to set it right. What might be the possible reason for this sp to stop running. The dba's tell that there are no other processes running at the same time .

Please advice.

Thank you,


Dp

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-12-20 : 10:53:09
For Agent jobs that can suffer from deadlocks, we add retry steps.

To debug this, you'll need to determine who the owner of the deadlock is. You can do this by adding a trace flag or by viewing the deadlock graph in Profiler.

For the trace flag then, you can run this for the current session of SQL Server:
DBCC TRACEON(1222,-1)

In case you want to track deadlocks after SQL gets restarted sometime in the future, have the DBA also add -T1222 to the startup parameters for SQL Server.

The deadlock output using the trace flags will be put into the SQL Server Error Log. It'll be rather confusing to read, so have your DBA help you with it.

You should also consider READ_COMMITTED_SNAPSHOT isolation level, especially if the deadlock owner is found to be a read-only query.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

dim
Yak Posting Veteran

57 Posts

Posted - 2010-12-20 : 13:30:34
Hi tkizer,

I did have my dba look at the profiler and do as you suggested. I have SQL profiler results from Trace Start and Trace Stop eventclass. It says lock:Deadlock Chain. In one of the lines description in the textdata it says: Parallel query worker thread was involved in a deadlock.

Can you advice which part of the query might casue this.

Thank you,


Dp
Go to Top of Page

dim
Yak Posting Veteran

57 Posts

Posted - 2010-12-20 : 14:24:25

The query is trying to do an update on a table. Would that mean applying no lock on that table? would that not allow bad updated data in the table?

Dp
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-12-20 : 14:39:32
Nolock is not a solution for deadlocks in my opinion. Dirty reads are bad.

In order to help you with the deadlocks, you'll need to post the deadlock owner's query. Have you looked into RCSI?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

dim
Yak Posting Veteran

57 Posts

Posted - 2010-12-20 : 15:02:09
Hi tkizer,

Thank You for the response. The query that might be causing deadlock to occur is as below:

UPDATE FIC.dbo.Contact
SET
contact_Updated_ind = 'Y'
, datetime_updated = getdate()
, last_action_cd = 'U'
, last_program = 'Differential'
, last_source_system = 'ix'
, user_updated = USER
FROM
FIC.dbo.Contact C
INNER JOIN
WorkStaging_Ebix_Address_Type WA
ON WA.Contact_ID = C.Contact_ID
INNER JOIN
FIC.dbo.Address_Type A
ON WA.Contact_ID = A.Contact_ID
AND WA.Address_Type = A.Address_Type
WHERE
WA.Contact_ID IS NOT NULL
AND
WA.Address_ID IS NOT NULL
AND
WA.Address_Type_ID IS NULL

Would using cursors to update records by row level help?

Dp
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-12-20 : 15:04:52
We can't troubleshoot something that might be the culprit. We have to know exactly what the culprit is. The deadlock graph and the deadlock trace flag will provide the query for the deadlock owner. We need that query.

We'll also need the query of the deadlock victim.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -