Database in Recovery Pending: Cannot Be Opened (SQL Server Error 945)

🚨Part of the SQL Server Errors series, the exact messages and what actually causes them.Related pillar: Storage & Capacity

Msg 945  ·  Level 14  ·  State 2
Database 'SalesArchive' cannot be opened due to inaccessible files or insufficient memory or disk space. See the SQL Server errorlog for details.
⚡Check state_desc in sys.databases, then find the error log line that names the file. 945 almost always means the database is RECOVERY_PENDING because SQL Server cannot open one of its files. Fix the path or the access, run ALTER DATABASE ... SET ONLINE, and it comes back untouched. If the file is really gone, restore before you repair.

945 is a symptom, not the disease. Something stopped SQL Server opening one of the database’s files at startup, the database parked itself, and every connection that tries to use it gets this message instead. The three causes it names sit in strict order of likelihood: inaccessible files first by a distance, then disk space, then memory.

SSMS query window running USE SalesArchive; the Messages tab shows Msg 945, Level 14, State 2: Database SalesArchive cannot be opened due to inaccessible files or insufficient memory or disk space. See the SQL Server errorlog for details.

What the Instance Actually Looks Like

Two queries tell you nearly everything. The first is the state of the database, and with 945 it will almost certainly read RECOVERY_PENDING: SQL Server knows the database exists, cannot open its files, and has not even been able to begin recovery.

SELECT name, state_desc, user_access_desc
FROM sys.databases
WHERE name = 'YourDb';

The second is where SQL Server believes the files are, which you then check against the disk by hand:

SELECT type_desc, state_desc, physical_name
FROM sys.master_files
WHERE database_id = DB_ID('YourDb');
SSMS results: sys.databases shows zz_recpend RECOVERY_PENDING and MULTI_USER; sys.master_files shows the ROWS and LOG files both ONLINE, the log at D:\SQLData\zz_recpend_log_old.ldf.

sys.master_files still says ONLINE for both files, even with the log pointing at a file that is not there, so it will not tell you which one is the problem.

The error log fills in whichever detail the message left out. When I broke a database for this post by pointing it at a file that does not exist, the log carried one line that names the file and the operating system error: FCB::Open failed: Could not open file ... for file number 1. OS error: 2(The system cannot find the file specified.). The 5120 unable to open the physical file and 5181 could not restart the database messages went back to the session that ran the SET ONLINE, not into the log. The 945 you see in your session is the public face of that chain. A missing log file leaves a different line, so search for both:

EXEC xp_readerrorlog 0, 1, N'FCB::Open failed'; -- a data file
EXEC xp_readerrorlog 0, 1, N'Operating system error', N'YourDb'; -- a log file

With the log file pointed at a path that does not exist, every attempt to start the database logged the same line:

xp_readerrorlog search for Operating system error and zz_recpend returns two FileMgr::StartLogFiles rows: Operating system error 2, the system cannot find the file specified.

FileMgr::StartLogFiles means a log file; a data file shows up as FCB::Open failed. Either way the number in brackets is the operating system error, and it maps to a cause in the table below. The session that ran the SET ONLINE got the short version:

SSMS Messages tab after ALTER DATABASE zz_recpend SET ONLINE: File activation failure for D:\SQLData\zz_recpend_log_old.ldf, Msg 5181 could not restart database, Msg 5069 ALTER DATABASE statement failed.

MS Docs covers MSSQLSERVER_945 and database states in full.


The Usual Suspects, In Order

