Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Problems after running SHRINKFILE

 
   Database Help (Home) -> Programming RSS
Next:  stored proc to up date values  
Author Message
Farmer Nook

External


Since: Oct 27, 2010
Posts: 3



(Msg. 1) Posted: Wed Oct 27, 2010 2:17 am
Post subject: Problems after running SHRINKFILE
Archived from groups: microsoft>public>sqlserver>programming (more info?)

Hi,

I have major problems after doing a SHRINKFILE on a SQL2K5 database. I
read all the articles that said that you shouldn't do it unless
absolutely necessary so was well aware of the risks, but had no choice
as there was no room on disk for the transaction log to grow, causing
major headaches with long running transactions.

The problem that I have is that all indexes are badly fragmented but a
REBUILD and a REORGANIZE is having no effect on them. The index
fragmentation has gone from 0.x to > 85% in most cases. Batch jobs
taking 20 minutes now take over 10 hours and performance has hit rock-
bottom.

When I came in on Monday morning after the SHRINKFILE (over the
weekend) and checked the index fragmentation it all still looked good
(0.x% etc). Once the overnight job on Monday evening pushed data into
the tables, fragmentation went up, but a REBUILD on the major indexes
seemed to help the job finish in a timely manner. However, Tuesday
night's batch job has pushed the fragmentation back up again and this
time, no amount of rebuilding or reorganizing has made any difference.

I've also tried creating new tables and copying the data from a table
with fragmented indexes into the new tables, then adding indexes
(before and after) to see if that fixes the problem but strangely
enough the fragmentation is exactly the same (> 85%) as on the
original table. Does this make sense?

Has anyone else come across this problem? Or any suggestions on how to
fix it?
Any help gratefully received Smile

Many thanks,
F.

 >> Stay informed about: Problems after running SHRINKFILE 
Back to top
Login to vote
Farmer Nook

External


Since: Oct 27, 2010
Posts: 3



(Msg. 2) Posted: Wed Oct 27, 2010 6:09 am
Post subject: Re: Problems after running SHRINKFILE [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi Bob,

I think that the problem may be that the SHRINKFILE was done in 50MB
chunks to allow us to stop it at any point.
The previous time that we tried to run it, we ran it without any size
limit on it. It ran for over 17 hours before we had to kill it and it
didn't seem to have done much.
I suspect that it was doing stuff but because it had over 150GB to
chug through it was always going to take a long time.
By breaking it up into smaller peices we hoped to have more control
over it, by being able to see how long each database shrink took and
by being able to stop it without losing any of the work that had
already been done. We had no idea what a reasonable chunk would be so
settled on 50MB. In hindsight, perhaps it would have been better to
have made the chunks larger. What we suspect has happened is that the
database is now made of small 50MB chunks (some with data, some with
no data) that are not allowing all the index rows in a table to reside
together contiguously. So that no matter how much we rebuild, the
tables are always trying to slot into 50MB 'holes'. We could be wrong,
but it would be good if someone with more knowledge could confirm
whether this would be the case or not?

Now we just need to understand the best way to get back to where we
want to be.
At present we are only (re)building a small proportion of the indexes
that exist in the database, basically the ones that are affecting us
the most. So would it be a good idea to rebuild all indexes regardless
of whether we think we need to or not?
Or is it worth re-SHRINKING the database again but with a larger chunk
size (or even no size)? And then rebuilding indexes after this?

Many thanks,
F.

 >> Stay informed about: Problems after running SHRINKFILE 
Back to top
Login to vote
Bob Barrows

External


Since: Oct 27, 2010
Posts: 2



(Msg. 3) Posted: Wed Oct 27, 2010 7:18 am
Post subject: Re: Problems after running SHRINKFILE [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Farmer Nook wrote:
> Hi,
>
> I have major problems after doing a SHRINKFILE on a SQL2K5 database. I
> read all the articles that said that you shouldn't do it unless
> absolutely necessary so was well aware of the risks, but had no choice
> as there was no room on disk for the transaction log to grow, causing
> major headaches with long running transactions.
>
> The problem that I have is that all indexes are badly fragmented but a
> REBUILD and a REORGANIZE is having no effect on them. The index
> fragmentation has gone from 0.x to > 85% in most cases. Batch jobs
> taking 20 minutes now take over 10 hours and performance has hit rock-
> bottom.
>
> When I came in on Monday morning after the SHRINKFILE (over the
> weekend) and checked the index fragmentation it all still looked good
> (0.x% etc). Once the overnight job on Monday evening pushed data into
> the tables, fragmentation went up, but a REBUILD on the major indexes
> seemed to help the job finish in a timely manner. However, Tuesday
> night's batch job has pushed the fragmentation back up again and this
> time, no amount of rebuilding or reorganizing has made any difference.
>
> I've also tried creating new tables and copying the data from a table
> with fragmented indexes into the new tables, then adding indexes
> (before and after) to see if that fixes the problem but strangely
> enough the fragmentation is exactly the same (> 85%) as on the
> original table. Does this make sense?
>
> Has anyone else come across this problem? Or any suggestions on how to
> fix it?
> Any help gratefully received Smile
>
Is itt possible you have the fill factor set incorrectly? i seem to recall
an issue with database maintenance plans where the fill factor setting had
the reverse meaning from the setting in the index creation statement.
 >> Stay informed about: Problems after running SHRINKFILE 
Back to top
Login to vote
Erland Sommarskog2

External


Since: May 30, 2004
Posts: 2061



(Msg. 4) Posted: Thu Oct 28, 2010 12:00 am
Post subject: Re: Problems after running SHRINKFILE [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Farmer Nook ( ) writes:
> I think that the problem may be that the SHRINKFILE was done in 50MB
> chunks to allow us to stop it at any point.
> The previous time that we tried to run it, we ran it without any size
> limit on it. It ran for over 17 hours before we had to kill it and it
> didn't seem to have done much.
> I suspect that it was doing stuff but because it had over 150GB to
> chug through it was always going to take a long time.
> By breaking it up into smaller peices we hoped to have more control
> over it, by being able to see how long each database shrink took and
> by being able to stop it without losing any of the work that had
> already been done. We had no idea what a reasonable chunk would be so
> settled on 50MB. In hindsight, perhaps it would have been better to
> have made the chunks larger. What we suspect has happened is that the
> database is now made of small 50MB chunks (some with data, some with
> no data) that are not allowing all the index rows in a table to reside
> together contiguously. So that no matter how much we rebuild, the
> tables are always trying to slot into 50MB 'holes'. We could be wrong,
> but it would be good if someone with more knowledge could confirm
> whether this would be the case or not?

How big was the database originally?

How much free space was there?

To which size did you eventually shrink it?

Since you mention 150 GB, trying to shrink it 50 MB at a time does
not seem like a good thing. I would set the target size I need, and
which is able to be achieved. Keep in mind that index rebuild needs
space for the new index.

Then again, I can't see that this creates these holes you talk about.
But if you shrink, you need to rebuild all indexes after the shrink.

You don't still have that shrink job running, have you?



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

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
 >> Stay informed about: Problems after running SHRINKFILE 
Back to top
Login to vote
Farmer Nook

External


Since: Oct 27, 2010
Posts: 3



(Msg. 5) Posted: Thu Oct 28, 2010 1:18 am
Post subject: Re: Problems after running SHRINKFILE [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi Erland,

Thanks for the response.

The database was originally 285GB on a 320GB drive with a few other
smaller databases.
At one point, we ended up with less than 5GB on disk for the
transaction log to use.
But could see that there was space in the database that was unused,
due to the removal of some large redundant tables.
We eventually shrunk the database to 200GB. Performing the shrink in
50MB chunks took almost all weekend to get back about 85GB.
The 85GB space that we got back has already gone back down to 60GB
(obviously due to the rebuild of the indexes).
The problem that we had with stating the target size and just going
for it was that the time that we had tried this before the job never
finished and we had to cancel it.
The 'holes' were just a supposition. I'm happy to be proved incorrect
on this.
And no we don't have the job running any more.
I think the main problem was that I didn't realise that I had to
rebuild every single index on every single table.
I was just rebuilding the indexes for a particular job and couldn't
work out why the fragmentation wasn't getting any better.
I now understand that all indexes need to take part in the rebuild and
have started doing that.
Things are improving already, although there is still some way to go.
I am also guessing that even if the job is cancelled part way through,
the work done so far by that SHRINK will remain in place, so the 50MB
limit we used was of little advantage.

So whether we used a 50MB limit and eventually reached the target size
or specified the target size in one go, the end result would have been
the same?

Many thanks,
F.
 >> Stay informed about: Problems after running SHRINKFILE 
Back to top
Login to vote
Erland Sommarskog2

External


Since: May 30, 2004
Posts: 2061



(Msg. 6) Posted: Thu Oct 28, 2010 11:43 pm
Post subject: Re: Problems after running SHRINKFILE [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Farmer Nook ( ) writes:
> So whether we used a 50MB limit and eventually reached the target size
> or specified the target size in one go, the end result would have been
> the same?

I don't know, and I am no going to do any experiments to find out. But
it's possible that doing it many times makes matter worse.

Since the file has grown again, you might have shrunk the file a bit
too much.

But do you really have the transaction log on the same drive? I don't
know what kind of database this is, but 200 GB sounds like it could
be a decently business-critical thing.


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

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
 >> Stay informed about: Problems after running SHRINKFILE 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Log Mgt: Truncate_only --> DBCC ShrinkFile --> Backup Data.. - Hi, I'm doing some tests on an offline version of our SQL Server 2000 production database. Our backups were allowing the log file to increase instead of removing inactive entries so I'm planning to flush out and shrink the log file before re-establishing...

Running Balance in view - I would like to modify my view below to create a running balance of IncomeAmt - ExpenseAmt and wasn't sure if this could be done in a view. I am only getting records for 1 account so I don't think performance will be an issue. Thanks. SELECT..

Error running update - I am a little novice at running queries, so please be patient with me. Windows Server 2000 SQL Server 2005 I am trying this is a test database first. query: UPDATE VEND_addr SET COUNTRY_CD = 'USA', SALES_TAX_CD = 'CA', SHIP_ID = NULL, EMAIL_ID =..

Query running slow - SELECT otherstu0_.STUDENT_DBKEY AS STUDENT1_0_ , otherstu0_.IDENTIFIER_DBKEY AS IDENTIFIER2_0_ FROM OTHER_STUDENT_IDENTIFIER otherstu0_ WHERE otherstu0_.STUDENT_DBKEY IN ( SELECT studentpdo0_.STUDENT_DBKEY FROM STUDENT studentpdo0_ inner join TUTOR..

stored procedures running slow - I am currently working on boosting the performance of a database used to store music information. As it turns out the insertions of tuples into a table storing distances between songs seems to be the worst bottleneck to overcome.. For that reason I..
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]