Groups | Blog | Home
all groups > sql server (alternate) > february 2005 >

sql server (alternate) : Shrinking database files



Jens
2/14/2005 12:18:37 AM
I have a database file LEAR_Index(yes, it hold index data) from a have
have recently removed a bunch of data.
It is about 120 Gb, 100Gb of which is not used. I wan=B4t to shrink the
file to lean 30-40Gb.

I=B4ve been trying this:

dbcc shrinkfile('LEAR_Index',40000)

But to no apparent avail; the file did not shrink.
I=B4ve tried using enterprise manager for this but it consistenly
crashes when performing this operation.#

Any thoughs, idear as to what i might be doing wrong?
Simon Hayes
2/14/2005 2:39:26 AM
Is LEAR_Index also the logical name of the database's data file? If
not, then you may have mixed up the syntax for DBCC SHRINKFILE and DBCC
SHRINKDATABASE:

DBCC SHRINKDATABASE(LEAR_Index, 30)
DBCC SHRINKFILE(LEAR_Index_Data, 40000)

If that doesn't help, perhaps you can post the result set from the DBCC
execution, or whatever output you get. This KB article might also be
relevant:

http://support.microsoft.com/default.aspx?scid=kb;en-us;324432

Simon
Erland Sommarskog
2/14/2005 11:42:05 PM
Jens (jens.aggergren@lycos-europe.com) writes:
[quoted text, click to view]

You may first have to run DBCC DBREINDEX to defragment fragmented
tables.



--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
Tzvika Barenholz
2/15/2005 5:01:47 AM

[quoted text, click to view]

It takes many hours on even good hardware to perform this operation.
you did not mention your disk setup.
In any event, if the actual usage is only 20gb, it may be cheaper to
create another file of 30gb, move the objects to it and drop the old
file.
alternatively you should consider partitioning, which will allow you do
make this move gradually.
Paul S Randal [MS]
2/15/2005 10:02:58 AM
Erland - why do you think this will help? Fragmented tables don't affect
shrink in the least, and also, shrink will most likely remove all the work
done by DBREINDEX as it tends to introduce fragmentation.

Thanks

--
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine

This posting is provided "AS IS" with no warranties, and confers no rights.

[quoted text, click to view]

Brian Cryer
2/15/2005 10:27:19 AM
I recall shrinking a database using enterprise manager and thinking it had
locked up (i.e. crashed) but it hadn't - it came back when it had finished
shrinking.

If Enterprise Manager appears to lock up then try shrinking using it before
you go home and see if it has finished by the following morning.

Brian.

www.cryer.co.uk/brian

Erland Sommarskog
2/15/2005 9:52:46 PM
Paul S Randal [MS] (prandal@online.microsoft.com) writes:
[quoted text, click to view]

Ok, thanks for the correction, Paul!


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
AddThis Social Bookmark Button