Learn more about SQL Server tools

mssqltips logo
 

Tutorials          DBA          Dev          BI          Career          Categories          Webcasts          Scripts          Today's Tip          Join

Tutorials      DBA      Dev      BI      Categories      Webcasts

DBA    Dev    BI    Categories

 

Killing a SPID and Checking Rollback progress in SQL Server


By:   |   Last Updated: 2008-04-09   |   Comments (5)   |   Related Tips: More > Monitoring

Problem

From time to time, I encounter blocking situations where I end up issuing a KILL command against the blocking SPID. When I run sp_who2, I can see the killed SPID is in a ROLLBACK state. Is there any way I can get an idea of how long the rollback for the SPID will take?

Solution

There sure is! The KILL command offers the WITH STATUSONLY argument which displays an estimation of completion for an in progress ROLLBACK. Using KILL with this argument does not kill a connection; it simply produces a progress report.

Run the following script in a new query window. It captures the connected SPID for the query and displays the fact that the SPID has an open transaction when the script completes:

set nocount on
go 
select 'SPID = ' + cast(@@spid as varchar) -- what connection is this?
go

create table test (col1 int identity) -- create a test table
go

begin tran tran1 -- start a transaction

while (1 = 1)
begin
   insert test default values
   if scope_identity() > 999999 -- break after inserting 1m rows
      break
end
go
dbcc opentran(0)
go
sql query

Now open a new connection and issue the following statements to kill the connection we just opened and to examine the connection's state:

kill 52
go
exec sp_who2
go
rollback

Now that we've KILLed the SPID, we can monitor its rollback progress by issuing KILL using the WITH STATUSONLY argument.

kill 52 with statusonly 
jester

As you can see, you can get a good estimation from the server of rollback progress.

Next Steps
  • Read about KILL UOW in the SQL Server Books Online
  • Read about DBCC OPENTRAN in the SQL Server Books Online


Last Updated: 2008-04-09


get scripts

next tip button



About the author
MSSQLTips author Armando Prato Armando Prato has close to 30 years of industry experience and has been working with SQL Server since version 6.5.

View all my tips
Related Resources




Post a comment or let the author know this tip helped.

All comments are reviewed, so stay on subject or we may delete your comment. Note: your email address is not published. Required fields are marked with an asterisk (*).

*Name    *Email    Email me updates 


Signup for our newsletter
 I agree by submitting my data to receive communications, account updates and/or special offers about SQL Server from MSSQLTips and/or its Sponsors. I have read the privacy statement and understand I may unsubscribe at any time.



    



Thursday, March 05, 2015 - 7:30:14 AM - Anderson Back To Top

Thank you. Very usefull tip!


Tuesday, May 07, 2013 - 1:27:08 PM - dinesh Back To Top
SPID 140:transtion rollback in process.Estaimated rollback completion:0%
 Estimated time remaining:0 seconds.
 
 
any Solutiuon??

Thursday, April 25, 2013 - 11:42:26 AM - Santosh Kamoli Back To Top

The Same issue of rollback i am facing while killing session of a tlog job.

 

Error "Transaction rollback in progress. Estimated rollback completion : 0%......."

 

Please recommend the solution or send me work around.

 

Thanks

Santosh Kamoli

 


Friday, August 03, 2012 - 5:32:07 AM - Rajasekhar Back To Top

Hi

when I use  kill 70with statusonly.this given the fallowing msg "SPID 70: transaction rollback in progress. Estimated rollback completion: 0%. Estimated time remaining: 0 seconds.".this showing o seconds from last 1 hour and since it has been executing.How can i know Much time still it will take..???


Saturday, March 24, 2012 - 9:37:47 AM - Shamsideen Back To Top

I ahve been having issue with SQl Server 2008 installed on Windows serv er 2008 R2.  The SQL takes most of the memory. the size out DB is about 52 GB and we have  8 GB RAM installed. Please help out. This the output of DBCC command


Learn more about SQL Server tools