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

SQL
5 Comments

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]
GO
ALTER DATABASE [msdb] SET READ_ONLY WITH ROLLBACK IMMEDIATE 
GO

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.

BACKUP DATABASE MASTER TO DISK = 'master.bak'

Here is the error which we would receive.

Solarwinds

SQL SERVER - FIX: Msg 3009 - Could Not Insert a Backup or Restore History Detail Record in the MSDB Database msdb-err-3009-01-800x212

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.

WORKAROUND/SOLUTION

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.

DBCC TRACEON(3001,-1)

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

CLEANUP

Here is the command to cleanup MSDB mode.

USE [master]
GO
ALTER DATABASE [msdb] SET READ_WRITE WITH ROLLBACK IMMEDIATE 
GO

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

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

Solarwinds
, , , , , , ,
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

5 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

    Reply
  • 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.

    Reply
  • 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?

    Reply

Leave a Reply

Menu