SQL SERVER – The Log Scan Number Passed to Log Scan in Database ‘master’ is not Valid

SQL
7 Comments

If you have landed on this blog by searching below error, then I must tell you that your SQL Server service is not getting started. Let us learn in this blog how to fix  The Log Scan Number Passed to Log Scan in Database ‘master’ is not Valid.

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

When I was working with my client, all they wanted was to get his SQL Server up and running as soon as possible. I always wish that client has a database backup before the problem. In this case, the master database was corrupt.

The interesting situation here:

  • To restore master database, we need to start SQL Server.
  • To start SQL Server, we need a master database, which is corrupted.

SQL SERVER - The Log Scan Number Passed to Log Scan in Database 'master' is not Valid startpath-800x785

SOLUTION / WORKAROUND – Log Scan

to move forward, we had to rebuild the master database first. Here is the command which we should use.

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

Instance name needs to be replaced based on our installation. For a default instance, its MSSQLSERVER else it should be the instance name. We need to keep in mind that rebuild would rebuild other system databases, msdb and model, as well. It would be safe to take MDF and LDF files of those databases. They can be replaced back once rebuild is complete.

Once rebuild is complete, we need to restore the master database using the query below:

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

After rebuilding and restore, we could bring the SQL Server resource online successfully.

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

SQL Connection, 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 – Fix – Error 15240, Severity: 16, State: 2 – Cannot write into file

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