Cannot Recover the Master Database (Error 3417) and What the Log Actually Says

🚨Part of the SQL Server Errors series, the exact messages and what actually causes them.

Msg 3417  ·  Level 21  ·  logged
Cannot recover the master database. SQL Server is unable to run. Restore master from a full backup, repair it, or rebuild it.
3417 is the summary, not the diagnosis. The error you can act on is above it in the log. The instance is down, so start with the error log on disk, and read upwards from the last line rather than searching for 3417.

When SQL Server will not start, the temptation is to search the one number you were given. That number is usually the least useful line in the file. To find out what master damage actually produces, I broke it four different ways in a throwaway container and read the log each time. 3417 did not appear in any of them. Something more specific always did, and that was always the line worth acting on.

This is the same shape as error 3013 on a failed restore: a closing message that tells you the operation failed, sitting underneath the message that says why.

How this was tested A disposable SQL Server 2022 CU26 (16.0.4265.3) container, damaged deliberately, started, and its log read. Four kinds of damage, four different results, all reproduced rather than recalled. Nothing here was run against a real instance, and neither should your practice run be.

What Master Damage Actually Produces

What was damagedWhat the log saidWhat it points at
Files left owned by the wrong account17204 then 5120, OS error 5, access deniedPermissions, not corruption. The most common real cause, and the easiest to fix.
master.mdf header destroyed5172, then 5173 twiceThe file is not a database file any more. Restore or rebuild.
mastlog.ldf overwritten824, severity 24, torn pageThe log cannot be read. Recovery never starts.
master.mdf interior pages, header intactrecovery runs, then 824, incorrect checksumThe file opens and recovery gets partway. Genuine page corruption.

Four failures, four different first lines, and in every case the instance exited rather than continuing. The practical consequence: the fix is decided by the specific error, and three of these four are not the same problem at all.

Case 1Wrong file ownership, which is not corruption at all

This one happened by accident during testing, which is exactly how it happens in production: the files were copied back into place by an account that left the ownership wrong. The instance behaves as though the database is broken.

Error: 17204, Severity: 16, State: 1.
FCB::Open failed: Could not open file /var/opt/mssql/data/master.mdf for file number 1.
OS error: 5(Access is denied.).
Error: 5120, Severity: 16, State: 101.
Unable to open the physical file "/var/opt/mssql/data/master.mdf".
Operating system error 5: "5(Access is denied.)".

Nothing is corrupt. Check ownership and permissions on the data directory before you reach for a backup. After a file move, a restore from a copy, a drive remap or a service account change, this is the first thing to rule out and it costs a minute.

Case 2The master.mdf header destroyed

The first pages of the file zeroed, so the header no longer identifies it as a database.

Starting up database 'master'.
Error: 5172, Severity: 16, State: 15.
The header for file '/var/opt/mssql/data/master.mdf' is not a valid database file header.
The PageAudit property is incorrect.
Error: 5173, Severity: 16, State: 1.
One or more files do not match the primary file of the database.

5172 is the one to search, not 3417. The 5173 that follows is a consequence: the log file no longer matches a primary file that is no longer readable. This is a restore or rebuild, and no amount of restarting will change it.

Case 3The master log overwritten

Master’s own transaction log filled with random data, leaving the data file untouched.

Starting up database 'master'.
Error: 824, Severity: 24, State: 2.
SQL Server detected a logical consistency-based I/O error: torn page
(expected signature: 0xaaaaaaaa; actual signature: 0x8834a602). It occurred during a
read of page (2:0) in database ID 1 at offset 0000000000000000
in file '/var/opt/mssql/data/mastlog.ldf'.

A textbook error 824, on master’s own log, with real signatures. Recovery never begins because the log cannot be read. Note that database ID 1 in an 824 means master, and that is worth recognising instantly.

Case 4Pages inside master, header left valid

The most interesting one, because the file opens and recovery genuinely runs before it fails.

Starting up database 'master'.
16 transactions rolled forward in database 'master' (1:0).
Error: 824, Severity: 24, State: 2.
SQL Server detected a logical consistency-based I/O error: incorrect checksum
(expected: 0x524b60b1; actual: 0x8af60429). It occurred during a read of page (1:56)
in database ID 1 at offset 0x00000000070000
in file '/var/opt/mssql/data/master.mdf'.

