Cleanup MSDB history tables


Job details

Name: Cleanup MSDB history tables
Platform: Sqlserver
Category: Maintenance
Premium package: Maintenance package
Description: This task deletes entries in the MSDB database history tables which holds statistics of backup/restore, jobs and maintenance plan executions.
Long description: This task reduces the size of the history tables which holds statistics of backup/restore, jobs and maintenance plan executions by deleting the entries older than the specified date.
Version: 1.5
Default schedule: 35 1 1 *
Requires engine install: Yes
Compatibility tag: .[type=‘instance’ & databasetype=‘sqlserver’]/instance[maj_version > ‘2000′ & hasengine=‘YES’]/.[engine_edition = ‘Microsoft SQL Server’ & eng_inst_priv = 0]

Parameters

Name Default value Description
delete history threshold 90 Number of days to provide information for in the history tables which holds statistics of backup/restore, jobs and maintenance plan executions.
delete backup/restore history YES If set to YES the task will run the sp_delete_backuphistory stored procedure to delete old statistics.
delete jobs history YES If set to YES the task will run the sp_purge_jobhistory stored procedure to delete old statistics.
delete maintenance plans history YES If set to YES the task will run the sp_maintplan_delete_log stored procedure to delete old statistics.
max delete size 60 The maximum number of days with statistics of backup/restore, jobs and maintenance plan executions which will be deleted/removed per execution of this task.
max records count 60000 If the historical table has less number of rows than the following parameter, the procedure will remove all older rows than the “delete history threshold” parameter value, without taking into account the “max delete size” parameter.

Job Summary

select 'backupset' as "History table", min(backup_finish_date) as "Oldest record", count(*) as "Record count" from msdb.dbo.backupset
union all
select 'sysjobhistory', min(convert(varchar, run_date, 112)), count(*) FROM msdb..sysjobhistory
union all
select 'sysmaintplan_log', min(start_time), count(*) from msdb.dbo.sysmaintplan_log

Implementation Details

Default Configuration and Parameters

Reporting

Dependencies and Setup

Version Handling and Upgrades

Error Handling

Additional Notes