Extreme wait-time when taking a SQL Server database offline

前端 未结 17 915
有刺的猬
有刺的猬 2021-01-29 17:05

I\'m trying to perform some offline maintenance (dev database restore from live backup) on my dev database, but the \'Take Offline\' command via SQL Server Management Studio is

相关标签:
17条回答
  • 2021-01-29 17:44

    For me, I just had to go into the Job Activity Monitor and stop two things that were processing. Then it went offline immediately. In my case though I knew what those 2 processes were and that it was ok to stop them.

    0 讨论(0)
  • 2021-01-29 17:47

    After some additional searching (new search terms inspired by gbn's answer and u07ch's comment on KMike's answer) I found this, which completed successfully in 2 seconds:

    ALTER DATABASE <dbname> SET OFFLINE WITH ROLLBACK IMMEDIATE
    

    (Update)

    When this still fails with the following error, you can fix it as inspired by this blog post:

    ALTER DATABASE failed because a lock could not be placed on database 'dbname' Try again later.

    you can run the following command to find out who is keeping a lock on your database:

    EXEC sp_who2
    

    And use whatever SPID you find in the following command:

    KILL <SPID>
    

    Then run the ALTER DATABASE command again. It should now work.

    0 讨论(0)
  • 2021-01-29 17:50

    There is most likely a connection to the DB from somewhere (a rare example: asynchronous statistic update)

    To find connections, use sys.sysprocesses

    USE master
    SELECT * FROM sys.sysprocesses WHERE dbid = DB_ID('MyDB')
    

    To force disconnections, use ROLLBACK IMMEDIATE

    USE master
    ALTER DATABASE MyDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
    
    0 讨论(0)
  • 2021-01-29 17:50

    execute the stored procedure sp_who2

    This will allow you to see if there is any blocking locks.. kill their should fix it.

    0 讨论(0)
  • 2021-01-29 17:50

    Closing the instance of SSMS (SQL Service Manager) from which the request was made solved the problem for me.....

    0 讨论(0)
  • 2021-01-29 17:50

    In my case i stopped Tomcat server . then immediately the DB went offline .

    0 讨论(0)
提交回复
热议问题