Never set “AutoShrink = true”


In my last post, I wrote how you could detect fragmentation and how to fix it.  This post describes a feature that many people in the SQL Server Community hate. This is a single setting under “Database Properties” and might seem to be a pretty good idea for someone who don’t know all the facts, and will sooner or later result in decreased performance. This feature will in worst case totally fragment your database – tables, indexes and even files on the file system level.

You can run the following command to detect which databases that have turned on AutoShrink:

select name, is_auto_shrink_on 
from sys.databases
where is_auto_shrink_on = 1

You can run the following command to turn off AutoShrink for a database:

alter database [MyDB]
set auto_shrink off

The AutoShrink feature fires every 30 minutes by default and it severly fragement the database.  If you use AutoGrowth as well, this can totally fragment the entire database. AutoShrink starts at end of file and brute-force moving the pages as close to the beginning of the file as possible. These pages are physically getting out of order inside the database. If you have a “full rebuild index” the night before and AutoShrink could fragment the database again.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.