Yesterday one of my production database went into restoring mode,but fortunately i recovered it using below query
USE MASTER
EXEC SP_CONFIGURE 'Allow updates',1
RECONFIGURE WITH OVERRIDE
GO
EXEC SP_RESETSTATUS 'DatabaseNAME'
DBCC DBRECOVER('DatabaseName')
EXEC SP_CONFIGURE 'Allow updates',0
GO
RECONFIGURE WITH OVERRIDE
GO
It brought my database online, but I want to know why it went in restoring mode, I read SQL error log but I didn't get much information about it. Is the query I used to bring the database online correct? It is used to recover the database from suspect mode.
Best Answer
(Restoring...)
is typically seen under two circumstances.You're restoring a database, and have specified the
WITH NORECOVERY
option to allow, typically, log backups to be restored. The last restore operation would not use theWITH NORECOVERY
option, thereby directing SQL Server to run the recovery process on the database, and allow client access to it.You've taken a backup of the database logfile, and have specified the
WITH NORECOVERY
option to ensure you have backed up the tail of the log. This option might be used to ensure no one can access the database in anticipation of migrating the database to a different server. You may inadvertently use this option when running a transaction log backup via the GUI:While a database is being restored, it will show up as
RESTORING
.You can test the tail log recovery scenario mentioned above in option 2 using this MCVE:
First, we create a database, and set it to FULL recovery:
This shows the state of the database:
Here we backup the tail of the log. (NOTE, this is NOT a real backup, since the target is the NUL: device. DO NOT USE THIS IN PRODUCTION!)
Now, when we look at the state of the database:
This statement will cause SQL Server to run the recovery process on the database to return it to the
ONLINE
state: