Hello, Welcome to my blog

Recover SQL Server Database Suspect Mode

0 Comments »

I got stuck with a SQL Server database which is on suspect mode and need to recover it without having any recent backups in hand. I Googled for quite a long time and found these steps to bring back the database to online state without losing any data. I found these steps very useful and I hope they will be useful to others who face similar problem

Step 1:
Open SQL Server Management Studio and connect to the SQL Server. Make sure that your current database is set to master

Step 2:
Clear the suspect mode of the database using sp_resetstatus DatabaseName. This will clear the suspect flag and make the database available online

Step 3:
Change the database status to Emergency using the following command. Emergency mode allows you to access the databases as normal but with no consistency guarantee. This option also allows us to export the table data so that we can minimize the damage.

ALTER DATABASE DatabaseName SET EMERGENCY;

Step 4:
Restrict database to single user by changing the access mode as mentioned below
ALTER DATABASE DatabaseName SET SINGLE_USER;

Step 5:
Run the CHECKDB command with “REPAIR_ALLOW_DATA_LOSS” option. This option should be tried as last option as it always behaves the way it is named. We are not sure of what data it removes.

DBCC CHECKDB (DatabaseName, REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS, ALL_ERRORMSGS;

Even though the step 4 is expected to result in data loss while repairing the database, I was lucky to restore the database without any loss. My job would have been much easier if the admin of the database server followed few general guidelines that allow recovery of database in case of any unexpected failures. Here are the few of them

  • Backup your data frequently. (once in two days or daily or even more frequent depending on your needs)
  • Have multiple backups. Move the backups to external drives or tapes frequently
  • Validate that your backups are good by performing trial restores to alternate server
  • Run CHECKDB regularly if possibly in your case, to know how long it regularly takes

Stumble Upon Toolbar
2:00 AM

0 Responses to "Recover SQL Server Database Suspect Mode"

Post a Comment