Skip to Content

Blog Archives

How to fix a suspect database

One of the relatively common situations during disaster recovery is a suspect database. The suspect flag is a mode which is set to the database by SQL Server in several cases. When it comes to disaster recovery, mainly databases are marked as suspect in case of a hardware failure, improper shutdown of the DB server, DB files corruption, etc. Strangely enough, it can happen when you restore the entire DB server from a valid snapshot (it happened to me).

In such cases, you will need to bring the database back to online mode. At this point you need to be aware that during the process there may be some data loss. This can occur if there are incomplete transactions which will need to be rolled back. In general,

What you will need for the procedure is the SQL Server Management Studio. I will use the Prime database which I corrupted in the previous post 🙂

The first thing you need to do is to turn off the suspect flag (which does not mean that the DB is fixed). You will need to execute the following command:

EXEC sp_resetstatus ‘Prime’

You will get the following message:

1

The next step is to set the database into emergency mode, which will make it a read-only with the following command:

ALTER DATABASE Prime SET EMERGENCY

2

Then, perform a consistency check. The output will display any possible errors.

DBCC checkdb(‘Prime‘)

3

In the next step we do a rollback of any pending transactions. This step also brings the DB in a single user mode.

ALTER DATABASE Prime SET SINGLE_USER WITH ROLLBACK IMMEDIATE

4

Finally, we will correct any reported errors. Keep track of the time, since this may be a lengthy process.

DBCC CheckDB (‘Prime‘, REPAIR_ALLOW_DATA_LOSS)

5

To wrap up the procedure, we will need to enable the multi user access and bring it online.

ALTER DATABASE Prime SET MULTI_USER

6

If we check the DB status now, it will be shown as online. We can browse through the tables and query data:

select DATABASEPROPERTYEX(‘Prime‘, ‘status’)

7

 

Jana Georgievska,

DBA

0 1 Continue Reading →

Radix Technologies Video

A short video depicting our capabilities. Enjoy and share! 🙂

0 1 Continue Reading →