Showing posts with label locking. Show all posts
Showing posts with label locking. Show all posts

Wednesday, March 28, 2012

Killing the process automatically

Hi everybody,

We have a very large database and high transaction volume. Time to time
these transactions are locking each other and decrease the performance
of the database. Is there any way that I can automate the killing
process when blocking and deadlock time is exceeded in certain time
elipsade? Can somebody help me on this please?

Regards

asa.laststubborn wrote:
> Hi everybody,
> We have a very large database and high transaction volume. Time to time
> these transactions are locking each other and decrease the performance
> of the database. Is there any way that I can automate the killing
> process when blocking and deadlock time is exceeded in certain time
> elipsade? Can somebody help me on this please?

If SQL Server detects a deadlock it will kill one of the two involved TX
automatically. But you should really change your app to prevent these
deadlocks.

You probably cannot do much about normal locking as this is expected
behavior other than probably optimizing your SQL to make it faster.

HTH

robert|||Is it possible to change this deadlock killing time? for instance lets
say instead of 5 min change it to 2 min??

Thanks|||laststubborn wrote:
> Is it possible to change this deadlock killing time? for instance lets
> say instead of 5 min change it to 2 min??

read the docs (BOL)

Customizing the Lock Time-out
When Microsoft SQL Server 2000 cannot grant a lock to a transaction on
a resource because another transaction already owns a conflicting lock
on that resource, the first transaction becomes blocked waiting on that
resource. If this causes a deadlock, SQL Server terminates one of the
participating transactions (with no time-out involved). If there is no
deadlock, the transaction requesting the lock is blocked until the other
transaction releases the lock. By default, there is no mandatory
time-out period, and no way to test if a resource is locked before
locking it, except to attempt to access the data (and potentially get
blocked indefinitely).

robert|||laststubborn (arafatsalih@.gmail.com) writes:
> Is it possible to change this deadlock killing time? for instance lets
> say instead of 5 min change it to 2 min??

A deadlock does not take five minutes to sort out. It seems that you
have a misconception of what a deadlock is. A deadlock is when two
processes are blocking each other, so none of them can continue. This
is something that SQL Server detects automatically. It usually takes a
couple of seconds.

But one long-running process can block other processes (than in their
turn can block other processes etc) without any deadlock to occur.

I would advice against any automatic killing, as supposedly some processes
are more important than others. It's better to analyse what those blockers
are up to, and if the queries can be improved, or indexes added to
speed up these queries.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Not sure if this could be relevant but perhaps add WITH(NOLOCK) on your
queries.. With this, no locks would actually happen.|||"D0MZE" <domze.sa@.gmail.com> wrote in message
news:1144891406.165135.214850@.i40g2000cwc.googlegr oups.com...
> Not sure if this could be relevant but perhaps add WITH(NOLOCK) on your
> queries.. With this, no locks would actually happen.

Not quite.

For a select it basically means to ignore locks on rows.

This can mean you can get phantom rows, not get rows you should etc. i.e.
you'll get an inconsistent view of the table at the time.

This MAY be acceptable in some circumstances, but in others would be
completely verbotin. (imagine an ATM that did a look up on cache available
with a (NOLOCK) while your bank is deleting your last check. You'd falsely
be told you have more money available than you actually do and could
overdraw the account.)

Monday, March 26, 2012

Killing Locks by Object - SS2005

splocI can't restore a database due to a locking issue. While I've killed
the Process in Activity Monitor, I still see the database listed on the Locks
By Object page. The Process ID is a negative number. Any ideas as to what I
can do to get rid of this lock?
Here's the output from sp_lock: -2 7 0 0 DB
S GRANT
Thanks in advance.
JohnOn Oct 5, 1:49 am, John Roberts
<JohnRobe...@.discussions.microsoft.com> wrote:
> splocI can't restore a database due to a locking issue. While I've killed
> the Process in Activity Monitor, I still see the database listed on the Locks
> By Object page. The Process ID is a negative number. Any ideas as to what I
> can do to get rid of this lock?
> Here's the output from sp_lock: -2 7 0 0 DB
> S GRANT
> Thanks in advance.
> John
After killing the process you may try putting database in single user
mode which would prevent application or user establishing connection.
Thanks
VS|||Thanks for the response..
When I do a select distinct req_transactionuow, req_transactionID from
syslockinfo where req_spid = -2
I see the follwing:
req_transactionuow req_transactionID
--
--
00000000-0000-0000-0000-000000000000 0
When I try to kill this UOW using the guid of all zeroes, we get the
following error:
Msg 6110, Level 16, State 1, Line 1
The distributed transaction with UOW {00000000-0000-0000-0000-000000000000}
does not exist.
Anybody out there familiar with killing orphaned transactions where the UOW
GUID is all zeros? My only solution now is to restart the service and, as
you might have imagined, that's NOT the only database running!!
Thanks in advance.
John
"vijay" wrote:
> On Oct 5, 1:49 am, John Roberts
> <JohnRobe...@.discussions.microsoft.com> wrote:
> > splocI can't restore a database due to a locking issue. While I've killed
> > the Process in Activity Monitor, I still see the database listed on the Locks
> > By Object page. The Process ID is a negative number. Any ideas as to what I
> > can do to get rid of this lock?
> >
> > Here's the output from sp_lock: -2 7 0 0 DB
> > S GRANT
> >
> > Thanks in advance.
> >
> > John
> After killing the process you may try putting database in single user
> mode which would prevent application or user establishing connection.
> Thanks
> VS
>

