Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
gangadhara.ms
Aged Yak Warrior
549 Posts |
Posted - 2010-11-17 : 10:49:29
|
Dear All,I am DBA for production server DB with SQL server 2005 Enteprise Edition,as i am new to system DB file move.I want to move msdb data and log files from C:\ drive to E:\ drive without system offline.I have scheduled job of around 100-120 jobs but the size of my msdb database is very huge..!! what would be the size of the msdb database ??My msdb size: msdbdata.mdf --> 2.04 GB msdblog.ldf ---> 2.7 GBThanksGangadhar' |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
gangadhara.ms
Aged Yak Warrior
549 Posts |
Posted - 2010-11-17 : 21:20:28
|
Hi Tara,Thanks.I ran this procedure in SQl server 2005.But my msdb size didn't come down still its having size as earlier.create PROCEDURE [dbo].[Delete_Backup_History_new](@days_to_retain int = 4)ASBEGINSET NOCOUNT ONDECLARE @Err intDECLARE @rc intDECLARE @target_date datetimeSET @target_date = GETDATE() - @days_to_retainBEGIN TRANDELETE FROM msdb..restorefileFROM msdb..restorefile rfINNER JOIN msdb..restorehistory rh ON rf.restore_history_id = rh.restore_history_idINNER JOIN msdb..backupset bs ON rh.backup_set_id = bs.backup_set_idWHERE bs.backup_finish_date < @target_dateSET @Err = @@ERRORIF @Err <> 0GOTO Error_ExitDELETE FROM msdb..restorefilegroupFROM msdb..restorefilegroup rfgINNER JOIN msdb..restorehistory rh ON rfg.restore_history_id = rh.restore_history_idINNER JOIN msdb..backupset bs ON rh.backup_set_id = bs.backup_set_idWHERE bs.backup_finish_date < @target_dateSET @Err = @@ERRORIF @Err <> 0GOTO Error_ExitDELETE FROM msdb..restorehistoryFROM msdb..restorehistory rh INNER JOIN msdb..backupset bsON rh.backup_set_id = bs.backup_set_idWHERE bs.backup_finish_date < @target_dateSET @Err = @@ERRORIF @Err <> 0GOTO Error_ExitSELECT media_set_id, backup_finish_dateINTO #TempFROM msdb..backupsetWHERE backup_finish_date < @target_dateSET @Err = @@ERRORIF @Err <> 0GOTO Error_ExitDELETE FROM msdb..backupfilegroupFROM msdb..backupfilegroup bfgINNER JOIN msdb..backupset bs ON bfg.backup_set_id = bs.backup_set_idINNER JOIN #Temp t ON bs.media_set_id = t.media_set_idWHERE bs.backup_finish_date < @target_dateSET @Err = @@ERRORIF @Err <> 0GOTO Error_ExitDELETE FROM msdb..backupfileFROM msdb..backupfile bfINNER JOIN msdb..backupset bs ON bf.backup_set_id = bs.backup_set_idINNER JOIN #Temp t ON bs.media_set_id = t.media_set_idWHERE bs.backup_finish_date < @target_dateSET @Err = @@ERRORIF @Err <> 0GOTO Error_ExitDELETE FROM msdb..backupsetFROM msdb..backupset bsINNER JOIN #Temp t ON bs.media_set_id = t.media_set_idWHERE bs.backup_finish_date < @target_dateSET @Err = @@ERRORIF @Err <> 0GOTO Error_ExitDELETE FROM msdb..backupmediafamilyFROM msdb..backupmediafamily bmfINNER JOIN msdb..backupmediaset bms ON bmf.media_set_id = bms.media_set_idINNER JOIN #Temp t ON bms.media_set_id = t.media_set_idWHERE NOT EXISTS (SELECT media_set_id FROM msdb..backupset bsWHERE bs.media_set_id = t.media_set_idAND bs.backup_finish_date >= @target_date)SET @Err = @@ERRORIF @Err <> 0GOTO Error_ExitDELETE FROM msdb..backupmediasetFROM msdb..backupmediaset bmsINNER JOIN #Temp t ON bms.media_set_id = t.media_set_idWHERE NOT EXISTS (SELECT media_set_id FROM msdb..backupset bsWHERE bs.media_set_id = t.media_set_idAND bs.backup_finish_date >= @target_date)SET @Err = @@ERRORIF @Err <> 0GOTO Error_ExitCOMMIT TRANSET @rc = 0GOTO isp_DeleteBackupHistory_ExitError_Exit:ROLLBACK TRANSET @rc = -1isp_DeleteBackupHistory_Exit:DROP TABLE #TempSET NOCOUNT OFFRETURN @rcEND |
|
|
gangadhara.ms
Aged Yak Warrior
549 Posts |
Posted - 2010-11-17 : 21:37:19
|
After running above msdb job history cleaning and database mail clean up i didn't get any disk space cleared from msdb,could you please suggest.Thanks,Gangadhar |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
gangadhara.ms
Aged Yak Warrior
549 Posts |
Posted - 2010-11-18 : 03:41:07
|
As per the general thumb rule we should't prepare to shrink the DB files unless until its really required,do we have any other options to get freee the DB space.Thanks,Gangadhar |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-11-18 : 07:03:48
|
No. This is one of those "really required" cases. There was run-away expansion of the file. You have corrected that, and deleted the extraneous data, so now the file needs to be shrunk back to appropriate size. You should not do this often - so you need to prevent the run-away expansion happening again (e.g. by scheduling the housekeeping / cleanup task) - rather than shrinking it again in a short while |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|