Recovering a SQL 2012 cluster from a corrupt master database

 

Emergency support can be a bit stressful, especially out of hours on a system you’ve never worked on before.

We recently needed to step in to help a customer who’s 2 node SQL cluster had gone down late one night and managed to get it backup in a few hours after a major disk corruption on the data and logs volume of cluster shared disks taking our the system databases and the user databases.

The Errors

  1. The SQL service in failover cluster manager is showing as failed.

  2. The SQL server service won’t start manually.

  3. Error in the event log

[sourcecode language='text' ]
An error occurred while processing the log for database 'master'.  If possible, restore from backup. If a backup is not available, it might be necessary to rebuild the log.
[/sourcecode]

The Fix

Step 1.

Put the shared disks into maintenance mode in failover cluster manager and run chkdsk “drive” /F /X on all of them. Repairs will happen as necessary. In this case, a lot of repairs where made.

Step 2.

Take the disks out of maintenance mode and browse through to the data and logs volumes – we noted zero size user databases – those are gone for sure and need to be restored from backup one the system databases are fixed.

Step 3.

Stop, think and ignore the interweb search results you get back.

There is a lot of mention on the internet about using /ACTION=REBUILDDATABASE to rebuild the system database to get you back to the point where SQL will start and will let you restore a backup of the system databases.

This method didn’t work no matter what media or setup.exe we used, it silently failed and gave no errors.

[sourcecode language='text'  padlinenumbers='true']
setup.exe /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=MSSQLSERVER /SQLSYSADMINACCOUNTS=Domain\Username /SAPWD=blahblah1£23 /SQLCOLLATION=Latin_General_CI_AS_KS
[/sourcecode]

Go and find yourself another SQL instance running the same version, restore the master backups there.  As per this blog post, restore it with an alternative name such as “restore_master” for the both the database name and the database MDF and LDF files to avoid conflicts with the running SQL instance.

Copy those back over to your damaged SQL instance, rename the old ones and rename these restored back to the correct name.

hero-1Step. 4 Start SQL. Relax and restore the user databases as needed.

References

http://blogs.technet.com/b/fort_sql/archive/2011/02/01/the-easiest-way-to-rebuild-the-sql-server-master-database.aspx

http://msdn.microsoft.com/en-us/library/dd207003(v=sql.110).aspx

http://thomaslarock.com/2014/01/restore-the-master-database-in-sql-server-2012/

http://www.experts-exchange.com/Database/MS-SQL-Server/SQL_Server_2008/Q_25524423.html

http://blog.sqlauthority.com/2008/07/21/sql-server-fix-error-9004-an-error-occurred-while-processing-the-log-for-database-if-possible-restore-from-backup-if-a-backup-is-not-available-it-might-be-necessary-to-rebuild-the-log/

https://social.technet.microsoft.com/Forums/en-US/76e99d3a-0d6b-4ee3-8f22-6d56c3c6e50c/sql-2012-database-stuck-in-recovery-pending-status?forum=sqldatabaseengine