Read that middle line. Sixteen transactions rolled forward before the failure, so recovery was working. A partial start is not a good sign here, it just means the damage was further in. The checksum values are the giveaway that this is real page corruption rather than a configuration problem.


Finding the Log When the Instance Is Down

You cannot query anything, so the error log has to be read from disk. It is plain text and the newest one is always ERRORLOG with no extension.

# Windows, default path. Adjust the instance folder for a named instance.
Get-Content "C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\Log\ERRORLOG" -Tail 60

# The lines that matter, rather than the whole file
Select-String -Path "C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\Log\ERRORLOG" `
              -Pattern "Error:|Cannot recover|FCB::Open|not a valid database file header"
# Linux
sudo tail -n 60 /var/opt/mssql/log/errorlog

# In a container the log goes to the container's output as well
docker logs <container> | tail -n 40

Read from the bottom upwards. The instance stops at the first thing it cannot survive, so the last error in the file is the one that killed it, and anything after it is shutdown noise.


Getting It Back

In order of how much you lose, least first. Work down this list, do not start at the bottom.

  1. Rule out permissions. Case 1 above. Free, instant, and it is the answer more often than corruption is.
  2. Put back a known-good copy of the files, if you have one from a snapshot or a file-level backup taken while the instance was stopped. Confirmed working in testing: replacing master.mdf and mastlog.ldf with intact copies brought the instance straight back up with no other action.
  3. Restore master from a database backup. This needs the instance started in single-user mode, because you cannot restore master while it is serving normally. This is the path Microsoft’s own message points at, and it is only available if someone was backing master up.
  4. Rebuild the system databases, then restore master. The last resort. It gives you a working instance with none of your logins, jobs, linked servers or configuration, which you then restore. The rebuild command differs by platform and version, so take it from the documentation for the exact build you are on rather than from memory.

The uncomfortable part of that list is that steps 3 and 4 both depend on having a master backup. Master is small, changes rarely, and is the one database whose loss costs you every login and every job on the instance. If it is not in your backup schedule, that is the thing to fix today rather than the thing to discover during an outage.


What Not To Do

  • Do not restart repeatedly hoping it catches. Every one of the four cases failed identically on every attempt. Restarting only costs you the time you need for the log.
  • Do not delete or move the damaged files before you have read the log. The file names and paths in the error are half the diagnosis, and a damaged master may still be restorable.
  • Do not rebuild the system databases as a first move. It works, and it throws away every login, job, linked server and server-level setting. It is step 4 for a reason.
  • Do not assume corruption because the instance is down. Ownership and permissions produce the same headline symptom and none of the damage.
  • Do not practise this on a real instance. Everything on this page was reproduced in a disposable container, which took minutes and cost nothing.

Common Questions

I searched 3417 and found nothing useful. Why?
Because 3417 tells you the outcome, not the cause. Across four different kinds of deliberate master damage it did not appear at all, and a more specific error did every time: 5172 for a destroyed header, 824 for page or log corruption, 5120 for a permissions problem. Search the error above it in the log.
Does an 824 on database ID 1 mean the whole instance is lost?
It means master is damaged, which stops the instance from starting, but it does not mean your user databases are affected. They are separate files and are usually intact. Recovering master gets the instance back and the user databases come with it.
The instance will not start after we moved the data files. Is it corruption?
Almost certainly not. Look for FCB::Open failed and operating system error 5 in the log, which is a permissions problem on the file or the folder. Reproduced here by accident, because copying files back into place as the wrong user is exactly how it happens for real.
Can I just copy master.mdf from another server?
No. Master holds the instance’s own identity, logins, and configuration, and is tied to the build. A master from a different server or a different patch level will not start, and may leave you worse off than the damaged one you still had.
How do I practise this safely?
A container. Everything on this page was reproduced in a throwaway SQL Server 2022 container: damage the file, start it, read the log, put a good copy back, watch it come up. That last step is the one worth rehearsing, because it is the one you will be doing under pressure.
Should I be backing up master?
Yes, and it is cheap. Master is a few megabytes and changes only when logins, jobs or server settings change. Without a backup, your recovery options reduce to file-level copies or a rebuild that discards every login and job on the instance.

Related Scripts

Comments

Leave a Reply

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