Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 autoshrink option in SQL Server 2005

Author  Topic 

mahajanakhil1985
Yak Posting Veteran

71 Posts

Posted - 2010-05-19 : 09:52:55
I was searching through the Net to find the disadvantages of keeping a SQL Server database on autoshrink option but didn't get any satisfactory response.
Are there any performance implications of doing so?

Thanks!!

Kristen
Test

22859 Posts

Posted - 2010-05-19 : 11:13:21
Autoshrink will reduce the size of files, which will immediately grow back to the same size because of normal activity. This repeated Shrink/Grow fragments the files, and the internal SQL logical meta data, and leads to reduced performance.

With regular backups SQL filesize should be "static" (i.e. growing at whatever rate you add data), not growing at an alarming rate.

Schedule TLog backups for every 15 minutes if you use Full Recovery Model (if you only backup the Log once a day, or less, then, Yeah, the Tlog will become huge ...)
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2010-05-19 : 12:50:41
http://blogs.msdn.com/sqlserverstorageengine/archive/2007/03/28/turn-auto-shrink-off.aspx
http://www.sqlskills.com/blogs/paul/2007/11/13/AutoshrinkTurnItOFF.aspx


--
Gail Shaw
SQL Server MVP
Go to Top of Page

mahajanakhil1985
Yak Posting Veteran

71 Posts

Posted - 2010-05-19 : 13:35:45
So, when should be shrink the database/file manually and how do we know how much space is occupied and how much is free?
And how do we know if shrinking the database/file would not cause any harm effect?
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-05-19 : 17:18:49
Manual shrink if you have made an exceptional, one-off, deletion of (say) stale data and it has caused the logs to grow larger than is normally the case.

Or perhaps if you did a one-off bulk import of data (again, which caused the Log file to grow above its normal size).

In such circumstances you should shrink the log file back to its "normal size"
Go to Top of Page

mahajanakhil1985
Yak Posting Veteran

71 Posts

Posted - 2010-05-20 : 07:57:50
@kirsten

Thanks!
This was about the log files. Under what conditions, we should shrink data files? And how can we know if the data file shrink operation will be helpful and that it won't degrade the performance.

I am specifically asking about a database table/view that contains information about space that will be vacated after we issue shrink file command.
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2010-05-20 : 10:00:55
quote:
Originally posted by mahajanakhil1985

Under what conditions, we should shrink data files?


When you've archived or purged large amounts of data and don't expect the free space to be reused in a significant period of time

quote:
And how can we know if the data file shrink operation will be helpful and that it won't degrade the performance.


That's easy. Shrink will never help performance. Will almost always degrade performance due to index fragmentation.

You can use sp_spaceused to see how much free space there is in the database.



--
Gail Shaw
SQL Server MVP
Go to Top of Page

mahajanakhil1985
Yak Posting Veteran

71 Posts

Posted - 2010-05-20 : 12:36:26
Thanks all!!!
Go to Top of Page

mahajanakhil1985
Yak Posting Veteran

71 Posts

Posted - 2010-05-24 : 11:10:05
@GilaMonster

I think sp_spaceused tells us only about unallocated free space in the database and not free space that could be reclaimed after performing shrink of database.

How could I know the free space that may be vacated if we perform DBCC SHRINKDATABASE.
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2010-05-24 : 12:12:49
Yes, it tells about unallocated free space, and that's what shrink file will release if you use it.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

mahajanakhil1985
Yak Posting Veteran

71 Posts

Posted - 2010-05-24 : 13:02:39
Okay. I was mistaken then.

I have a different scenario then.
Suppose lot of deletions have occurred in a table due to which space in data pages got freed. Can we push all remaining rows on one side and free the remaining space?
If yes,
1. how can we predict the space that would be freed before actually shrinking the space?
2. How can we actually free this space?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-24 : 13:04:58
In a scenario like that, you would rebuild the clustered index. Calculating how much space it would free would be dependent upon the size of the rows and number of them.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

mahajanakhil1985
Yak Posting Veteran

71 Posts

Posted - 2010-05-24 : 13:18:58
@tkizer

Could you please let me know one more thing?
Does a data page become added to unallocated space if all rows in that page get deleted?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-24 : 13:25:07
I think so, but I'll let someone else better answer that such as Gail.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

mahajanakhil1985
Yak Posting Veteran

71 Posts

Posted - 2010-05-24 : 13:30:53
@tkizer

If so is the case, then this space should become unallocated and should be shown by sp_spaceused procedure as unallocated. If so, then it should be shrunk by DBCC SHRINKFILE procedure.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-24 : 13:46:44
But did you rebuild the clustered index?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

mahajanakhil1985
Yak Posting Veteran

71 Posts

Posted - 2010-05-24 : 14:33:02
I don't have such a large clustered index to test its effects.
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2010-05-24 : 15:36:35
quote:
Originally posted by mahajanakhil1985

Does a data page become added to unallocated space if all rows in that page get deleted?


Usually, yes. Doesn't necessarily mean it'll happen immediately.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

zstarsales04
Starting Member

20 Posts

Posted - 2010-05-25 : 02:32:39
spam removed
Go to Top of Page

mahajanakhil1985
Yak Posting Veteran

71 Posts

Posted - 2010-05-25 : 04:49:55
@Gail Shaw
quote:
Originally posted by mahajanakhil1985



If so is the case, then this space should become unallocated and should be shown by sp_spaceused procedure as unallocated. If so, then it should be shrunk by DBCC SHRINKFILE procedure.




Above is actually my post. Is it true?
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2010-05-25 : 05:04:28
Pretty much, yes.

Why are you so focused on shrinking? You shouldn't be shrinking a database in general

--
Gail Shaw
SQL Server MVP
Go to Top of Page
    Next Page

- Advertisement -