Corrupted Model Database: How to Get SQL Server Running Again

A corrupted model database stops SQL Server from starting. Some of the advice about it on the internet is wrong. A reader emailed me with this problem and asked how to restore model from backup. The email made me think about how much incorrect information is out there.

Flow chart for SQL Server that will not start because of model corruption: if another instance has the exact same build, copy model.mdf and modellog.ldf; if not, back up all MDFs and LDFs, rebuild the system databases with Setup.exe and replace the files except model; then restore model if a backup is available

The Error

The reader said SQL Server could not start because of corruption in the model database. These are the messages in the SQL Server ERRORLOG. Error 5125 says the model.mdf file is smaller than expected.

2015-09-23 21:45:07.00 spid11s     Starting up database 'model'.
2015-09-23 21:45:07.45 spid11s     Error: 5125, Severity: 24, State: 2.
2015-09-23 21:45:07.45 spid11s     File 'E:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014\MSSQL\DATA\model.mdf' appears to have been truncated by the operating system.  Expected size is 4288 KB but actual size is 4280 KB.
2015-09-23 21:45:07.49 spid11s     SQL Trace was stopped due to server shutdown. Trace ID = '1'. This is an informational message only; no user action is required.

What the Reader Sent

The reader had a backup of the model database and wanted to restore it. They had spoken to many people and got different answers. They asked me for the right direction.

Why the Usual Advice Is Wrong

The problem is straightforward. Restore the backup of model when the current one is corrupted and SQL Server won’t start. A search on the internet gives these incorrect hints:

  1. Start SQL Server with trace flag 3608. From a command prompt, use sqlservr.exe -T3608.
  2. Start SQL Server from a command prompt using sqlservr.exe -c -m.

To test them, I renamed the model database files. Then I started SQL Server with trace flag 3608 and tried a restore. This is the message I received during the restore.

Shared Memory Provider: The pipe has been ended.
Communication link failure

Command prompt: net start mssql$sql2014 /T3608 starts the service, then sqlcmd runs RESTORE DATABASE MODEL FROM DISK = MODEL.BAK and returns Shared Memory Provider: The pipe has been ended. Communication link failure

Restoring model is not a big deal. It does not need a special switch or startup parameter. You can restore it with a T-SQL query or with the Management Studio interface. The real problem is that SQL Server does not start because model is in a bad state.

The Fix

There are two working solutions, and the flow chart at the top shows both. The first one works when another instance runs the exact same build of SQL Server.

  1. Take model.mdf and modellog.ldf from the working server and replace them on the non-working server.
  2. SQL Server should start now.
  3. Restore model if a backup is available.

If no other instance has the same build, use the second one.

  1. Take a backup of all MDFs and LDFs for ALL databases.
  2. Rebuild the system databases using Setup.exe.
  3. SQL Server should start now.
  4. Replace all MDFs and LDFs except the model files.
  5. Restore model if a backup is available.

Once SQL Server runs, model can be restored directly with T-SQL or with SSMS.

SSMS Object Explorer: right-click the model database under System Databases, then Tasks, Restore, Database

How to Prevent It

Keep a backup of model, as the reader did, so you have something to restore. Have you ever found incorrect information on the internet? Never trust information from untrusted sources.

Quick reference card: corrupted model database, two ways to get SQL Server running

A corrupted model database is not a restore problem, it is a startup problem.

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.

SQL Backup and Restore, SQL Error Messages, SQL Server, System Database
Previous Post
SQL SERVER – Failed Rule “Valid DSN” and “Valid Database compatibility level and successful connection”
Next Post
SQL SERVER – Basic architecture of Transaction Logs

Related Posts

8 Comments. Leave new

  • twoknightsthenight
    September 28, 2015 5:19 am

    Gail Shaw has an extensive post on this.

    Reply
  • If your SQL Server 2014 can’t start and show error of “model.mdf” then do the following steps:
    1) Copy “model.mdf” and “modellog.ldf” files form “C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER2014\MSSQL\Binn”
    2) Paste\overwrite those copied file inside “C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER2014\MSSQL\DATA”
    3) Restart SQL server 2014

    Reply
  • Dieter Brouckaert
    July 3, 2017 3:18 pm

    CMD command for rebuilding your system databases:
    Setup /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=InstanceName /SQLSYSADMINACCOUNTS=accounts [ /SAPWD= StrongPassword ] [ /SQLCOLLATION=CollationName]

    Source:
    https://docs.microsoft.com/en-us/sql/relational-databases/databases/rebuild-system-databases?view=sql-server-2017

    Reply
  • sachin jawalkar
    February 13, 2018 1:04 pm

    Hi sir i have also faced same issue i resolved this by copy paste from

    “C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Binn\Templates\”

    Reply
  • Hi Pinal

    This post has saved me..

    I was getting below error while starting SQL SERVER services.

    2018-07-01 18:39:32.96 spid6s [INFO] HkHostDbCtxt::Initialize(): Database ID: [3] ‘model’. XTP Engine version is 0.0.
    2018-07-01 18:39:32.96 spid6s Starting up database ‘model’.
    2018-07-01 18:39:32.98 spid6s [INFO] HkHostDbCtxt::Initialize(): Database ID: [3] ‘model’. XTP Engine version is 0.0.
    2018-07-01 18:39:33.50 spid17s [INFO] HkHostDbCtxt::Initialize(): Database ID: [7] ‘SACC LIVE’. XTP Engine version is 0.0.
    2018-07-01 18:39:33.57 spid6s [INFO] HkHostDbCtxt::Initialize(): Database ID: [3] ‘model’. XTP Engine version is 0.0.
    2018-07-01 18:39:33.59 spid6s Error: 9003, Severity: 20, State: 1.
    2018-07-01 18:39:33.59 spid6s The log scan number (33:1888:1) passed to log scan in database ‘model’ 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.
    2018-07-01 18:39:33.60 spid6s SQL Server shutdown has been initiated
    2018-07-01 18:39:33.60 spid6s SQL Trace was stopped due to server shutdown. Trace ID = ‘1’. This is an informational message only; no user action is required.

    I replaced model LDF and MDF file from working server and was able to start service.

    Great Thanks.

    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.