CauseOS error in the logHow it happens
The file moved or was renamed2, file not foundA drive letter changed, a file was tidied into a new folder, a SAN volume came back under a different path, or a migration moved files without updating the database. SQL Server still holds the old path in sys.master_files and cannot know where the file went.
The engine lost permission5, access deniedThe file is exactly where it should be, but an ACL change, a restore from backup software, or a copy between machines stripped the SQL Server service account’s rights to it. You can see the file in Explorer; the service cannot open it. Error 5120 covers the permissions in detail.
The volume is not there yet3, path not foundAfter a reboot, SQL Server can start before a mount point, iSCSI target or BitLocker-protected volume is available. Databases on that volume come up RECOVERY_PENDING and 945 until it appears. Error 5123 is the same problem when SQL Server creates a file.
Another process holds the file32, file in useUsually antivirus, a file-level backup agent, or a second instance pointed at the same file. Stop that process or exclude the database folders.
Disk full or out of memory112, disk fullThe two causes the message names last, and the two you will meet least. The error log makes it obvious when either is genuinely the reason. For a full disk, Disk Is Full or the Log Will Not Truncate is the next page.

Only OS error 2 was reproduced as a RECOVERY_PENDING startup for this post; error 5 was captured on the attach shown further down. The other numbers are documented, not reproduced here. No operating system error at all, but a database that got as far as recovery and stopped, is a different state: In Recovery if it is still working through the log, SUSPECT (Error 926) if recovery ran and failed.


The Fix, Measured

Once the file problem is solved, the database does not need restoring, rebuilding or detaching. It needs to be told to start again. In the reproduction for this post the repair was two statements: point the catalog back at the right file, then bring the database online.

-- Only needed if the path in sys.master_files is wrong:
ALTER DATABASE YourDb
MODIFY FILE (NAME = YourDb, FILENAME = 'D:\SQLData\YourDb.mdf');

ALTER DATABASE YourDb SET ONLINE;

If the path was right and the problem was access or an absent volume, fix that side instead: restore the service account’s rights on the folder, or bring the volume back, and then run the SET ONLINE. The database went from RECOVERY_PENDING to ONLINE the moment the file could be opened, with no recovery drama, because nothing about the data ever went wrong.

The missing log file case is the same fix. Pointing the log back at its real path and running the SET ONLINE was the whole repair:

MODIFY FILE points zz_recpend_log back at D:\SQLData\zz_recpend_log.ldf and SET ONLINE succeeds; sys.databases shows ONLINE and FULL, and dbo.orders still holds 1000 rows.

All 1,000 rows were there, the recovery model was still FULL, and the backup chain was untouched.


When the Log File Is Really Gone

If the drive died and the .ldf is not coming back, the order is restore, then rebuild, then repair.

  • Restore from backup. The last full plus the log backups gets you a transactionally consistent database. Without the log file you cannot take a tail-log backup, so anything after the last log backup is lost either way; restore is still the clean option. Get Backup Coverage tells you what you have.
  • Rebuild the log on attach, only after a clean shutdown. CREATE DATABASE ... FOR ATTACH_REBUILD_LOG builds a new log when the database was shut down cleanly. Documented, not reproduced here: the attempt on the lab failed for a reason worth knowing, shown below.
  • Repair as the last resort. EMERGENCY mode plus REPAIR_ALLOW_DATA_LOSS, with its cost in the next section.

To try the attach route, the database was taken offline and dropped first (dropping an offline database leaves its files on disk). The attach then failed with access denied. SQL Server sets file permissions when a database is detached or attached, and dropping the offline database reset them here too:

CREATE DATABASE zz_recpend FOR ATTACH_REBUILD_LOG fails: Msg 5120 unable to open D:\SQLData\zz_recpend.mdf, operating system error 5 access is denied, then Msg 1802 CREATE DATABASE failed.

The service account could no longer open the .mdf. Getting it back needs a local administrator to reset the ACL. That is the strongest argument against the vendor advice to “detach and re-attach to rebuild the log”: you remove the database from the instance and can lose the ability to put it back. MS Docs covers this under Database detach and attach.


Repair Is the Last Resort, and This Is What It Costs

Before any of this, copy the .mdf and any surviving .ndf files somewhere safe, so a failed repair can be retried or handed to someone else. Then, on the lab database with its log file missing:

ALTER DATABASE YourDb SET EMERGENCY;
-- read-only, sysadmin only: copy out what you need now

