ALTER DATABASE failed because a lock could not be placed on database

后端 未结 10 2227
感情败类
感情败类 2020-12-12 09:52

I need to restart a database because some processes are not working. My plan is to take it offline and back online again.

I am trying to do this in Sql Server Manage

相关标签:
10条回答
  • 2020-12-12 10:27

    I managed to reproduce this error by doing the following.

    Connection 1 (leave running for a couple of minutes)

    CREATE DATABASE TESTING123
    GO
    
    USE TESTING123;
    
    SELECT NEWID() AS X INTO FOO
    FROM sys.objects s1,sys.objects s2,sys.objects s3,sys.objects s4 ,sys.objects s5 ,sys.objects s6
    

    Connections 2 and 3

    set lock_timeout 5;
    
    ALTER DATABASE TESTING123 SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
    
    0 讨论(0)
  • 2020-12-12 10:29

    Try this if it is "in transition" ...

    http://learnmysql.blogspot.com/2012/05/database-is-in-transition-try-statement.html

    USE master
    GO
    
    ALTER DATABASE <db_name>
    
    SET OFFLINE WITH ROLLBACK IMMEDIATE
    ...
    ...
    ALTER DATABASE <db_name> SET ONLINE
    
    0 讨论(0)
  • In rare cases (e.g., after a heavy transaction is commited) a running CHECKPOINT system process holding a FILE lock on the database file prevents transition to MULTI_USER mode.

    0 讨论(0)
  • 2020-12-12 10:38

    In my scenario, there was no process blocking the database under sp_who2. However, we discovered because the database is much larger than our other databases that pending processes were still running which is why the database under the availability group still displayed as red/offline after we tried to 'resume data'by right clicking the paused database.

    To check if you still have processes running just execute this command: select percent complete from sys.dm_exec_requests where percent_complete > 0

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