SQL SERVER – FIX: Msg 3009, Level 16 – Could not Insert a Backup or Restore History Detail Record in the msdb Database

As most of my blogs, this blog is also an outcome of an interesting engagement with a client. While trying to help one of my clients to recover from a hardware failure, I learned something about a trace flag. Let us learn about backup or restore history.

My client was trying to restore a database from the backup. Even though it was a small database, SQL was executing restore for a very long time and as soon as they cancelled it, the output was as follows:

36 percent processed.
73 percent processed.
100 percent processed.
Processed 328 pages for database ‘MyDatabase’, file ‘MyDatabase_Logical_File’ on file 1.
Processed 8 pages for database ‘MyDatabase’, file ‘MyDatabase_Logical_File1’ on file 1.
Processed 8 pages for database ‘MyDatabase’, file ‘MyDatabase_Logical_File1’ on file 1.
Processed 3 pages for database ‘MyDatabase’, file ‘MyDatabase_log’ on file 1.
Processed 0 pages for database ‘MyDatabase’, file ‘MyDatabase_log1’ on file 1.
Processed 0 pages for database ‘MyDatabase’, file ‘MyDatabase_log1’ on file 1.
Msg 3009, Level 16, State 1, Line 2
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.
Problems recording information in the msdb..suspect_pages table were encountered. This error does not interfere with any activity except maintenance of the suspect_pages table. Check the error log for more information.
RESTORE DATABASE successfully processed 347 pages in 0.578 seconds (4.683 MB/sec).
Msg 3204, Level 16, State 1, Line 2
The backup or restore was aborted.
Query was canceled by user.

When they checked the database, it was there and they were able to see all the data in it. This is the time they contacted me and wanted advice on what is happening.
I tried reproducing the same issue in my lab. To simulate logging issue to restore the history table in the msdb database, I have taken lock on the table using below statement.

begin tran
update [msdb].[dbo].[restorehistory] with (tablock)
set replace = 1

Note that, I have not issued rollback/commit and have tablock hint to cause locking. In another query window, I started to restore my database. I used below command

USE [master]
RESTORE DATABASE [Foo] FROM DISK = N'foo.bak' 
WITH FILE = 1, NOUNLOAD, STATS = 20
GO

SQL SERVER - FIX: Msg 3009, Level 16 - Could not Insert a Backup or Restore History Detail Record in the msdb Database TF3001-01

20 percent processed.
40 percent processed.
60 percent processed.
80 percent processed.
100 percent processed.
Processed 63872 pages for database ‘Foo’, file ‘Foo’ on file 1.
Processed 3 pages for database ‘Foo’, file ‘Foo_log’ on file 1.

< <<<<<<<<<<<<< Stuck here >>>>>>>>>>>>>>>>>>>
< <<<<<<<<<<<<< Below appeared when I cancelled the query >>>>>>>>>>>>>>>>

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.
Problems recording information in the msdb..suspect_pages table were encountered. This error does not interfere with any activity except maintenance of the suspect_pages table. Check the error log for more information.
RESTORE DATABASE successfully processed 63875 pages in 14.750 seconds (33.831 MB/sec).
Msg 3204, Level 16, State 1, Line 3
The backup or restore was aborted.
Query was canceled by user.

When I checked the database, it was there. This means only logging didn’t happen in the MSDB database. Note that this is only a simulation of the issue and the logging might go wrong because of any reason. One of the reasons could be that MSDB database is not available.

WORKAROUND/SOLUTION

If you are not bothered about the history of logging messages in MSDB, then we can use undocumented Trace Flag 3001. (Referred to my websites)

SQL SERVER - FIX: Msg 3009, Level 16 - Could not Insert a Backup or Restore History Detail Record in the msdb Database TF3001-02

While doing above, I still had the same blocking, but due to trace flag, the logging didn’t happen to MSDB tables and restore completed without error.
Have you ever heard of such trace flags?

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

, , ,
Previous Post
SQL SERVER – Error: Timeout (30000 milliseconds) Waiting for the SQL Server (MSSQLSERVER) Service to Connect
Next Post
MySQL – Fix – Error – Your Password does not Satisfy the Current Policy Requirements

Related Posts

2 Comments. Leave new

Leave a Reply

Menu