I was recently helping my client to SQL recovery from a hardware failure. I have implemented a good backup strategy for them, and things were easy. I saw a few interesting errors and I am writing a blog on them from the past few days. In this blog, we would discuss error: Error: 5173 – One or more files do not match the primary file of the database.
When I was trying to start SQL Server, it was getting started successfully but MSDB was not coming online.
• 2019-05-13 07:46:25.450 spid4s Error: 5173, Severity: 16, State: 1.
• 2019-05-13 07:46:25.450 spid4s One or more files do not match the primary file of the database. If you are attempting to attach a database, retry the operation with the correct files. If this is an existing database, the file may be corrupted and should be restored from a backup.
• 2019-05-13 07:46:25.450 spid4s Log file ‘L:\MSSQL\ DATA\MSSQL14.MSSQLSERVER\MSSQL\DATA\MSDBLog.ldf’ does not match the primary file. It may be from a different database or the log may have been rebuilt previously.
From the error message provided in SQL Server ERRORLOG, it is clear that the file is corrupted. There are two situations which you might have:
- If you have backups available, then restore last known good backup.
- If there is no backup available for MSDB database, then there are more steps to be followed. First, secure all the existing database files and save them to a different location. Few of them might be corrupted as well but take MDF and LDF backups to secure location. Next steps would be to perform REBUILDDATABASE as per this document.
Once rebuild is complete, then stop SQL Server and replace all the files which were secured earlier. In this situation MSDB was corrupt so we can leave MSDB and replace others.
As I mentioned earlier, we had backups taken of the database and all we needed to do was restore the MSDB database (first situation). If you are in situation # 2 and you don’t have MSDB backup then you need to find a way to recreate everything that you had in MSDB like Jobs, operator, log shipping, etc. That’s why taking regular backup is always a good idea and this client didn’t lose any data due to our backup strategy.
If you are looking for any such consultancy, feel free to contact me by visiting this link https://blog.sqlauthority.com/hire-me/
Reference: Pinal Dave (https://blog.sqlauthority.com)