SQL SERVER – Database going to Recovery Pending Automatically and Coming Back

I love connecting community via various channels. One of my clients explained an interesting issue to me. He explained that he has a production database which is going to Recovery Pending state by itself and without any user intervention, it’s coming back as well.

SQL SERVER - Database going to Recovery Pending Automatically and Coming Back rec-pending-01

As you might have seen my earlier post, I always start by asking SQL Server ERRORLOG file to see if there are some interesting messages.

SQL SERVER – Where is ERRORLOG? Various Ways to Find ERRORLOG Location

Solarwinds

Here is what I saw in ERROLOG which made complete sense about the behavior.

2016-07-16 17:06:00.38 spid58 Starting up database ‘ProdDB’.
2016-07-16 17:06:01.40 spid58 Error: 17204, Severity: 16, State: 1.
2016-07-16 17:06:01.40 spid58 FCB::Open failed: Could not open file G:\MSSQL11.MSSQLSERVER\MSSQL\DATA\ProdDB_log.ldf for file number 2. OS error: 32(The process cannot access the file because it is being used by another process.).
2016-07-16 17:06:01.42 spid58 Error: 5105, Severity: 16, State: 1.
2016-07-16 17:06:01.42 spid58 A file activation error occurred. The physical file name ‘G:\MSSQL11.MSSQLSERVER\MSSQL\DATA\ProdDB_log.ldf’ may be incorrect. Diagnose and correct additional errors, and retry the operation.
2016-07-16 17:06:01.45 spid58 Error: 5170, Severity: 16, State: 1.
2016-07-16 17:06:01.45 spid58 Cannot create file ‘G:\MSSQL11.MSSQLSERVER\MSSQL\DATA\ProdDB_log.ldf’ because it already exists. Change the file path or the file name, and retry the operation.
2016-07-16 17:06:01.45 spid58 Error: 5170, Severity: 16, State: 1.
2016-07-16 17:06:01.45 spid58 Cannot create file ‘G:\MSSQL11.MSSQLSERVER\MSSQL\DATA\ProdDB_log.ldf’ because it already exists. Change the file path or the file name, and retry the operation.

Since the database was getting started (another issue) it was trying to get the file handle and open the files. Due to “OS error: 32(The process cannot access the file because it is being used by another process.).” SQL was unable to open files and hence going to Recovery Pending state.

Now, the questions are

  1. Why database is getting started automatically?
  2. Which is the “another” process which is having open handle on the files.

For the first issue, you can read my earlier blog!

SQL SERVER – Starting Up Database – Why Multiple Times in Errorlog?

While investigating I found that they had Antivirus running on the server, which was doing “On-Access” scan which was causing SQL to not get handle and cause OS error 32. If you have not seen earlier, here is the Microsoft knowledge base article on the same topic.

How to choose antivirus software to run on computers that are running SQL Server

Once we fixed Auto_Close setting and added file exception for MDF, LDF files, the issue never occurred.

Have you ever encountered such behavior?

Reference: Pinal Dave (https://blog.sqlauthority.com)

Solarwinds
, ,
Previous Post
Interview Question of the Week #056 – How to fix Installation Failure – Rule “Setup account privileges” Failed in SQL Server

Related Posts

6 Comments. Leave new

  • Great Article Pinal, we encountered similar issue long time back and we applied the same fix at that Point of Time.

    Reply
  • Database going into ‘Recovery pending’ state could be due to lack of permissions for the SQL Server Service account on the database folder(s). This can happen when the database is created on a different folder other than SQL Server data folder

    Reply
    • Thanks for sharing this @Babu. In case of permission the database would never come online.

      Reply
      • Hi Pinal,
        This happened on my local db (not production) because I had the database files on an external drive.
        The Mapping letter for the external drive changed in due course and SQL could not find the database files.

  • Hi Pinal, What antivirus did he use?

    Reply

Leave a Reply

Menu