SQL SERVER – FIX: Msg 3009 – Could Not Insert a Backup or Restore History Detail Record in the MSDB Database


While preparing for a demo session for my client, I was playing with SQL Server backups on my lab server. I encountered an error which I am going to blog here. Here is the error about backup or restore history details.

Msg 3009, Level 16, State 1, Line 3
Could not insert a backup or restore history/detail record in the msdb database. This may indicate a problem with the msdb database. The backup/restore operation was still successful.

Here are the steps to reproduce the error.

USE [master]

Once above command is completed successfully, we can try to take a backup of any database. I have taken backup of the master database using the command mentioned below.


Here is the error which we would receive.

Here is the complete text of the error message, which is truncated in the image.

Processed 456 pages for database ‘MASTER’, file ‘master’ on file 1.
Processed 2 pages for database ‘MASTER’, file ‘mastlog’ on file 1.
Msg 3906, Level 16, State 1, Line 3
Failed to update database “msdb” because the database is read-only.
Msg 3009, Level 16, State 1, Line 3
Could not insert a backup or restore history/detail record in the msdb database. This may indicate a problem with the msdb database. The backup/restore operation was still successful.
BACKUP DATABASE successfully processed 458 pages in 0.045 seconds (79.427 MB/sec).
The statement has been terminated.


As we can see in the message, the backup has been successful but only logging to MSDB history tables didn’t happen. I must mention that above is just one of the causes of the error 3009. We need to look the error before that which is the root cause of the error. There are various probable causes and MSDB read-only was just one of them. Here are the possible errors:

  1. Error: Time-out occurred while waiting for buffer latch type 4 for page (1:2516), database ID 4.

Action Needed: This error indicates corruption in the database and we should run DBCC CHECKDB for MSDB database.

  1. Error: Database ‘msdb’ cannot be opened due to inaccessible files or insufficient memory or disk space. See the SQL Server ERRORLOG for details.

Action Needed: This error indicated that msdb is not opened. We should check ERRORLOG and find the cause.

If you are not bothered about the logging in MSDB database, then you can use trace flag 3001.


Above will stay active til SQL is stopped. To keep it ON permanently, you need to put it as a startup parameter. Read my earlier blog about Trace Flags. SQL SERVER – What is Trace Flag – An Introduction


Here is the command to cleanup MSDB mode.

USE [master]

Have you used such undocumented trace flags in SQL Server in production?

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

SQL Backup, SQL Error Messages, SQL Restore, SQL Scripts, SQL Server, SQL System Table, System Database, TraceFlags
Previous Post
SQL SERVER – Incorrect Error: Unable to Add Filegroup – A Severe Error Occurred on the Current Command
Next Post
SQL SERVER – SQL Service Not Starting in Cluster- The System Cannot Find the File Specified

Related Posts

6 Comments. Leave new

  • I’ve had this experience too, but it was caused by a very large msdb database (no cleanup) and no index maintenance. It was actually caused by a timeout

  • needed use TF3001 in a case where VLDBs are partitioned daily and have 8 files per partition which easily results to 10,000+ files per DB. Tlog backups writing to msdb causes the inserts to take 90% of the time where the actual backup only takes 2 mins.

  • We’ve encountered this today using Ola Hallengren maintenance solution, as per the log, it is due to deadlock. Will it affect the backup’s lsn?

  • I encountered this today and the reason was due to msdb primary file full. The backups were running from emc ddboost tool which was failing without any proper error message. I then ran the backup on SQL native to get the actual error message and then fix this. Increased the max size of primary file to few more MBs fixed the issue.

    Could not allocate space for object ‘dbo.sysjobhistory’.’clust’ in database ‘msdb’ because the ‘PRIMARY’ filegroup is full. Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.


Leave a Reply

Exit mobile version