Author |
Topic |
Goalie35
Yak Posting Veteran
81 Posts |
Posted - 2011-07-19 : 01:14:10
|
My server is close to running out of space and I was trying to find out why. Turns out, the largest culprit is that my sql server 2005's MSDB database is up to 25gb. I'm not a dba, so I wasn't really sure how to resude the size. I went onto the internet, found a script to run, and executed it. It ran successfully however the odd thing now, is my msdb tables are all trunacted however, my total file size of the msdb database is still 25gb! How can I reduce this size? Thanks |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
Goalie35
Yak Posting Veteran
81 Posts |
Posted - 2011-07-21 : 09:32:12
|
Hi Tara. Thanks for the reply.Unfortunately, shrinking my database didn't affect it all too much. I tried shrinking via both the gui & the dbcc shrinkfile, however it merely went from 25gb down to 24.5gb. At this point, I'm dangerously low on space, so I was hoping to essentially knock this database down to zero, if possible. Is there any way to do that? If I were to simply go in and delete the entire msdb database, I'm guessing my sql server would probably experience problems right?Thanks again. |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-07-21 : 09:42:03
|
quote: If I were to simply go in and delete the entire msdb database, I'm guessing my sql server would probably experience problems right
That's the understatement of the year. Don't do it.First off, find out how large the data and log files are individually. You can look at this in the Properties tab of the database when you right-click, or use the Disk Usage report under the Reports option. You should also run the Disk Usage by Top Tables report and see which tables are largest.If you've "truncated" all the msdb tables (also a no-no but seems to be too late) then you shouldn't have any trouble shrinking it. My guess is there's a mail or backup history table that still has a lot of data in it, or your msdb database is set to full recovery and the log needs to be backed up. |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-07-21 : 09:59:27
|
Are you saving lots of ssis/dts packages there with their versions? Move them out to files.How much job history are you holding?How big is the log?Has anyone created user tables?Log shipping?First step is probably to find out which tables are big.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
Goalie35
Yak Posting Veteran
81 Posts |
Posted - 2011-07-26 : 16:35:40
|
Nigel, in response to your questions, please see below:Q: Are you saving lots of ssis/dts packages there with their versions? Move them out to files.A: I don't have any ssis/dts packages set on this databaseQ:How much job history are you holding?A: I'm not really sure. How would I find that?Q: How big is the log?A: I'm not really sure. How would I find that (I have very little dba experience)?Q:Has anyone created user tables?A: NoQ: Log shipping?A: NoQ: First step is probably to find out which tables are big.A:The following are my msdb table sizes. The rows are very small so I'm baffled as to where these 25gb are hiding:MSdbms_datatype_mapping 325MSdbms_map 248MSdbms_datatype 141syssessions 45syscategories 21syssubsystems 11MSdbms 7sysmail_configuration 7sysdtscategories 3sysmail_log 2sysdtspackagefolders90 2sysmail_servertype 1sysdbmaintplans 1sysdownloadlist 0sysdbmaintplan_databases 0sysdbmaintplan_history 0sysdbmaintplan_jobs 0restorefile 0restorefilegroup 0restorehistory 0sqlagent_info 0suspect_pages 0sysalerts 0syscachedcredentials 0backupfile 0backupfilegroup 0backupmediafamily 0backupmediaset 0backupset 0log_shipping_monitor_alert 0log_shipping_monitor_error_detail 0log_shipping_monitor_history_detail 0log_shipping_monitor_primary 0log_shipping_monitor_secondary 0log_shipping_primaries 0log_shipping_primary_databases 0log_shipping_primary_secondaries 0log_shipping_secondaries 0log_shipping_secondary 0log_shipping_secondary_databases 0logmarkhistory 0sysmaintplan_log 0sysmaintplan_logdetail 0sysmaintplan_subplans 0sysnotifications 0sysoperators 0sysoriginatingservers 0sysproxies 0sysproxylogin 0sysproxysubsystem 0sysschedules 0sysmail_mailitems 0sysmail_principalprofile 0sysmail_profile 0sysmail_profileaccount 0sysmail_query_transfer 0sysmail_send_retries 0sysmail_server 0sysdtspackagelog 0sysdtspackages 0sysdtspackages90 0sysdtssteplog 0sysdtstasklog 0sysjobactivity 0sysjobhistory 0sysjobs 0sysjobschedules 0sysjobservers 0sysjobsteps 0sysjobstepslogs 0sysmail_account 0sysmail_attachments 0sysmail_attachments_transfer 0sysdtslog90 0systargetservergroupmembers 0systargetservergroups 0systargetservers 0systaskids 0Thanks again. |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-07-26 : 16:45:08
|
Run the following query and post the results:select size/128 MB, name, physical_name from sys.master_files where database_id=db_id('msdb') |
|
|
Goalie35
Yak Posting Veteran
81 Posts |
Posted - 2011-07-27 : 00:07:05
|
The results are as follows:MB | Name | Physical_Name-------------------------------------------------------------25255 | MSDBData | C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\MSDBData.mdf0 | MSDBLog | C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\MSDBLog.ldf-------------------------------------------------------------Thanks |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-07-27 : 07:20:12
|
This should fix the problem:USE msdbDBCC SHRINKFILE(1,256)After you shrink the file, run the following:EXEC sp_msforeachtable 'ALTER INDEX ALL ON ? REORGANIZE'That will defragment the tables in msdb, which will become fragmented from the shrink operation. |
|
|
Goalie35
Yak Posting Veteran
81 Posts |
Posted - 2011-07-27 : 09:25:23
|
Hi robvolk.Thanks for the reply but unfortunately, that didn't work. My database is still 25gb.My results returned the following:DblID | FileId | CurrentSize | MinimumSize | UsedPages | EstimatedPages---------------------------------------------------------------4 | 1 | 3233920 | 384 | 3233864 | 3233864Thanks |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-07-27 : 09:31:49
|
You may have to run it several times. Also try alternating with this:DBCC SHRINKFILE(1, TRUNCATEONLY) |
|
|
DBA in the making
Aged Yak Warrior
638 Posts |
Posted - 2011-07-28 : 06:21:32
|
You can try running this script, which will tell you how much data is being used by each table.USE msdbDECLARE @TableName VARCHAR(100) --For storing values in the cursorDECLARE @UserName VARCHAR(100) --For storing values in the cursorDECLARE @FullName VARCHAR(201) --For storing values in the cursor--Cursor to get the name of all user tables from the sysobjects listingDECLARE tableCursor CURSORFOR select o.[name] AS TableName, u.[name] as UserNamefrom dbo.sysobjects oINNER JOIN dbo.sysusers u ON o.uid = u.uidwhere OBJECTPROPERTY(id, N'IsUserTable') = 1ORDER BY o.NameFOR READ ONLY--A procedure level temp table to store the resultsCREATE TABLE #TempTable( userName varchar(100), tableName varchar(100), numberofRows varchar(100), reservedSize varchar(50), dataSize varchar(50), indexSize varchar(50), unusedSize varchar(50))--Open the cursorOPEN tableCursor--Get the first table name from the cursorFETCH NEXT FROM tableCursor INTO @TableName, @UserName--Loop until the cursor was not able to fetchWHILE (@@Fetch_Status >= 0)BEGIN --Dump the results of the sp_spaceused query to the temp table SET @FullName = '[' + @UserName + '].[' + @TableName + ']' PRINT @UserName + ' - ' + @TableName INSERT #TempTable (tableName, numberofRows, reservedSize, dataSize, indexSize, unusedSize) EXEC sp_spaceused @FullName UPDATE #TempTable SET userName = @UserName WHERE userName IS NULL --Get the next table name FETCH NEXT FROM tableCursor INTO @TableName, @UserNameEND--Get rid of the cursorCLOSE tableCursorDEALLOCATE tableCursor--Select all records so we can use the reultsSELECT * FROM #TempTableORDER BY CAST(numberofRows AS BIGINT) DESC--Final cleanup!DROP TABLE #TempTable ------------------------------------------------------------------------------------Any and all code contained within this post comes with a 100% money back guarantee. |
|
|
Goalie35
Yak Posting Veteran
81 Posts |
Posted - 2011-07-28 : 16:30:14
|
Robvolk,Unfortunately, that didn't work either. I tried running the dbccshrinkfile (both versions you gave me), alternating between the two versions about a dozen times but still no luck. My database is still listed as 25gbAny other ideas? Thanks again, I really appreciate your help!! |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-07-28 : 17:01:18
|
Honestly, I think you should contact Microsoft support, because something is not right if it won't shrink with so little data in it.Have you run DBCC CHECKDB on msdb? Maybe there's some corruption or other error that's behind it. |
|
|
Goalie35
Yak Posting Veteran
81 Posts |
Posted - 2011-08-03 : 00:38:14
|
Robvolk, thanks for the suggestion of running dbcc checkdb, but unfortunately, after about 10 minutes of running this, I get an error stating my hard drive is out of space, and terminates the query.As another option, if I were to simply copy and paste the 2 databases I care about (only about 100mb of data in total) to create backups of them, then uninstall sql server, reinstall it, and finally paste the 2 databases back in again, would this be a viable alternative?Thanks again. |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-08-03 : 06:19:04
|
No, that's not a viable option. Never copy database files, use the SQL Server BACKUP command to make backups, and RESTORE to restore them to a new server. You can also try detaching and attaching the databases, but make backups first.I still recommend contacting Microsoft Support. |
|
|
DBA in the making
Aged Yak Warrior
638 Posts |
Posted - 2011-08-03 : 09:28:27
|
quote: Originally posted by Goalie35 Robvolk, thanks for the suggestion of running dbcc checkdb, but unfortunately, after about 10 minutes of running this, I get an error stating my hard drive is out of space, and terminates the query.As another option, if I were to simply copy and paste the 2 databases I care about (only about 100mb of data in total) to create backups of them, then uninstall sql server, reinstall it, and finally paste the 2 databases back in again, would this be a viable alternative?Thanks again.
Did you run the script I posted earlier?------------------------------------------------------------------------------------Any and all code contained within this post comes with a 100% money back guarantee. |
|
|
manju3606
Yak Posting Veteran
78 Posts |
Posted - 2011-08-04 : 08:51:55
|
Hi, Take your msdb database backup exit sql server management studio stop the instant of sql server and restart the instance of sql server in masteer-only recovery mode by using command prompt and change your msdb physical location by using alter database command and restor your msdb backup to that new location.after restor exit sql server management studio stop the instant of sql server and restart the instance of sql server normalyManju |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-08-04 : 09:34:22
|
quote: Originally posted by manju3606 Hi, Take your msdb database backup exit sql server management studio stop the instant of sql server and restart the instance of sql server in masteer-only recovery mode by using command prompt and change your msdb physical location by using alter database command and restor your msdb backup to that new location.after restor exit sql server management studio stop the instant of sql server and restart the instance of sql server normaly
Ummmm, no. Backing up and restoring will not change the file sizes, and there's no need to stop/restart the SQL Server to do any of this. You can RESTORE DATABASE...WITH MOVE to move it to a new location, which doesn't sound like a viable option unless the OP can install additional drives...which also solves the problem. |
|
|
manju3606
Yak Posting Veteran
78 Posts |
Posted - 2011-08-04 : 16:39:13
|
Hi,Goalie35 please tell me,what is your msdb full backup size?Manju |
|
|
Next Page
|