Bobcares

How to recover the database from suspect mode in SQL Server?

by | Nov 4, 2020

Users often are unable to connect to the SQL databases as the database is in suspect mode. To recover the database from suspect mode in sql, we may need to perform consistency checks and rollback of transactions.

As a part of our Server Management Services, we help our Customers to fix SQL related errors regularly.

Let us today discuss the possible causes and fixes for this error.

What causes database to enter suspect mode in SQL?

A database in suspect state indicates that the database recovery process has initiated but not finished successfully. This indicates the users to fix that issue and repair the corrupted files.

While a database is in suspect mode, users won’t be able to connect the databases to read and write data.

There are many reasons that can cause a database to go in suspect mode. Some of them include:

  • SQL Server Crash
  • Database Files are inaccessible
  • SQL Server Database Operation Failures
  • Due to Sudden Power Outage
  • Improper shutdown of the database or database server.
  • Hardware Failure.
  • Corruption in database files.
  • There is not enough space available for the SQL Server to recover the database during startup.
  • Inaccessible database files or Insufficient memory.
  • Database files drive letters mistyped/changed during any maintenance work.

How to recover the database from suspect mode in SQL?

First step in recovering or repairing the suspect database is to analyze the database server.

Sometimes, files can go missing/changed to another location due to human error or maintenance work.

Thus, we need to check the files and make sure that all database files are in same location where they should be.

Once we have checked the drive and there is no change in it, then we can try to run below SQL statement to bring the database online.

Alter database DBNAME SET ONLINE.

Where, DBNAME is the name of the database name that is showing in suspect mode.

If it does’nt work, then we will run below t-sql code to get all errors due to which database went in suspect mode:

DBCC CHECKDB ([DBNAME]) WITH NO_INFOMSGS, ALL_ERRORMSGS

Once we have enough information about errors, then our next step would be Repair.

If error is showing data files missing, then check the data file drive connectivity from storage side. If it is missing, then check data file drive is healthy or not.

 

Steps to Fix the SQL Server Database Suspect Mode Error

  1. Bring Database Online in EMERGENCY MODE
  2. Perform Consistency Check Using DBCC Command DBCC CHECKDB
  3. Bring the Database in SINGLE_USER Mode to ROLLBACK TRANSACTION
  4. Take a Full Backup of the User Database which was marked Suspect Before
  5. Execute DBCC CHECKDB WITH REPAIR ALLOW DATA LOSS (Caution: It will result in Data Loss)
  6. Once the above command has executed successful. Bring the Database in MULTI_USER Mode for normal read and write operations.
Bring Database Online in EMERGENCY MODE

When a database is in SUSPECT mode we will not be able to get connected to the database. Hence we need to bring the database first in EMERGENCY mode to repair the database. Execute the below mentioned TSQL code to bring the database in EMERGENCY mode.

USE master
GO

ALTER DATABASE DBNAME SET EMERGENCY
GO
Perform Consistency Check Using DBCC Command DBCC CHECKDB

Once the database is in EMERGENCY mode we will be able to query the database.

Execute the DBCC CHECKDB command which will check the logical and physical integrity of all the objects within the specified database.

DBCC CHECKDB (BPO)
GO
Bring the Database in SINGLE_USER Mode to ROLLBACK TRANSACTION

Next step will be to bring the user database in SINGLE_USER mode by executing the below mentioned TSQL code.

ALTER DATABASE BPO SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO

Now take a Full Backup of the User Database which was marked Suspect Before.

Execute DBCC CHECKDB WITH REPAIR ALLOW DATA LOSS

Once the database is in SINGLE_USER mode execute the below TSQL code to repair the database.

DBCC CHECKDB (BPO, REPAIR_ALLOW_DATA_LOSS)
GO

A point to be noted here is that, when we repair the database using REPAIR_ALLOW_DATA_LOSS option of DBCC CHECKDB command there can be some loss of data.

Bring the Database in MULTI_USER Mode

Finally, execute the below mentioned TSQL command to allow MULTI_USER access to the database.

ALTER DATABASE BPO SET MULTI_USER
GO

This will make the database available for normal read and write operations.

[Need any further assistance to recover the database from suspect mode in sql ? – We’re available 24*7]

 

Conclusion

In short, to recover a database from suspect mode in SQL we will need to perform a consistency check on database in emergency mode. Further we will need to run a repair with ALLOW DATA LOSS in single user mode. Today, we saw how our Support Engineers perform these tasks.

 

 

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

2 Comments

  1. Ammar Barya

    hi . i am facing this issue at my DR site . PR is showing the DB is in Synchronized but DR is showing initializing/suspect . please guide me how to do it?

    Reply
    • Hiba Razak

      Hi,
      Our Experts can help you with the issue, we’ll be happy to talk to you on chat

      Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF