Imagine the following situation: your server runs out of disk space, so you decide to move a few mailboxes away from the database, and purge unneeded data from the database. You would expect the available disk space to increase, but this is not what happens. Exchange databases are designed not to shrink. When data is deleted from them, they leave white spaces behind, that will be used by new mailboxes and new items.
It is possible to release that white space though, to gain back free disk space. To do that, the database needs to be dismounted, so you can defragment it with ESEUTIL.
In our example we have database DB01 with a huge white space:
PS C:\> Get-MailboxDatabase DB01 -Status | fl databasesize, availablenewmailboxspace DatabaseSize : 14.38 GB (15,435,038,720 bytes) AvailableNewMailboxSpace : 10.08 GB (10,819,371,008 bytes)

To reclaim that space, we do the following:
1. Dismount the Database
Ideally on the server that hosts the database run the following:
PS C:\> Dismount-Database DB01 -Confirm:$false
2. Defragment the database
Check where the EDB file is stored
PS C:\> Get-MailboxDatabase DB01 | fl EdbFilePath EdbFilePath : C:\ExchangeDatabases\DB01\db\DB01.edb
Now, Defragment the EDB database file using ESEUTIL
C:\>eseutil /d C:\ExchangeDatabases\DB01\db\DB01.edb Extensible Storage Engine Utilities for Microsoft(R) Exchange Server Version 15.02 Copyright (C) Microsoft Corporation. All Rights Reserved. Initiating DEFRAGMENTATION mode... Database: C:\ExchangeDatabases\DB01\db\DB01.edb Defragmentation Status (% complete) 0 10 20 30 40 50 60 70 80 90 100 |----|----|----|----|----|----|----|----|----|----| ................................................... Moving '.\TEMPDFRG4504.EDB' to 'C:\ExchangeDatabases\DB01\db\DB01.edb'... DONE! Moving '.\TEMPDFRG4504.jfm' to 'C:\ExchangeDatabases\DB01\db\DB01.jfm'... DONE! Note: It is recommended that you immediately perform a full backup of this database. If you restore a backup made before the defragmentation, the database will be rolled back to the state it was in at the time of that backup. Operation completed successfully in 66.172 seconds. C:\>
3. Mount the database
You are ready to mount the database again
PS C:\> Mount-Database DB01
4. Verify the EDB file size
And lastly verify that the database has shrunk indeed as expected.

Comments