Summary: Defragmenting Exchange database removes the fragments and arranges data or information in continuous order that helps ensure database health and improve read performance. It also shrinks the database by wiping the 'White Space,' which helps reduce the database size and save the drive storage. In this blog, we have shared the steps to defragment and optimize the Exchange mailbox database using the PowerShell cmdlets.
In Microsoft Exchange Server, the database size increases as more mailboxes are created, and data is generated by the users as they send/receive emails.
When some mail items are deleted from the mailboxes or mailboxes are removed from the Exchange databases, the free storage left by deleted items is not reclaimed.
For instance, if the database size is 10GB and you remove a mailbox ~2GB, the database will remain 10GB. The 2GB space left by the deleted mailbox is called ‘White Space.’
Thus, it’s important and a best practice to reclaim the White Space by defragmenting the Exchange database. It will reduce the database size and help prevent database corruption issues caused by low or no storage.
Why Defrag Exchange Mailbox Database?
Defragmentation is a process of cleaning all unused storage or reclaiming White Space from the database, removing data fragments, and arranging the information in the contiguous regions for quick access.
From the performance point of view, defragmentation (Eseutil /d) makes the database access faster as the Exchange Server would not have to process a large file in memory or open and search the file, which can incur a large number of input/output from the storage for nothing.
Another thing is the operation of the server. As you may know, Exchange Server is sensitive about the database’s health if there is no storage or a shortage.
Databases tend to fill the hard drive with unused space or log files. If the storage is not increased or logs are not purged, it can damage the database and lead to corruption. As a result, the Exchange database will dismount, breaking the client-server connectivity and preventing the users from sending or receiving emails
So, it would be wise to set a schedule to check the database state periodically, depending on the size and number of users. A corrupted database can cause loss of data, service, and business.
Things to Remember Before Defragging Exchange Mailbox Database using Eseutil /d
Before running Eseutil /d command to defragment the Exchange database, ensure the following:
- To defrag an Exchange Server database, the database must be dismounted. Unfortunately, this means that the users will be unable to access their mailboxes during this operation.
- Exchange database defragmentation should be executed only after office hours as it might take some time to finish (depending on the database size and the server/storage).
- It is highly recommended to back up the database before defragmentation for those just-in-case scenarios.
- Ensure the drive where the database is stored has enough free storage space, which is equivalent to or larger than the database size (preferably 1.1x or 1.2x size of the database). If you are short on storage capacity, this could cause a problem.
To calculate the required space, you must check the database size in your Exchange Server that requires defragmentation. To do so, you can use the Get-MailboxDatabase PowerShell cmdlet, as given below.
Get-MailboxDatabase -Status | ft name, database size, availablenewmailboxspace –auto
The output will display the database Name, the DatabaseSize, and the AvailableNewMailboxSpace.
As you can see from the above example, the Mailbox Database 0954395982 has a size of 247.9 MB.
On the other hand, it also has 74.34 MB of White Space. Of course, this is a small database with a few mailboxes. But on larger databases, defrag (Eseutil /d) will make significant performance improvements on the disks and operation of the server.
You can use the following formulae to calculate the total free space required to defragment the Exchange mailbox database.
- (DatabaseSize) – (AvailableNewMailboxSpace) = (Actual Database Size).
- (Actual Database Size) X 1.1= (Space required for defragmentation).
250MB – 75MB = 175MB
175MB X 1.1 = 192.5MB —is the minimum free space required to defrag the Exchange mailbox database.
NOTE: We have rounded off 247.9MB as 250MB in the above calculations.
Steps to Defrag Exchange Mailbox Database using Eseutil /d cmdlet
To defragment and optimize an Exchange mailbox database, follow these steps:
Step 1: Launch the Exchange Management Shell (EMS).
Step 2: Go to the folder location where the database that needs defragmentation is located using the cd command. For instance,
cd "C:\Program Files\Microsoft\Exchange Server\V15\Mailbox\Mailbox Database 0954395982"
Step 3: Run the following command to dismount the Exchange mailbox database.
Dismount-Database <database name>
Step 4: Once the database is dismounted, use the below EseUtil command to start the defragmentation process.
Eseutil /d "Mailbox Database 0954395982.edb" /t "temp_0954395982.edb"
Step 5: After the defragmentation (which may take time depending on the performance of the server/storage and the size of the database), mount the database back by using the Mount-Database PowerShell cmdlet.
Mount-Database "Mailbox Database 0954395982"
Step 6: After mounting the database and testing the connectivity of the affected users, you can test how the database has been defragmented by rechecking the database size using the Get-MaiboxDatabase PowerShell cmdlet.
Get-MailboxDatabase -Status | ft name, databasesize, availablenewmailboxspace -auto
Here you can see that the database has shrunk from 247.9 MB to 56 MB in size with only 512KB of White Space.
To Conclude
All goes well with the defrag operation if you have not incurred any issues or encountered an error message during the operation. However, there are several factors that may corrupt the database before and during the defrag (Eseutil /d) process. For example, if you have not calculated the free or left enough space for the process to run, this could lead to low or full storage that will halt the server and corrupt the database.
In such situations, for any Exchange Administrator, a third-party Exchange recovery tool such as Stellar Repair for Exchange comes in handy to save the database when a disaster strikes. With Stellar Repair for Exchange, you can repair any corrupt or damaged Exchange Database of any version and recover data to PST or other formats. With this software, you can also directly export the mailboxes from the repaired Exchange database to a live database in your Exchange Server and an Office 365 tenant.