I have a very large MSDB database and have been working on clearing this out and setting up maintenance tasks – something my predecessor should have done years ago!
So far I've managed to truncate the sysmaintplan_logdetail and sysmaintplan_log files.
Now I'm hoping to look at some of the backup databases – the backupfile table is over 5Gb.
I tried to use the SP sp_delete_backuphistory but this filled my MSDB transaction log and almost killed the server…
Are there any other ways to clear this and shrink the file without causing any damage?
For information my MSDB data file is still 20Gb, used 13Gb. The log in 500Mb, used 6Mb.
Any help would be appreciated – I'm no DBA!
Best Answer
Do it in batches.
If your msdb is huge, then after running the script, to release unused space, I would recommend you to shrink your msdb (Yes shrink it and then once the space is released, you can do a reorg/rebuild and update stats use OLA's scripts - This shrink will be a one time thing to do- so that you can release the unused space).
Make sure that you schedule the below script to run on a frequent basis depending on how busy your servers is (in terms of frequency of jobs, logshipping is running or not and the use of database mail + the backups and restores happening on the server as they all log into MSDB)