Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Shrink large database Expand / Collapse
Author
Message
Posted Thursday, May 16, 2013 5:19 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, November 12, 2014 1:38 PM
Points: 22, Visits: 87
I have been asked to look a a sql 2000 database that has been neglected for some time.

It has an audit database linked to the system and no maintenance has been done on this database on over three years,

The database has grown to around 322Gb

I have started doing some maintenance on the table and deleted over 9million entries for just one months worth of auditing data for back in 2010 and I will need to continue doing this on a nightly basis until we only have around 6 month worth of audit data left.

Since I am deleting so much data, from the database, I thought it might be a good idea to shrink the database. I started shrinking the database and left it to run. The next day back at work it was still running and I had complaints from users using the system. I was reluctant to stop the shrink as I felt it woild stop soon. It continued to run and the next day before work started I decided to cancel the shrink.

Any suggestions on how to get this done more efficiently?
Post #1453813
Posted Friday, May 17, 2013 11:02 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, November 21, 2014 1:12 AM
Points: 132, Visits: 934
I'm curious has your database full backups taken longer to backup after removing/deleting all that data? We deleted Terabytes of data (though we have less data our backups take longer)

I'm considering moving all the data in current FileGroup and moving it to another FileGroup. if you have a big enough window that might be something that could be done?



--------------------------------------------------
...0.05 points per day since registration... slowly crawl up to 1 pt per day hopefully
Post #1454105
Posted Friday, May 17, 2013 2:56 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, November 12, 2014 1:38 PM
Points: 22, Visits: 87
Sorry I cannot really answer that.... as the server had been neglected, the backups appear to have failed for some time now.

Not sure it helps, but I noted as soon as I had cancelled the shrink that had been running a couple of days, the log file backup was much bigger.

I have been executing must of my commands to this server from a remote machine with SSMS 2008 installed. Today I decided to re-visit sql 2000 query analyser and fired that up on the server in question. I ran the shrink from there but instead of shrinking to 0% free I set it to 50% first.


The shrink ran suprisingly quick and freed up around 10gig. I ran another and this time set it to 40% and this ran quick also. I have now kicked off another delete to run over the weekend.

I feel confident that I will manage to get the space down significantly in this way.
Post #1454193
Posted Monday, May 20, 2013 3:00 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, November 21, 2014 1:12 AM
Points: 132, Visits: 934
terry.home (5/17/2013)
Sorry I cannot really answer that.... as the server had been neglected, the backups appear to have failed for some time now.

Might not be a bad idea to setup some backups, especially if it's important data. You could use the SQL Server maintenance plan feature as an option.


Not sure it helps, but I noted as soon as I had cancelled the shrink that had been running a couple of days, the log file backup was much bigger.


Thanks for the info. I've noticed that when running shrink there is some log growth, possible after log grew too when stopping? Good information, I don't use shrink often so that last part is interesting. Documentation on Shrink is not so good online. I wonder if Sybase docs would be better?... Mostly everything on internet just states "don't shrink" not really internals of how it works.


I have been executing must of my commands to this server from a remote machine with SSMS 2008 installed. Today I decided to re-visit sql 2000 query analyser and fired that up on the server in question. I ran the shrink from there but instead of shrinking to 0% free I set it to 50% first.


The shrink ran suprisingly quick and freed up around 10gig. I ran another and this time set it to 40% and this ran quick also. I have now kicked off another delete to run over the weekend.

I feel confident that I will manage to get the space down significantly in this way.


How did it go with shrinking 50% to 40%.. and lower? Did it get progressively slower to shrink as you got closer to the actual data size?


--------------------------------------------------
...0.05 points per day since registration... slowly crawl up to 1 pt per day hopefully
Post #1454751
Posted Wednesday, May 22, 2013 5:08 AM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Today @ 3:46 AM
Points: 709, Visits: 1,442
First thing's first, you need to get a good backup of that database. Next run a DBCC CHECKDB to ensure that after years of neglect that it is still consistent.