Killed/Rollback process hogging ALL CPU resources.

I have a test database for the end users to test their select queries for reports.
One of my users is writing queries that cause locking in the database. I killed the process last evening and they are in Killed/Rollback status but are still hogging 90% of the CPU resources for the past 12 hrs. I tried killing them several times but no go.

I know that the best way to clear of these processes is by restarting SQL Server. If that is not an option is there is any other way we can clean these processes?

Also the user running these queries has a read only and create view access to the database. From my experience processes that go into Kill/Rollback state after you kill them are processes associated with some update transaction. Since the user as far as i know is running Select commands would an infinite loop cause this ?

thanks
ninaWhat a good time to talk about execute only authorit to stored procedures...

Your rool back can take up 2 twice as long as the original process...maybe longer...

I doubt it was select only...any chance a work table was involved with millions of rows and they did a delete to clear it out?

Guess you don't have the opportunity to do a code review...

If you stop and restart the server, it'll just pick up from where it left off.

What version is this?

Is this a dev or production box?

I know I saw someone once who discussed this...but it was messy

Before you issue a kill, you should find out what the spid was doing...did you do sp_who to see how much I/O and CPU it was using?

Do you monitor the developers with profiler?

What login Id did the developer login with?|||Hello Brett
thanks for responding. This is a development box and that is probably the only good thing about this entire mess.
And no i killed the process without actually looking into the query that it was running. It is SQL Server 2000 box and the user has a SQL Server account and he uses query analyzer to write/test his queries.
The user has create view rights and belongs to db_datareader role for just the one test database on the server.
Would a query running into an infinite loop cause this problem ?
Before killing the process it was using about 70% of CPU but it kept hogging more resources through the night after i killed it and this morning everything on the server came to a standstill as it hogged 99% of CPU|||Put the user in the pillory, until the rollback is complete. They should learn after that ;-)|||The rollback ran through the night and ate up all our server resources and still did not complete. I just went in and restarted the server. Since this is a development environment it was not that much of a problem.

What i would like to know is that was restarting the SQLServer the only option that we have in such a situation ? And also would a select query every cause a rollback ?|||My guess is that if the restart worked then it wasn't rolling back...

Did you check and see if to spids where deadlocked?|||Yes i did check for deadlocks and there were none in the system.|||OK, Try this next time

ALTER DATABASE dbname SET SINGLE_USER WITH ROLLBACK IMMEDIATE

That will throw everyone out without having to issue a kill

btw did you kill all spids?|||Thanks will keep the Alter statement for future reference. And yes i did try to kill all the processes accociated with that user. And since there were only 4-5 processes for that user i know i got them all.

Wednesday, March 21, 2012

Kill autoshrink process

On one of our databases the autoshrink process is locking a lot of users.
I want to stop the autoshrink process but I'm not able to kill the system
process.
How can I stop this process?Well, wait till is finished and turn this off
"Zekske" <Zekske@.discussions.microsoft.com> wrote in message
news:A4400A93-6471-42B4-A4C4-9F1324E0674C@.microsoft.com...
> On one of our databases the autoshrink process is locking a lot of users.
> I want to stop the autoshrink process but I'm not able to kill the system
> process.
> How can I stop this process?

Kill autoshrink process

On one of our databases the autoshrink process is locking a lot of users.
I want to stop the autoshrink process but I'm not able to kill the system
process.
How can I stop this process?Well, wait till is finished and turn this off
"Zekske" <Zekske@.discussions.microsoft.com> wrote in message
news:A4400A93-6471-42B4-A4C4-9F1324E0674C@.microsoft.com...
> On one of our databases the autoshrink process is locking a lot of users.
> I want to stop the autoshrink process but I'm not able to kill the system
> process.
> How can I stop this process?sql