cancling a rebuild clustered index

  • Hi

    What happen when I stop rebuilding a clustered index on a 400 G data table?

    I stopped it and the rollback operation has taken 3 hours and has not finished yet.

    What can I do ,the whole database is locked.

  • You just have to wait for the rollback to complete (and yes it may take a very long time for such a large table). What do you mean the entire database is locked? The locks should just be on the table itself (unless you are clicking around in SSMS, then you typically will get locked up - but you should be free to run TSQL in another instance of SSMS

    ______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience

  • MyDoggieJessie (3/15/2014)


    What do you mean the entire database is locked? The locks should just be on the table itself (unless you are clicking around in SSMS, then you typically will get locked up - but you should be free to run TSQL in another instance of SSMS

    Yes when I want to click around in SSMS to open the database I get the locked error ,

    and another question is that does it need free space for log or tempdb in rollback?

  • you will need to run a query to find "your" blocked spid and kill that if you want to use the current SSMS application you have open (you will need to do this several times to unblock it).

    It depends. Did you specify it to sort in tempdb on or off?

    Yes it is logged. If you are in full recovery make sure your transaction log backups are running regularly

    ______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience

  • how long does it take to finish approximately?

    No the sort in tempdb option is off

    you mean by this script I find the blocked spid and kill it manually?

    SELECT p.spid,

    DB_NAME(p.dbid) AS DBName,

    p.hostname,

    p.loginame,

    p.blocked AS blocked_by,

    (

    SELECT t.[text]

    FROM sys.dm_exec_sql_text(sql_handle) AS t

    ) AS [QUERY],

    p.waittime,

    p.cpu,

    p.[status],

    p.program_name,

    p.cmd,

    p.waittype,

    p.nt_username,

    p.login_time,

    p.nt_domain,p.memusage

    FROM sys.sysprocesses p

    WHERE p.spid > 50

    AND DB_NAME(p.dbid)=dbname

    I checked in activity monitor and rebuild statement is the only statement running on database

  • A rollback takes as long or longer than the operation had until the point it was cancelled. You wait, because there's nothing else you can do.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • A rollback takes as long or longer than the operation had until the point it was cancelled. You wait, because there's nothing else you can do.

    Gile,

    Suppose an index rebuild job was running for 5 hours. In case if u cancel it then, will it take a minimum 5 hours or longer to rolllback ..?

  • Joy Smith San (3/15/2014)


    A rollback takes as long or longer than the operation had until the point it was cancelled. You wait, because there's nothing else you can do.

    Gile,

    Suppose an index rebuild job was running for 5 hours. In case if u cancel it then, will it take a minimum 5 hours or longer to rolllback ..?

    Yep.

    ______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience

  • Joy Smith San (3/15/2014)


    A rollback takes as long or longer than the operation had until the point it was cancelled. You wait, because there's nothing else you can do.

    Gile,

    Suppose an index rebuild job was running for 5 hours. In case if u cancel it then, will it take a minimum 5 hours or longer to rolllback ..?

    Assuming that was 5 hours of processing and not a blocked process waiting that long, yes, 5 hours or more. But, if the process was blocked, which is what caused it to run so long, the rollback could be fast.

    ----------------------------------------------------The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood... Theodore RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software

  • Thanks all.....Once one of our weekly index rebuild which normaly takes 7 hours was not compeleted till Monday morning. However when I cancelled the job it took hardly an hour to rollback. Hence I asked... Yes, there was blocking of course...

  • Joy Smith San (3/16/2014)


    Thanks all.....Once one of our weekly index rebuild which normaly takes 7 hours was not compeleted till Monday morning. However when I cancelled the job it took hardly an hour to rollback. Hence I asked... Yes, there was blocking of course...

    It might actually work out better if you determined what the other things that were blocking were doing and maybe kill their spids instead of the index rebuild spid.

    Shifting gears, killing spids always scares the hell out of me especially since it can leave a spid in a "zero rollback" that does nothing but eat CPUs. Frequently, the only way to fix those is to bounce the service. There's actually a CONNECT item on this problem.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply