Exchange: optimize database space


Exchange 2013 Exchange 2016 Exchange 2019 Exchange Online

In this tutorial, I will explain how to optimize the disk space used by the databases (MailboxDatabase) of Exchange.

What you need to know is that the size of Exchange databases only increases and over time, “empty” spaces are created in the database files. Empty space is normally reused to store other data.

Despite this reuse, it happens that the loss of space is significant and therefore I will explain how to recover disk space.

There are several solutions, some require a service stop, because you have to dismantle the database, interrupting Exchange is not always easy, or even impossible, so I will explain how to do it without service stop.

The first step before embarking on this manipulation is to see the space you can potentially recover.

From a PowerShell (EMS) window, enter the command below:

Get-MailboxDatabase -Status | Select Name, DatabaseSize, AvailableNewMailboxSpace

This command will return the size of the database files as well as the “empty” space.

On the capture above, we can see that the B100 base is 130 GB and that there is 100 GB of space available. In the database, there are only 30 GB of data and 100 GB of empty space.

We will therefore see how to recover this empty space.

In fact, we will not be able to recover the empty space of the database as we would for a SQL Server database with a simple right on the database.

The only way to recover empty space without service interruption is to move all mailboxes to a new database.

The first step will be to create a new database and configure it with the same parameters (limits) and high availability as the source database.

Once the database is ready, move the database mailboxes:

Get-Mailbox -Database "SRC_MXDB" -ResultSize Unlimited | New-MoveRequest -TargetDatabase "NEW_MXDB"

Wait while moving mailboxes.

It is possible to follow the progress with the cmdlet:

Get-MoveRequest

Once the moved mailboxes clean up the move requests:

Get-MoveRequest -MoveStatus Completed | Remove-MoveRequest

If the database contains other types of mailboxes (Arbitration, Archive …), move them too.

# Vérifier les autres types de boites :
Get-Mailbox -Database SRC_MXDB Name -Arbitration
Get-Mailbox -Database SRC_MXDB Name -Archive
Get-Mailbox -Database SRC_MXDB Name -Auditlog
Get-Mailbox -Database SRC_MXDB Name -Monitoring

# Deplacer les boites aux lettres
Get-Mailbox -Database SRC_MXDB Name -Arbitration | New-MoveRequest -TargetDatabase "NEW_MXDB" 
Get-Mailbox -Database SRC_MXDB Name -Archive | New-MoveRequest -TargetDatabase "NEW_MXDB"
Get-Mailbox -Database SRC_MXDB Name -Auditlog | New-MoveRequest -TargetDatabase "NEW_MXDB"
Get-Mailbox -Database SRC_MXDB Name -Monitoring | New-MoveRequest -TargetDatabase "NEW_MXDB"
Get-Mailbox -Database SRC_MXDB Name -PublicFolder| New-MoveRequest -TargetDatabase "NEW_MXDB"

Once all the mailboxes have been moved, you can delete the old database.




Leave a Comment