ALTER DATABASE YourDb SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
DBCC CHECKDB (YourDb, REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS;
ALTER DATABASE YourDb SET MULTI_USER;
SSMS results of the EMERGENCY mode repair: state EMERGENCY, 1000 orders readable in emergency, then after DBCC CHECKDB REPAIR_ALLOW_DATA_LOSS the database is ONLINE with recovery model SIMPLE.

The Messages tab carries the part that matters, the warning that the log was rebuilt:

Messages from the repair: File activation failure for zz_recpend_log_lost.ldf, then the warning that the log has been rebuilt, transactional consistency has been lost and the RESTORE chain was broken.

Read what that cost, even on a database that lost no rows:

  • The backup chain is gone. No log backup taken before the repair can be applied after it. Take a full backup straight away.
  • The recovery model changed. It went in as FULL and came out as SIMPLE. Set it back, then take that full backup, or your log backup jobs will start failing.
  • Consistency is not guaranteed. The lab database was shut down cleanly before the log went, so all 1,000 rows survived. After a crash, the log held work that recovery would have redone or undone; the rebuild throws it away and can leave half-finished changes in the data. Documented, not reproduced here.
  • The application is now the check. CHECKDB proves the pages are readable, not that the business data is right. DBCC CHECKDB Found Corruption covers what to do with its output.

Note that EMERGENCY mode already let a sysadmin read all 1,000 rows. If restore is not possible, copying the data out in EMERGENCY mode into a new database is often a better outcome than repairing in place. MS Docs: DBCC CHECKDB.


What Not To Do

  • Do not run repair first. In the most common cases (a moved file, a late volume, a permission) the fix is one SET ONLINE and repair would have broken the backup chain for nothing.
  • Do not detach or drop the database to “reset” it. Detaching a database that cannot be opened throws away the catalog entry that tells you which file is missing, and a database that will not attach is a harder problem than a database that will not open. The lab attach above failed with OS error 5 after exactly that.
  • Do not restart the service as a first move. If the file is still inaccessible, you get the same state back plus an outage for every other database. Restarting only helps when the real cause was a volume that has since come back.
  • Do not reach for RESTORE yet. Restoring over a database whose files are merely mispointed converts a two-statement fix into a recovery exercise. Prove the files are actually gone or damaged first; the 823/824 family is the signal for damage, 945 on its own is not.
  • Do not delete a log file because it looks spare. Check sys.master_files for every file the database owns before touching the folder.

Frequently Asked Questions

Is RECOVERY_PENDING the same as SUSPECT?
No, and the difference decides how worried to be. RECOVERY_PENDING means recovery has not started because a file cannot be opened; fix the file and the database usually comes back untouched. SUSPECT means recovery ran and failed, which is a genuinely harder situation. 945 belongs to the first world.
The message mentions memory and disk space, but my disk is fine. Why say it?
The message text covers every reason the open can fail and cannot know which one applied. The error log can: it records the specific operating system error, and in the reproduction for this post that was error 2, file not found. Read the log before acting on any of the three causes.
Why does my error say Level 14 when the catalog says severity 16?
Both are real. The template sits in sys.messages at severity 16, and the engine raises it at Level 14 when a session hits it. Measured on SQL Server 2025 while writing this post.
Can this happen to tempdb or master?
The system databases play by harsher rules: if master cannot open, the instance does not start at all, and tempdb is recreated at startup so a bad tempdb path also stops the service. 945 as a running-instance message is a user database story. SQL Server Service Will Not Start covers that path.
Can I read the data while it is RECOVERY_PENDING?
Not in that state; connections get Msg 945. A sysadmin can set it to EMERGENCY, which is read-only, and on the lab all rows were readable that way with the log file missing.
Why did my recovery model change to SIMPLE after the repair?
In our lab on SQL Server 2025 CU8 it went in as FULL and came back SIMPLE after EMERGENCY mode and REPAIR_ALLOW_DATA_LOSS. Check recovery_model_desc in sys.databases afterwards, set it back if it changed, and take a full backup to start a new chain.

Where To Go Next

945 is the message; the neighbours are the states and the checks around it:

Comments

Leave a Reply

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