Table of Contents
    SQL Database Repair

    How to Fix Recovery Pending State in SQL Server Database?


    Table of Contents

      Summary: You may see the Recovery Pending state in MS SQL Server if there is a problem with the SQL database or due to any other reason. This post will outline the reasons behind the Recovery Pending state of SQL database and mention the methods to fix the problem. It will also mention an advanced SQL repair software that can come in handy if the issue is due to corruption in the database file.

      MS SQL database goes into the Recovery Pending state when something prevents the MS SQL Server from starting the database recovery. This might happen due to resource-related issues, missing files, or problem with the database. When the server marks the database in Recovery Pending state, the database is not available for users. In this post, we’ll discuss the possible causes for the Recovery Pending state of MS SQL Server database and the solutions to fix the issue.

      Reasons behind Recovery Pending State in SQL Server

      SQL Server database may go into the Recovery Pending mode due to one or more of the below reasons:

      • The database didn’t shutdown properly.
      • Missing or corrupted transaction log files.
      • Disk/drive, where the database is saved, is out of storage.
      • Database file is corrupted or damaged.
      • System is terminated or crashed abnormally.
      • Bugs in MS SQL Server.

      Methods to Fix Recovery Pending in SQL Server Database Issue

      First, you can check the SQL Server error log. This will help you detect any issues that might be responsible for the Recovery Pending state of the database. To check the error logs, open the SSMS, expand the SQL Server Agent, and click Error Logs. If you didn’t find any issues, then follow the below troubleshooting methods to bring the SQL database to normal mode.

      1. Turn OFF the AUTO CLOSE Option

      Sometimes, the database goes into the Recovery Pending state if the AUTO CLOSE option is ON for the database. When this option is turned ON, SQL Server closes the database after the use and turn it ON next time when a user accesses the database. So, if the database is frequently opened and closed after each connection, it is recommended to turn OFF the AUTO CLOSE option. To do so,

      • Open SQL Server Management Studio (SSMS) and connect to the SQL Server Instance.
      • Right-click on the database and select Properties.
      • On the Database Properties window, click on Options in the left pane.
      • Then, set the value as FALSE for AUTO CLOSE and click OK to save the changes.

      2. Recreate the Log Files

      SQL database can go into Recovery Pending state if the transaction log files are missing or corrupt.  You can recreate the log files by detaching and re-attaching the main database. When you detach the database (take the database offline) and then bring it online (re-attach), it rebuild the log files automatically. Here’s how to detach the SQL database:  

      Note: You can’t detach the database which is published, replicated, suspect, or in a mirroring session.

      • Open SQL Server Management Studio (SSMS) and click the New Query option.
      • Set the database in EMERGENCY mode by using the below command:
      ALTER DATABASE [DBName] SET EMERGENCY;
      • Next, change the database to multi_user mode by using the below command:
      ALTER DATABASE [DBName] set multi_user
      • Now, run the below command to detach the database:
      EXEC sp_detach_db ‘[DBName]’

      Once the database is detached, run the below command to reattach the SQL database:

      EXEC sp_attach_single_file_db @DBName = ‘[DBName]’, @physname = N'[mdf path]’

      3. Repair the Database

      SQL Server may fail to start the database recovery if there is corruption in database (MDF/NDF) files. You can repair the database by using the DBCC CHECKDB command. Here’s how to use this command.

      First, check the database for any inconsistencies or errors by running the below command with NO_INFOMSGS:

      DBCC CHECKDB(database15) with NO_INFOMSGS;

      The above command will display the consistency errors (if any) in the database without information messages and also recommends the repair options.

      If the DBCC CHECKDB command shows any issues in the database, then you need to repair the database. For this,

      Note: Before initiating the repair procedure, make sure to take a backup of the database.

      • Set the database in EMERGENCY mode by using the below command:
      ALTER DATABASE [DBName] SET EMERGENCY;
      GO
      • Then, execute the below command to set the database to SINGLE USER mode.
      ALTER DATABASE [DBName] set single_user
      GO
      • Now, run the DBCC CHECKDB command with the ‘REPAIR_ALLOW_DATA_LOSS’ option (as given below) to repair the database.
      DBCC CHECKDB ([DBName], REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS;
      GO
      • When the repair process is finished, change the database to multi-user mode again by running the below command:
      ALTER DATABASE [DBName] set multi_user
      GO

      An Alternative Solution to Repair SQL Database

      Running the DBCC CHECKDB command with REPAIR_ALLOW_DATA_LOSS can result in loss of data. To prevent data loss and to quickly repair the corrupt database, you can use an advanced SQL database repair software, like Stellar Repair for MS SQL. It is a specialized software that can repair corrupt database and help bring the database back online from the Recovery Pending state. It can recover all the data from corrupted NDF/MDF files with complete integrity and precision.

      Key Features of Stellar Repair for MS SQL

      • Repairs corrupt and inaccessible MS SQL database (.mdf and .ndf) files.
      • Recover all the database components, like tables, keys, indexes, triggers, rules, stored procedures, etc.
      • Recover deleted records.
      • Supports MS SQL 2019, 2017, 2016, 2014, 2012, 2008, 2008 R2, and lower versions.
      Free Download for Windows

      Steps to Use Stellar Repair for MS SQL Software

      • Download, install, and run Stellar Repair for MS SQL software.
      • From the Select Database window, click Browse or Search to select the database file you want to repair. 
      select database file
      • You will see two options – Standard Scan and Advanced Scan to scan the corrupt database. Select the Standard Scan mode. If the database file is highly corrupted, then click on Advanced Scan. Click OK.
      Scan Corrupt MDF File by Standard Scan Mode
      • Click Repair to start the repair process.
      • Once the repair process is complete, the software will show all the recoverable items in the database.
      Preview of the repaired MS SQL database objects
      • To save the repaired file and its components, click Save on the File menu. 
      Saving option to save repaired SQL database
      • On the Save Database window, do the following:
      • Choose MDF under Save As.
      • Select New Database or Live Database under Saving Option.
      • Enter the required details in the Connect To section.
      Authentication options for connectivity
      • Click Browse to choose the destination for saving the repaired file.
      File Saving Options
      • Click Save.
      • When the ‘Save Complete’ message box appears, click OK.
      Save Complete Window

      The repaired file will be saved at the selected location.

      Conclusion

      SQL database can go into Recovery Pending state due to several reasons. In this post, we’ve explained how to fix the Recovery Pending state and bring the database back online. If the Recovery Pending mode of the database is due to corruption, then you can use Stellar Repair for MS SQL software to repair the database. It can repair the database (MDF/NDF) file and restore all the objects with complete integrity. It can also help you fix several corruption-related errors in SQL database.

      Recovery Pending, Suspect, and Offline are three different states of SQL database in which the users are not able to access the database. However, the major difference lies in the cause of issue that leads to such state. Here’s how these SQL database states are different from each other:

      • In a Recovery Pending state, the server fails to initiate the recovery due to any resource-related error.
      • In Suspect mode, the recovery process has started but failed to complete due to corruption in the primary file group or transaction log files.
      • In the Offline mode, the SQL database is simply unavailable or inaccessible for user connections due to explicit user action. It requires user action to bring the database back online.

      Here are some checks that you should perform when your database is in Recovery Pending state:

      • Check the SQL Server error log to determine why the database is in Recovery Pending state.
      • Verify whether the database files or backup files are readable and accessible at their specified locations.
      • Check permissions on the database files.
      In SQL Server, the AUTO_CLOSE option is a database-level setting that automatically closes down the database and frees its resources when the last user is disconnected. If the value of the AUTO_CLOSE option is true/ON, it can lead to Recovery Pending state. So, it is recommended to set it to OFF/False.

      You can check the state of SQL database that is in Recovery Pending state by using the following T-SQL command:

      SELECT name, state_desc

      FROM sys.databases;

      No, data is not lost just because the database is in Recovery Pending state. This state means SQL Server can't start recovery due to any issue. The data in the database is still there. To access the data, you need to recover the database from the Recovery Pending state to online.

      You can prevent the Recovery Pending state in future by following the below practices:

      • Regularly backup the database.
      • Check the integrity of the backup before restoring the database.
      • If accessing the database in an Always On Availability group, do not forget to perform regular health checks.
      • Check disk space and file system health.
      • Regularly check the SQL Server error logs for any error warnings.
      • Ensure you have an UPS to avoid sudden power failure.
      To fix a Recovery Pending state in an Always On Availability group, first remove the affected replica if it's the only one in the availability group. Reassign the listener to maintain connectivity. If the database marked as Recovery Pending, then check resource issues and corruption. If there is corruption in database file, use Stellar Repair for MS SQL to repair the database. After recovery, re-add the database to the availability group and check synchronization across replicas.
      The database usually goes into Recovery Pending state due to corruption. There are many professional SQL database repair tools available, like Stellar Repair for MS SQL that can help recover the database if it goes into Recovery Pending state due to corruption.

      Was this article helpful?

      No NO

      About The Author

      Monika Dadool linkdin

      Monika Dadool is a Senior Content Writer at Stellar with over 5 years of experience in technical writing. She is a tech enthusiast and expert who specializes in writing about SQL Server, MySQL Server, MariaDB Server, Microsoft Access, Active Directory, email recovery, Microsoft 365, pattern recognition, machine learning, data recovery, file repair, and operating systems like Linux, Windows, and Mac. She also writes about accounting software such as QuickBooks and Sage 50, as well as web-scripting languages like HTML, JavaScript, Python, PHP, Visual Basic, ASP.NET, and AJAX. Monika is passionate about researching and exploring new technologies, and she enjoys developing engaging technical blogs that help organizations and database administrators resolve various issues. When she's not creating content, you can find her on social media, watching web series, reading books, or exploring new food recipes.

      29 comments

      1. I have decided to give up manual procedures. Now, I will move on a third party solution to check the feasibility of SQL database recovery in minimal time using a free demo.

      2. Our team was struggling since the last Friday. But, yesterday I got the reference of this guide from a SQL MVP. Really, you guys helped us to get relief from a panic SQL server error.

      3. Hi,

        I keep getting this error “Invalid database version. Select appropriate database version”, I tried every choice in the wizard with no luck.

        I user SQL 2012, I am not sure if it is converted from another version or not, however, I don’t think this is the problem.

        In SQL management studio I got “Recovery Pending”, I tried to “emergency” the database, but it returns I/O error.

        Thanks in advance

        1. If you have tried all manual troubleshooting tips but the problem still exists, then try free demo of Stellar Repair for MS SQL.

      4. Hi,

        I got this error after running Windows updates and rebooting the server. What I did wrong in order to have this error?

        Should I end something before rebooting the server?

        Thanks.

      Leave a comment

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

      Image Captcha
      Refresh Image Captcha

      Enter Captcha Here :

      Google Trust
      Related Posts

      WHY STELLAR® IS GLOBAL LEADER

      Why Choose Stellar?

      • 0M+

        Customers

      • 0+

        Years of Excellence

      • 0+

        R&D Engineers

      • 0+

        Countries

      • 0+

        PARTNERS

      • 0+

        Awards Received

      BitRaser With 30 Years of Excellence
      Technology You Can Trust
      Data Care Experts since 1993
      ×