Skip to main content
  • Place orders quickly and easily
  • View orders and track your shipping status
  • Create and access a list of your products
Some article numbers may have changed. If this isn't what you're looking for, try searching all articles. Search articles

Microsoft SQL Server MSDB Database Recovery

Summary: Information on how to recover a Microsoft SQL Server MSDB database

This article applies to This article does not apply to This article is not tied to any specific product. Not all product versions are identified in this article.

Symptoms

When damaged and corrupted, a Microsoft SQL Server MSDB database may not come online and be operational. The SQL Server Agent Service does not start, and any scheduled jobs do not run automatically or manually.

Cause

SQL Server database file damage can occur for many different reasons. Most Microsoft SQL Server damaged MSDB database events occur because of hardware issues related to memory, disk, or processor problems.

Resolution

There are three methods to recover Microsoft SQL MSDB databases:
  1. Restore from backup
  2. Use DBCC CheckDB to repair MSDB database
  3. Replace the MSDB database files
MSDB database restore from backup:
The restore process using SQL Server Management Studio requires a current backup and can be performed by going to properties of the "msdb" database, Tasks > Restore > Database and pointing to the location of backup media.
 
Displays steps in SQL Server Studio Manager for restoring the MSDB database.

Use DBCC CheckDB for Database repair:
If no backup is available, we can run "DBCC CheckDB" to save the current MSDB database and its contents. The T-SQL commands below check the integrity of the MSDB database, run a soft repair of the MSDB database, and finally a hard repair of the MSDB database:
  • MSDB integrity check; is the database free of corruption?
Run the command below in the SSMS query window:
USE Master;
      GO
        ALTER Database MSDB
        SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
        GO
        DBCC CHECKDB (msdb, NOINDEX);
        GO
        ALTER DATABASE MSDB
        SET-MULTI_USER;
        GO
We want to check the line at the bottom of the return window reporting "allocation" and "consistency" errors. A damaged MSDB database reports an error and requires the DBCC CHECKDB commands below to repair.
 
Results of DBCC CHECkDB when checking for consistency errors.
  • MSDB T-SQL command for an attempted "soft recovery" with no data loss:
Run the command below in the SSMS query window:
USE Master;
      GO
        ALTER Database MSDB
        SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
        GO
        DBCC CHECKDB (msdb, REPAIR_REBUILD);
        GO
        ALTER DATABASE MSDB
        SET-MULTI_USER;
        GO
After running the command above, run DBCC CheckDB again to see new status of the the the database.
  • MSDB T-SQL command for an attempted "hard recovery" with possible data loss:
Run the command below in the SSMS query window:
USE Master;
      GO
        ALTER Database MSDB
        SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
        GO
        DBCC CHECKDB (msdb, REPAIR_ALLOW_DATA_LOSS);
        GO
        ALTER DATABASE MSDB
        SET-MULTI_USER;
        GO
After running the command above, run DBCC CheckDB again to see new status of the the database.

Replace the MSDB database files.
If the MSDB database is corrupt, and DBCC repair options have not worked, we can put a new MSDB database in by replacing the MSDB database files.

When we replace the MSDB database files we lose all information like custom backup jobs, task information, replication, log shipping, and maintenance plan data.

The steps below are used to replace an existing MSDB database with a new default MSDB database.
  • Browse to the SQL Server installation directory and go to the "Templates" folder under the "Binn" directory:
Showing file location of MSDB database and log templates.

The "msdbdata.mdf" and "msdblog.ldf" files are the MSDB database template files that we must bring up a new stable MSDB database.
  • We must stop the SQL Server Service to replace the existing MSDB database files.
Showing location in SQL Server Management Studio where the SQL Server Service can be started or stopped.
  • Go to the SQL Server Data directory. The directory path in the example below is "C:\Program Files\Microsoft SQL Server\MSSQL15.SQL2019\MSSQL\DATA"
image.png
 
  • Find the corrupt "msdbdata.mdf" and "msdblog.ldf" files.
Shows default MSDB database and log file location in SQL Server application directory.
  • Copy and move the files to another directory; in this case we are moving them to a folder called "MSDB_Save." There is a chance that these files can be imported into another SQL Server installation and checked again with DBCC CHECKDB; it is not a best practice to delete corrupt database files when troubleshooting.
                 Showing a location to store damaged MSDB database files.
  • Find where the MSDB temp database files are saved and put a copy of them back into our default SQL Server database directory:
Location of SQL Server MSDB database file templates
  • Final location for the MSDB database temp files; back in the default data directory of "C:\Program Files\Microsoft SQL Server\MSSQL15.SQL2019\MSSQL\DATA."
Active directory for MSDB database files
  • After replacing the MSDB database files, start the SQL Server Service.
Displaying where in SQL  Server Management Studio the SQL Server Service can be restarted.
 

Affected Products

Software, Dell Quickstart Data Warehouse Appliance, Microsoft Windows Server 2016, Microsoft Windows Server 2019, Microsoft Windows Server 2022, Prosupport for Microsoft Software
Article Properties
Article Number: 000200606
Article Type: Solution
Last Modified: 30 Nov 2023
Version:  4
Find answers to your questions from other Dell users
Support Services
Check if your device is covered by Support Services.