After that, if you can temporarily change the database to simple recovery then your deletes will go much faster, as they are not getting logged.


Joie Andrew
"Since 1982"
Post #1455428
Posted Wednesday, May 22, 2013 4:50 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, November 12, 2014 1:38 PM
Points: 22, Visits: 87
Thank you for the responses.

The backups are no longer failing. They were failing due to lack of disk space and this has now been sorted, partly down to allocating more disk space, and partly down to shrinking the file. Also found a very old, huge backup file which I deleted..

Both the shrink to 50% and 40% ran quick and as I am deleting more data every night (10's of millions) the database is progressively getting smaller.

Since I am deleting one months worth of data at a time, I expect to take another couple of weeks to get to a point where I only have 6 months worth of data left and will continue to shrink to 50% as I continue.
Post #1455755
Posted Thursday, May 23, 2013 3:02 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, June 6, 2014 2:44 AM
Points: 7, Visits: 157
After doing a shrink, also rebuild your indexes, as they will probably be invalidated by the shrink.

I don't do a shrink often, but in this case it was a valid choice. Only, one should indeed start with a slight decrease, and in most cases you're looking at days of decreased performance. Also, in my inderstanding, a shrink can not be cancelled, but I may be wrong. The reason why it finished quickly the next time tound, is because all the data had been moved already, so it's simply a matter of decreasing file size.
Post #1455897
Posted Sunday, May 26, 2013 11:15 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, November 21, 2014 1:12 AM
Points: 132, Visits: 934

The backups are no longer failing. They were failing due to lack of disk space and this has now been sorted, partly down to allocating more disk space, and partly down to shrinking the file. Also found a very old, huge backup file which I deleted..

Both the shrink to 50% and 40% ran quick and as I am deleting more data every night (10's of millions) the database is progressively getting smaller.

Since I am deleting one months worth of data at a time, I expect to take another couple of weeks to get to a point where I only have 6 months worth of data left and will continue to shrink to 50% as I continue.


This might be a moot point, since you're gone so far down this path "shrinking" and "deleting"....

I wonder if it's not too late to update add a thought. Have you considered.. copying the "6 months" of data needed into another table/filegroup instead of deleting 10's of millions in the database? I'm assuming last 6 month set is much smaller.



--------------------------------------------------
...0.05 points per day since registration... slowly crawl up to 1 pt per day hopefully
Post #1456964
Posted Monday, May 27, 2013 3:23 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, November 12, 2014 1:38 PM
Points: 22, Visits: 87
Not a bad suggestion. I have considired this, but not done it.
I dont know whether the last six months worth of data is any smaller in comparison to previous.
My original problem was a lack of disk space which caused performance issues. Therefore deleting and shrinking helped to free up some space and allowed the database to respond.

I could potentially now move the last 6 months to a new file, but once this is done, I assume I will still need to get the data older than 6 months deleted.

Am I wrong to think that I will therefore be adding another step into my process but still end up with the same result at the end of the process?


Regards
T
Post #1457149
Posted Tuesday, May 28, 2013 6:43 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 7:29 AM
Points: 35,554, Visits: 32,150
sqlsurfing (5/26/2013)

The backups are no longer failing. They were failing due to lack of disk space and this has now been sorted, partly down to allocating more disk space, and partly down to shrinking the file. Also found a very old, huge backup file which I deleted..

Both the shrink to 50% and 40% ran quick and as I am deleting more data every night (10's of millions) the database is progressively getting smaller.

Since I am deleting one months worth of data at a time, I expect to take another couple of weeks to get to a point where I only have 6 months worth of data left and will continue to shrink to 50% as I continue.


This might be a moot point, since you're gone so far down this path "shrinking" and "deleting"....

I wonder if it's not too late to update add a thought. Have you considered.. copying the "6 months" of data needed into another table/filegroup instead of deleting 10's of millions in the database? I'm assuming last 6 month set is much smaller.



+1 to that. It might also be a good time to consider partitioning the table to make future once-per-moth deletes easier.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1457290
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse