SQL Server: Database stuck in “Restoring” state

前端 未结 26 1865
后悔当初
后悔当初 2020-11-28 17:09

I backed up a database:

BACKUP DATABASE MyDatabase
TO DISK = \'MyDatabase.bak\'
WITH INIT --overwrite existing

And then tried to restore it

相关标签:
26条回答
  • 2020-11-28 17:38

    All the WITH RECOVERY based options did not work for me.

    What did was to do the complete restore from Management Studio.

    USE [master]
    RESTORE DATABASE Sales_SSD
    FROM  DISK = N'D:\databaseBackups02\Daily_Sales_20150309_0941.bak' 
    WITH  FILE = 1,  
    MOVE N'Sales_Data' TO N'C:\Data\SSD\Sales.mdf',  
    MOVE N'Sales_Log' TO N'C:\Data\SSD\Sales_1.ldf',  
    NOUNLOAD,  REPLACE,  STATS = 5
    
    0 讨论(0)
  • 2020-11-28 17:39

    Use the following command to solve this issue

    RESTORE DATABASE [DatabaseName] WITH RECOVERY
    
    0 讨论(0)
  • 2020-11-28 17:39

    What fixed it for me was

    1. stopping the instance
    2. creating a backup of the .mdf and .ldf files in the data folder
    3. Restart the instance
    4. delete the database stuck restoring
    5. put the .mdf and.ldf files back into the data folder
    6. Attach the instance to the .mdf and .ldf files
    0 讨论(0)
  • 2020-11-28 17:43

    I had a similar incident with stopping a log shipping secondary server. After the command to remove the server from log shipping and stopped the log shipping from primary server the database on secondary server got stuck in restoring status after the command

    RESTORE DATABASE <database name> WITH RECOVERY
    

    The database messages:

    RESTORE DATABASE successfully processed 0 pages in 18.530 seconds (0.000 MB/sec).

    The database was usable again after those 18 seconds.

    0 讨论(0)
  • 2020-11-28 17:44

    I had a . in my database name, and the query didn't work because of that (saying Incorrect syntax near '.') Then I realized that I need a bracket for the name:

    RESTORE DATABASE [My.DB.Name] WITH RECOVERY
    
    0 讨论(0)
  • 2020-11-28 17:45

    I had a similar issue with restoring using SQL Management Studio. I tried to restore a backup of the database to a new one with a different name. At first this failed and after fixing the new database's file names it was successfully performed - in any case the issue I'm describing re-occurred even if I got this right from the first time. So, after the restoration, the original database remained with a (Restoring...) next to its name. Considering the answers of the forum above (Bhusan's) I tried running in the query editor on the side the following:

    RESTORE DATABASE "[NAME_OF_DATABASE_STUCK_IN_RESTORING_STATE]"
    

    which fixed the issue. I was having trouble at first because of the database name which contained special characters. I resolved this by adding double quotes around - single quotes wouldn't work giving an "Incorrect syntax near ..." error.

    This was the minimal solution I've tried to resolve this issue (stuck database in restoring state) and I hope it can be applied to more cases.

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