Error 9003: Log Scan Number in master Is Not Valid

Error 9003 on the master database means your SQL Server service will not start. If you searched for the log scan number message in master, this post is for you. It shows how I fixed it for a client.

Gouache painting of a wooden window frame with one cracked pane and a spare pane edged in vermilion leaning against the sill

The Error

This is what the ERRORLOG showed:

2016-01-27 23:36:41.95 spid9s      Starting up database 'master'.
2016-01-27 23:36:42.04 spid9s      Error: 9003, Severity: 20, State: 6.
2016-01-27 23:36:42.04 spid9s      The log scan number (469:72:10) passed to log scan in database 'master' is not valid. This error may indicate data corruption or that the log file (.ldf) does not match the data file (.mdf). If this error occurred during replication, re-create the publication. Otherwise, restore from backup if the problem results in a failure during startup.
2016-01-27 23:36:42.04 spid9s      Cannot recover the master database. SQL Server is unable to run. Restore master from a full backup, repair it, or rebuild it. For more information about how to rebuild the master database, see SQL Server Books Online.
2016-01-27 23:36:42.04 spid9s      SQL Server shutdown has been initiated

What the Client Saw

My client wanted their SQL Server up and running as soon as possible. I always wish a client has a database backup before the problem happens. In this case, the master database was corrupt.

Why It Happens

The message says the log scan number is not valid. That points to data corruption, or to a log file that does not match the data file. SQL Server can’t recover master, so it shuts down.

That creates a catch. To restore master, we need SQL Server running. To start SQL Server, we need a working master database, and ours was corrupt.

Gouache painting of a wooden window frame with a new pane in place, sealed with a thin vermilion line of putty

How to Check

Look in the ERRORLOG for error 9003 on database ‘master’, followed by the line “Cannot recover the master database”. That pair tells you the service can’t start because master itself is damaged.

The Fix

To move forward, we had to rebuild the master database first. This is the command. Replace the instance name to match your installation: for a default instance it is MSSQLSERVER, otherwise use your instance name. The account and password switches need your own values.

setup.exe /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=MSSQLSERVER /SQLSYSADMINACCOUNTS= /SAPWD

Keep in mind that a rebuild also rebuilds the msdb and model databases. It is safe to copy the MDF and LDF files of those databases first. You can put them back after the rebuild is complete.

Once the rebuild is complete, restore the master database like this:

  1. Start SQL Server in single user mode with the -m parameter.
  2. Run the T-SQL below to restore master.
RESTORE DATABASE master FROM disk='C:\backup\master.bak' WITH REPLACE

Confirm It Worked

After the rebuild and the restore, we brought the SQL Server resource online successfully.

How to Prevent It

Keep a current backup of master. Without one, this fix has nothing to restore from.

Quick reference card: Error 9003 in master

A corrupt master is not the end of the instance, it is a rebuild and a restore away.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

Database Corruption, SQL Error Messages, SQL Server, Starting SQL, System Database
Previous Post
SQL SERVER – Why Cluster Network is Unavailable in Failover Cluster Manager?
Next Post
SQL SERVER – SSMS Tip – Using Drag and Drop Capability

Related Posts

7 Comments. Leave new

  • This saved me a lot of time, thank you! But users should be warned though that SQL Server users will be removed from the “Logins” list, and existing databases will be detached from the list of “Databases”. Nevertheless, great article indeed.

    Reply
  • Majid Hussain
    July 14, 2018 2:41 pm

    what should we do if we dont have master database backup..?

    Reply
    • Very sad to hear that.

      Reply
      • infoquestion
        May 14, 2019 9:03 pm

        When I run thsi command on Command line —- setup.exe /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=MSSQLSERVER /SQLSYSADMINACCOUNTS= /SAPWD

        I’m getting error message setup.exe is not recognized as INTERNAL OR EXTERNAL COMMAND– Please advice

  • Infoquestion
    May 14, 2019 9:07 pm

    when I run the above command on command line I ‘m getting ” is not recognized as an internal or external command

    Reply
  • setup.exe is the installer? I am using SQL Express 2005, and so the setup.exe is the installer of SQL EXPRESS 2005?

    Reply

Leave a Reply

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

Fill out this field
Fill out this field
Please enter a valid email address.