Monthly Archives: November 2017

MSDB Tuning by purging backup and restore history

Have you ever had problem with your backup jobs taking more time than usual overlapping your maintenance window? It is the disk IO throughput fast enough? or it is your SQL Server not performing well? what could be affecting the performance to avoid your backup job to completely in timely fashion?

The answer to all these questions is not that difficult to find, in most of the cases there is a common point of failure for backup jobs taking more time with the past of the time. Your databases are bigger and your backup and restore history has been retained forever (since the SQL instance was created).

Most of the DBAs in the wild doesn’t know about this very important performance tuning aspect, they completely forgot about paying attention to the MSDB database. Probably because this is a system database there is an assumption that does not requires maintenance as any other regular database.

According to Microsoft docs you simply have run the sp_delete_backuphistory stored procedure in MSDB database, providing a date parameter to be used by this process as your oldest date to retain data to …. but guess what it  does not work well and is not that simply.

Before you go for it, you must consider the following aspects:

  • Purging this backup and restore history leads to blocking into MSDB
  • Running the in sp_delete_backuphistory stored procedure causes odd problems to your ongoing or scheduled SQL Agent jobs
  • The sp_delete_backuphistory it’s not optimal and takes a long time to run

So what are your options?

  • Understand what the sp_delete_backuphistory stored procedure is doing and write your own

Probably not the best option, because it will require you to invest time doing research, analysis, design and testing

  • Look for missing indexes in all the MSDB tables purged by the sp_delete_backuphistory stored procedure (Best option due the amount of time you have to invest creating a new process)
  • Schedule a job to purge the backup history during short periods of time after all your daily jobs are completed

This is a good option, because we have identified those indexes beforehand for you and also there is no development effort to re-create a process that already exists. Also you probably can schedule a job to run every weekend to purge 2 weeks of data at the time so the MSDB is not compromised by the purging effort.

Based on our experience adding the missing indexes to all the tables involved in the purge process, we noticed an improvement of 60% of the sp_delete_backuphistory stored procedure. So go ahead and try it and let us know how everything works for you 🙂

Happy purging, stay tuned for more DBA mastery tips.


  • This indexes works starting from SQL Server 2008 R2 SP3
  • You can find the MSDB Missing indexes script here

SQL Server Management Studio Reports

Today’s tip is a very basic functionality that comes with any SSMS (SQL Server Management studio), we are talking about SSMS Instance and Database level reports.

These SSMS reports does not require any additional plugin or either SSRS (SQL Server Reporting Services), all these aware reports are part of any out of box SSMS instance you might have installed in your environment.

As mentioned above, there are two different levels of reports please keep in mind each set has unique reports that only applies to the specific level selected.

In order to explore the Instance level reports you just need to simply right click on your SQL Server instance, then select Reports, then Standard Reports:

In order to explore the Database level reports you just need to simply right click on any or your existing  SQL Server databases, then select Reports, then Standard Reports:

We are not going to dive deep on all these reports because as you may noticed there are too many and the report name does well job describing their purpose.

We will cover the Custom Reports option in the near future, stay tune for more DBA mastery tips.