473,657 Members | 2,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Time to shrink a database

Hi all,
I posted messages before about trying to purge many records (about 35%)
of a 200Gig database. The responses gave me a lot to think about,
especially regarding the indexes. But due to the short windows that I
have to run in, manipulating the indexes is not an option.

But this leads to another question. When all of this is done, we will
need to shrink the db to reclaim the space. We will also need to
rebuild the indexes, but this can be done one table at a time, so that
might be ok. What I am looking for is advice on how to get through a
shink of a 200G db on a fairly slow machine. Are there any 'tricks of
the trade' that will help me get through it? I believe one of the DBAs
said that they have not been able to shrink the db in years because it
takes longer than the longest available window.

Thanks In Advance

Apr 11 '06 #1
12 11760
(continuation of first post)

One idea that I had, which may not work at all, is as follows.

Copy a table to a temp db.
Do the shrink on the temp db.
Drop the original table.
Move the table from the temp db to the original db.

Repeat for each table in the db.

Shrink the original db.

The thought behind this is that if you shrink a db with only one table,
you can get through it much quicker than shrinking a db with all of the
tables in it. This could be done in the available window.
Then when you shrink the original db, there is less work to do since
each table was already shrunk.
I assume that because of the files behind the DBs, this would not work.
Any thoughts on this would be appreciated. I am planning on setting up
a test of this, but if it is a waste of time, please let me know.

Thanks

Apr 11 '06 #2
ha*****@yahoo.c om (ha*****@yahoo. com) writes:
I posted messages before about trying to purge many records (about 35%)
of a 200Gig database. The responses gave me a lot to think about,
especially regarding the indexes. But due to the short windows that I
have to run in, manipulating the indexes is not an option.

But this leads to another question. When all of this is done, we will
need to shrink the db to reclaim the space. We will also need to
rebuild the indexes, but this can be done one table at a time, so that
might be ok. What I am looking for is advice on how to get through a
shink of a 200G db on a fairly slow machine. Are there any 'tricks of
the trade' that will help me get through it? I believe one of the DBAs
said that they have not been able to shrink the db in years because it
takes longer than the longest available window.


I'm not sure you are going shrink at all. Even if you are removing
a lot of rows from the database, I assume that new rows keep coming in
all the time? There is no point in shrinking, if it will grow again.

Reindexing on the other hand is a good idea, but this it not something
you should run when your DELETE job is done, but which should be performed
regularly. Defragmenting can be performed in two ways DBCC DBREINDEX and
DBCC INDEXDEFRAG. The first is an offline operation, that is the table
is not accessible while it's running. INDEXDEFRAG is an online operation.
Again, I'm assuming that data is inserted and updated in the
database on a regular basis.

According to Books Online, shrinking is an online operation in the sense
that uses can keep on working. I would expect it to take some load,
and I would certainly not run a shrink on office hours. A tip is to
specify a target size; that's the variation I've been most successful
with.

If you are going to shrink, which again I don't recommend, the best is
to do this when all tables have been reduced by your deletion job.
You cannot shrink one table at a time as you outlined in you other
post.

Once you have completely any shrinking, you should definitely run
defragmentation , as shrinking causes a lot of fragmentation.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Apr 11 '06 #3
Ok, I think I understand your point about not shrinking the db. Does
this mean that new records will be written to the space that was freed
up by the deletes? I thought that the space would not be reused until
you did a shrink to release it.
However, my purge will be removing about 200 million records and the db
only grows at about 10 million per month. So it would take a long time
to fill up the space freed by the purge.

As for the DBREINDEX and the INDEXDEFRAG, do they produce similar
results? The DBAs that I am doing this for seem to believe that a
reindex will give a bigger performance boost than the defrag.

thanks

Apr 12 '06 #4
Does anyone have a resource on index defragmentation that could be done
on a schedule for an entire database based on some automated
statistics? I see plenty of info in BOL, but whether I should use fill
factors of 80, 30 or what I have no idea. We have never done any kind
of index defragmentation - is there some way that the database itself
can just handle it?

Apr 12 '06 #5
ha*****@yahoo.c om (ha*****@yahoo. com) writes:
Ok, I think I understand your point about not shrinking the db. Does
this mean that new records will be written to the space that was freed
up by the deletes?
Not really. If you don't defragment, the likelyhood that any space will
be reused is small. But if you defragment, the tables are compressed,
and the free space moved to free extents where it indeed can be reused.
I thought that the space would not be reused until
you did a shrink to release it.
When I think of it, you will probably have to defragment before you
can shrink. Shrinking works with free extents I guess. So if there
are pages in a table that are 10% full, that space will not be
reclaimed by a shrink.
However, my purge will be removing about 200 million records and the db
only grows at about 10 million per month. So it would take a long time
to fill up the space freed by the purge.
Less than two years.
As for the DBREINDEX and the INDEXDEFRAG, do they produce similar
results? The DBAs that I am doing this for seem to believe that a
reindex will give a bigger performance boost than the defrag.


I will have to admit that I am not too well acqauinted with INDEXDEFRAG
to answer. I personally prefer DBREINDEX, but it has the drawback of
closing out users, which appears to be a concern for you.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Apr 12 '06 #6
pb648174 (go****@webpaul .net) writes:
Does anyone have a resource on index defragmentation that could be done
on a schedule for an entire database based on some automated
statistics? I see plenty of info in BOL, but whether I should use fill
factors of 80, 30 or what I have no idea. We have never done any kind
of index defragmentation - is there some way that the database itself
can just handle it?


I guess that you can set up a maintenance job, but I think it's better
to run a separate job.

