How to remove recovery pending in SQL server
Being a SQL server user everybody must have faced Recovery Pending state at least once as this issue occurs at a regular interval. But many of us are unaware of the reason that leads to this error. Here we will discuss how to remove recovery pending in SQL server and the reasons responsible for this error. Sometimes when the data partition gets full then this error occurs in the SQL server. And SQL is not able to view the database and cannot lock the database file that is the same as the database in offline mode. It also prevents the server from initializing. Before we discuss solutions to the Recovery Pending State in SQL Server Lets understand the states of the SQL Server Database.
SQL Server Database States
A SQL database is said to be damaged or corrupted if one or more of its core files are in an unstable state. According to how critical the damage is, the DB is kept in different states. Here are states of SQL Server Database: Online – At this online state one of the data files is corrupted while running a query or some other operation, the database remains online and accessible.
Suspect – If the database is not able to recover while starting the SQL Server, then the database is termed as Suspect.
Recovery Pending – If the SQL Server is well known that database recovery requires to be run but is prevented from starting due to some issues, then the Server called the DB in the ‘Recovery Pending’ state. But this is distinct from the suspect mode because the recovery does not fail here, it is not started. After understanding the knowledge Let’s see how to remove recovery pending in SQL server by checking the database states.
How to Check the Database State?
To find the current state of an SQL DB, execute the below query:
SELECT name, state_desc from sys.databases
GO
This way you can easily find the database state and will be able to fix the issue of how to remove recovery pending in SQL. But before that let’s discuss the reasons responsible for such errors.
Causes of Recovery Pending State in SQL Server Issue
Some of the common reasons due to which such issue is faced and we need to perform SQL recovery process are listed below:
- Improper shutdown of Database with uncommitted transaction active results in the deletion of the active transaction log file.
- The user moves the log files to a new drive to defeat the server performance issues but ends up corrupted the log files in the procedure.
- Database Recovery is not able to initiate due to inadequate memory space or disk storage.
Manual methods to solve the Database in Pending State
Here are the two manual methods to recover SQL database in recovery mode to normal mode:
Mark or Assign Database in Emergency Mode and start Forceful Repair
Database EMERGENCY mode assigns the database as READ_ONLY disables sign in and allows access only to the administrator system. So, by setting the DB in this mode can take out the inaccessible database online.
After you view the DB in EMERGENCY mode, try to repair the database with the DBCC CHECKDB command using the ‘REPAIR_ALLOW_DATA_LOSS’ option. To do so, View SSMS and run the following set of queries:
- ALTER DATABASE [DBName] SET EMERGENCY;
- GO
- ALTER DATABASE [DBName] set single_user
- GO
- DBCC CHECKDB ([DBName], REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS;
- GO
- ALTER DATABASE [DBName] set multi_user
- GO
Mark or Assign Database in Emergency Mode, Disconnect the Main Database and Reconnect It
This solution also requires to assign DB in EMERGENCY mode. Once it gets assigned offline the database and then gets online (re-attach). To do so, run the following set of queries in SSMS:
- ALTER DATABASE [DBName] SET EMERGENCY;
- ALTER DATABASE [DBName] set multi_user
- EXEC sp_detach_db ‘[DBName]’
- EXEC sp_attach_single_file_db @DBName = ‘[DBName]’, @physname = N'[mdf path]’
This set of queries will help you to overcome the damage or corrupt log and a new one will be created automatically. The above-discussed methods are the manual method and a complete technical process so if you belong to a non-technical background then don’t use this solution. In some cases, users have to face critical data loss. But don’t panic you can use a third-party tool such as SQL Recovery tool to resolve the query recovery Pending State in SQL database Server. This is an exclusive software based on the Windows platform that executes the constant recovery of the Damaged SQL database.
Conclusions
Here, in this write-up, we discussed how to remove recovery pending in SQL server. Hope after reading this blog you will be able to resolve your issue.
Put the database in emergency mode and force a repair.
In the database EMERGENCY mode, the database is marked as READ ONLY, logging is disabled, and only system administrators have access. Simply, putting the database in this mode allows you to access an inaccessible database.
After you've accessed the database in EMERGENCY mode, use the DBCC CHECKDB command with the 'REPAIR ALLOW DATA LOSS' option to fix it. To do so, launch SQL Server Management Studio and run the following queries:
ALTER DATABASE [DBName] SET EMERGENCY;
GO
ALTER DATABASE [DBName] set single_user
GO
DBCC CHECKDB ([DBName], REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS;
GO
ALTER DATABASE [DBName] set multi_user
GO
Put the database in emergency mode, then detach and reattach the main database.
This technique also implies the setting of db to EMERGENCY mode. After that, take the database offline (detach) before bringing it back online (re-attach). To accomplish so, use SSMS to run the following queries:
ALTER DATABASE [DBName] SET EMERGENCY;
ALTER DATABASE [DBName] set multi_user
EXEC sp_detach_db ‘[DBName]’
EXEC sp_attach_single_file_db @DBName = ‘[DBName]’, @physname = N'[mdf path]’
The easiest way to remove recovery pending in SQL server is to use SQL Tools.