SQL Server: Database stuck in “Restoring” state

前端 未结 26 1864
后悔当初
后悔当初 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:52

    In my case, it was sufficient to drop the database which was hanging in state "Restoring..." with the SQL command

     drop database <dbname> 
    

    in a query window.

    Then I right-clicked on Databases and selected Refresh which removed the entry in Management Studio. Afterwards I did a new restore which worked fine (note that bringing it offline did not work, a restart of the SQL service did not work, a server reboot did not work as well).

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

    OK, I have similar problem and exactly as it was in case of Pauk, it was caused by the server running out of disk space while restoring and so caused a permanent restoring state. How to end this state without stopping SQL Server services?

    I have found a solution :)

    Drop database *dbname*
    
    0 讨论(0)
  • 2020-11-28 17:53
    1. Let check and run SQL Agent Service firstly.
    2. Using following T-SQL:

      SELECT filename FROM master.sys.sysaltfiles WHERE dbid = DB_ID('db_name');

    3. Using T-SQL continuously:

      RESTORE DATABASE FROM DISK = 'DB_path' WITH RESTART, REPLACE;

    Hope this help!

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

    I had this situation restoring a database to an SQL Server 2005 Standard Edition instance using Symantec Backup Exec 11d. After the restore job completed the database remained in a "Restoring" state. I had no disk space issues-- the database simply didn't come out of the "Restoring" state.

    I ran the following query against the SQL Server instance and found that the database immediately became usable:

    RESTORE DATABASE <database name> WITH RECOVERY
    
    0 讨论(0)
  • 2020-11-28 17:54

    WITH RECOVERY option is used by default when RESTORE DATABASE/RESTORE LOG commands is executed. If you're stuck in "restoring" process you can bring back a database to online state by executing:

    RESTORE DATABASE YourDB WITH RECOVERY
    GO
    

    If there's a need for multiple files restoring, CLI commands requires WITH NORECOVERY and WITH RECOVERY respectively - only the last file in command should have WITH RECOVERY to bring back the database online:

    RESTORE DATABASE YourDB FROM DISK = 'Z:\YourDB.bak'
    WITH NORECOVERY
    GO
    RESTORE LOG YourDB FROM DISK = 'Z:\YourDB.trn'
    WITH RECOVERY
    GO
    

    You can use SQL Server Management Studio wizard also:

    enter image description here

    There is also virtual restoring process, but you'll have to use 3rd party solutions. Usually you can use a database backup as live online database. ApexSQL and Idera has their own solutions. Review by SQL Hammer about ApexSQL Restore. Virtual restoring is good solution if you're dealing with large numbers of backups. Restore process is much faster and also can save a lot of space on disk drive. You can take a look on infographic here for some comparison.

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

    This may be fairly obvious, but it tripped me up just now:

    If you are taking a tail-log backup, this issue can also be caused by having this option checked in the SSMS Restore wizard - "Leave source database in the restoring state (WITH NORECOVERY)"

    enter image description here

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