>A client recently approached me with the question of whether they should shrink their Microsoft Dynamics GP databases to reclaim hard disk space, but instead of telling you what I think, I will demonstrate some of the issues arising from shrinking your databases:
Now to what I think…I have never been a big fan of shrinking databases to reclaim hard disk space — though, if you are running a dev environment where space is critical, then this may only be the one time. The problem arises from the way the shrink process occurs, and applies to DBCC SHRINKFILE, DBCC SHRINKDATABASE and the Auto Shrink setting in the database properties.
In summary, SQL Server goes to the end of a dabatabase file, picks up each individual page, then moves them to the first available empty space in the file. This process may reverse the order of your pages, turning perfectly defragmented indexes into perfectly fragmented ones.
So, let’s take a look with a test database in one of my client’s environments:
1. The first thing we will do is take a look at the stats on the GL00100 table by running the Microsoft SQL Server sys.dm_db_index_physical_stats function:
The following are the results from those stats:
|Original database stats|
Now, in particular, I have highlighted the Average Fragmentation in Percent and the Average Fragment Size in Pages columns. Also, note that I have executed the function in ‘LIMITED’ mode, which combines information from all the columns that form part of each index. So, while these fragmentation levels would indicate low defragmentation rates — which is always desirable — it means there is still room for improvement. So, let’s see what happens after rebuilding the indexes on GL00100 for our test database, then rerunning the stats:
|Stats after rebuilding indexes|
As you can tell now, we have no fragmentation and our page size utilization went up – this is what we would expect after rebuilding indexes. So let’s see what happens when we run the shrink process on the database:
|Stats after DBCC SHRINKDATABASE|
You can now tell that perfectly defragmented indexes now appear fragmented and even to a higher degree than what we started out with. These levels of fragmentation can cause serious performance issues in a production envrionment where database maintenance procedures are not properly planned and executed.
If you must reclaim hard disk space in your Microsoft Dynamics GP environment, please consult with your database administrator, but also keep in mind that storage is dirt cheap.
Until next post!
Mariano Gomez, MVP