Quantcast
Channel: SQL Backup Archives - SQL Authority with Pinal Dave
Viewing all articles
Browse latest Browse all 110

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

$
0
0

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.

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)

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


Viewing all articles
Browse latest Browse all 110

Trending Articles