The easy way is just to run a cursor over sysobjects and run DBREINDEX
on all tables. As long as you have enough off-hours to permit this, this
may be good enough. And it's certainly far better than nothing at all.

A colleage of mine has composed a reindexing job for our system. It uses
DBCC SHOWCONTIG to check for fragmentation, and runs DBREINDEX only if
fragmentation is over 30%. For the tables with lower fragmentation, he
instead runs UPDATE STATISTICS WITH FULLSCAN INDEX on my insistence. This
is because some tables have monotonically growing keys, so they don't
fragment, but statistics easily gets out of date, as new rows are always
added outside the current intervals in the histogramme.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Apr 12 '06 #7
So there isn't some source out there that has the script posted on the
net? If this is something that should be done for every single
database, why should every person write their own and go through a
development bug fix cycle to figure out what they are doing wrong? I'm
worried about throwing something together and it causing more problems
than it solves (right now we have no problems as far as I know related
to indexes or fragmentation for databases in use for years).

Apr 13 '06 #8
pb648174 (go****@webpaul .net) writes:
So there isn't some source out there that has the script posted on the
net? If this is something that should be done for every single
database, why should every person write their own and go through a
development bug fix cycle to figure out what they are doing wrong? I'm
worried about throwing something together and it causing more problems
than it solves (right now we have no problems as far as I know related
to indexes or fragmentation for databases in use for years).


I didn't say that there is not anything publicly available for this, but
I was too lazy to start searching for something. As a matter of fact the
code that we use to get the tables with 30% more fragmentation was some-
thing that SQL Server MVP Andrew Kelly posted to
microsoft.publi c.sqlserver.too ls once. (I believe that it was that news-
group, but I could be wrong.)

SQL Server comes with maintenance plans where you can set this up,
and probably get some default. But the problem is, that this is not a
case of one size fits all. There are several factors involved: how
much data is inserted? updated? deleted? What availability requirements
do you have? Do you need to use GUIDs etc.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Apr 13 '06 #9
The total database size is less than half a gig. Most of the time the
data is being read, with maybe 20% of the time being inserts and
updates. I would like an expert to give me the link so I know I'm not
getting the wrong thing.. I see plenty of stuff out there but am unsure
what the right thing to do is. I was hoping there would be
functionality in SQL 2005 that would just handle it.

Apr 18 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5461
by: Adrian Parker | last post by:
Hello all. I have a Access database which I read records from. All the records read fine, except the Date/Time field of the database is not being properly assigned to my Date-Time-Picker control in my VB code. I've tried setting the datasource and fields with both code, and by using the Adodc control (and setting the DTP control datasource, datafield, and dataformat properties via the VB interface). All I get is an error 545 code,...
1
1751
by: Kelvin | last post by:
Hi all, Any some tools or sample codes drop down asp script execute time and database connection time ? Thanks.
4
6726
by: Tommy.Vincent | last post by:
hi all, This will be a easy question for all out here. I have a database of 28GB. having 3 Data Files 22 GB, 3.58 Gb and 2.70 GB respectively. and a Transaction Log file of 156 mb. When i executed DBCC Shrinkdatabase(databasename),it reduced size of datafile but the LOG file had gone up to 5 Gb from 156mb.
1
5825
by: jdph40 | last post by:
I am using Access 2002. I downloaded the forms sample database FrmSmp97.mdb from Microsoft and used the following code in the timer event of a hidden form in order to close a database if no activity was detected. I have it set for one minute for testing purposes only. However, my problem with this code is when the message box pops up and says "No user activity detected...", you have to actually click the OK button before the database...
7
1888
by: Shivalee Gupta via AccessMonster.com | last post by:
i am working on access 2000. can i write a code which will tell me, at the time of closing the database, that at what time i had opened the database and at what time i am closing it? i am in a single user environment. i just want to check whether someone is opening my databse behind my back! thanks. -- Message posted via http://www.accessmonster.com
1
1585
by: simon | last post by:
I have time in my program: for example: dim timeTest as datetime timeTest="10:15:10" I save this time to database as decimal value: timeTest.ToOADate - I get the decimal value and I save it to database
0
1362
by: janbazamin | last post by:
Hi Dear. I am making time table application in ASP.NET i am facing some problem i am adding Start time, End Time In Database. on some date. if i again select same date and stat time and end time. i am successfull that application show me it is already exits. i am entering time like this . 8:00 am to 10: 00 am. when i enter the time like this 8:05 amd to 9:45 am it should show me already exits but t not show me . it entered in database on same...
0
1699
by: janbazamin | last post by:
I am making time table application in ASP.NET i am facing some problem i am adding Start time, End Time In Database. on some date. if i again select same date and stat time and end time. i am successfull that application show me it is already exits. i am entering time like this . 8:00 am to 10: 00 am. when i enter the time like this 8:05 amd to 9:45 am it should show me already exits but t not show me . it entered in database on same date. I...
8
1973
jschrader
by: jschrader | last post by:
I am trying to write a conditional Statement in ASP based on dates/times in a database entry. I'm basically a ASP/web designer and try my best to get into the fun coding, so not sure as to the syntax of what I'm trying to do... The structure I'm working on is Database Connection Select DB record occuring "Today" - have this working with BETWEEN statement DO UNTIL RS.EOF IF RS(title) < FromTime or >UntilTime Then
1
1920
by: MANU1k | last post by:
My database properties show Space Available 0.00 MB. And users complain the application is very slow. Do i need to do a database shrink? Also can i schedule db shrink on a weekly basis is that advisable?
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.