Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
T-SQL (SS2K5)
»
Stored Proc and performance
13 posts, Page 1 of 2
1
2
»»
Stored Proc and performance
Rate Topic
Display Mode
Topic Options
Author
Message
dwilliscp
dwilliscp
Posted Wednesday, January 16, 2013 9:13 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 9:52 AM
Points: 187,
Visits: 332
Is there any SQL that can be added to a Stored Proc to track if there was any blocking of its SQL, or for that matter explain the example below?
I am tasked with explaining, and if possible fixing, jobs that sometimes run more than twice their normal run times. A good example is a program that almost always runs in less than one min, but this morning it took 4 1/2 hours to run. This created problems since our data was not fully loaded when folks started using the application.
Thanks
Post #1407911
dwain.c
dwain.c
Posted Wednesday, January 16, 2013 5:47 PM
SSCrazy
Group: General Forum Members
Last Login: Yesterday @ 6:07 PM
Points: 2,340,
Visits: 3,167
You could try turning on the deadlocks trace flag:
DBCC TRACEON (1222, -1)
And then checking the log to see if it reports deadlocks during the period the job is running.
No loops! No CURSORs! No RBAR! Hoo-uh!
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Are you too recursively challenged?
Splitting strings based on patterns can be fast!
Post #1408111
Suresh B.
Suresh B.
Posted Thursday, January 17, 2013 2:03 AM
Ten Centuries
Group: General Forum Members
Last Login: Today @ 2:38 AM
Points: 1,075,
Visits: 5,116
dwilliscp (1/16/2013)
Is there any SQL that can be added to a Stored Proc to track if there was any blocking of its SQL, or for that matter explain the example below?
I am tasked with explaining, and if possible fixing, jobs that sometimes run more than twice their normal run times. A good example is a program that almost always runs in less than one min, but this morning it took 4 1/2 hours to run. This created problems since our data was not fully loaded when folks started using the application.
Thanks
No. There is no SQL that can be added to a Stored Proc to track if there was any blocking of its SQL.
But you can create another job to periodically check for the blocking and send you alert if there is any blocking.
You can start here:
select * from sys.dm_exec_requests where blocking_session > 0
Note that your job might have taken 4.5 hrs due to some other reason also (not necessary due to blocking).
There was no deadlock. Deadlock would fail the job.
Post #1408221
dwain.c
dwain.c
Posted Thursday, January 17, 2013 5:23 AM
SSCrazy
Group: General Forum Members
Last Login: Yesterday @ 6:07 PM
Points: 2,340,
Visits: 3,167
Suresh B. (1/17/2013)
There was no deadlock. Deadlock would fail the job.
Incorrect. SQL Server kills only the transaction that costs the least to rollback, so the competing transaction could have been killed and the SP completed without failure.
No loops! No CURSORs! No RBAR! Hoo-uh!
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Are you too recursively challenged?
Splitting strings based on patterns can be fast!
Post #1408357
dwilliscp
dwilliscp
Posted Thursday, January 17, 2013 8:03 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 9:52 AM
Points: 187,
Visits: 332
Thanks I will try and see what I get, but not sure that it will show much if I am just checking for deadlocks. All the job (at that step does) is copy records from one table to update a different table. PerfMon did not show anything abnormal (CPU,Mem,Phy IO), so my guess is that a user was in making changes to the forecast and did not file the screen... but that is just a guess. If I am right it would not have created a deadlock, just blocking.
Post #1408435
dwain.c
dwain.c
Posted Thursday, January 17, 2013 5:22 PM
SSCrazy
Group: General Forum Members
Last Login: Yesterday @ 6:07 PM
Points: 2,340,
Visits: 3,167
dwilliscp (1/17/2013)
Thanks I will try and see what I get, but not sure that it will show much if I am just checking for deadlocks. All the job (at that step does) is copy records from one table to update a different table. PerfMon did not show anything abnormal (CPU,Mem,Phy IO), so my guess is that a user was in making changes to the forecast and did not file the screen... but that is just a guess. If I am right it would not have created a deadlock, just blocking.
Here my experience is a little rough but my understanding is that blocks are a normal process. SQL must block some transactions, allowing others to complete if they've established locks. When a lock is kept and held for too long, the blocked transaction will then be considered in deadlock with it. So that is when SQL Server kicks in to decide which of the transaction processes should be killed.
No loops! No CURSORs! No RBAR! Hoo-uh!
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Are you too recursively challenged?
Splitting strings based on patterns can be fast!
Post #1408680
Lynn Pettis
Lynn Pettis
Posted Thursday, January 17, 2013 9:27 PM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 12:02 AM
Points: 21,596,
Visits: 27,415
dwain.c (1/17/2013)
dwilliscp (1/17/2013)
Thanks I will try and see what I get, but not sure that it will show much if I am just checking for deadlocks. All the job (at that step does) is copy records from one table to update a different table. PerfMon did not show anything abnormal (CPU,Mem,Phy IO), so my guess is that a user was in making changes to the forecast and did not file the screen... but that is just a guess. If I am right it would not have created a deadlock, just blocking.
Here my experience is a little rough but my understanding is that blocks are a normal process. SQL must block some transactions, allowing others to complete if they've established locks. When a lock is kept and held for too long, the blocked transaction will then be considered in deadlock with it. So that is when SQL Server kicks in to decide which of the transaction processes should be killed.
Not correct, Dwain. Blocking and Deadlock are two different beasts. A deadlock exists if two processes are are waiting are each waiting for a resource locked by the other process. If a process is simply blocked by another, like an update is waiting for a shared read (not sure of the correct term) to be released to place an exclusive lock to make an update, you may get a time-out, but it isn't deadlocked.
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #1408704
dwain.c
dwain.c
Posted Thursday, January 17, 2013 9:33 PM
SSCrazy
Group: General Forum Members
Last Login: Yesterday @ 6:07 PM
Points: 2,340,
Visits: 3,167
Lynn Pettis (1/17/2013)
A deadlock exists if two processes are are waiting are each waiting for a resource locked by the other process.
Easy for you to say.
Like I said, I was a little rough on this myself, so figured someone would come along and correct me.
No loops! No CURSORs! No RBAR! Hoo-uh!
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Are you too recursively challenged?
Splitting strings based on patterns can be fast!
Post #1408707
tyson.price
tyson.price
Posted Monday, January 21, 2013 5:11 AM
Valued Member
Group: General Forum Members
Last Login: Yesterday @ 6:10 AM
Points: 74,
Visits: 599
Any old CICS mainframe programmers here remember calling a deadlock a "deadly embrace"? That wasn't limited to just databases, which were relatively new in my environment (we were still using VSAM), but also the resources that you needed to control.
Post #1409497
dwain.c
dwain.c
Posted Monday, January 21, 2013 5:40 AM
SSCrazy
Group: General Forum Members
Last Login: Yesterday @ 6:07 PM
Points: 2,340,
Visits: 3,167
tyson.price (1/21/2013)
Any old CICS mainframe programmers here remember calling a deadlock a "deadly embrace"? That wasn't limited to just databases, which were relatively new in my environment (we were still using VSAM), but also the resources that you needed to control.
I remember VSAM. Wasn't the utility to create them called IDCAMS?
Thanks for the trip down memory lane.
No loops! No CURSORs! No RBAR! Hoo-uh!
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Are you too recursively challenged?
Splitting strings based on patterns can be fast!
Post #1409510
« Prev Topic
|
Next Topic »
13 posts, Page 1 of 2
1
2
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.