Can I ‘Shrink’ My Exchange Database?

KB ID 0001706

Problem

Saw this asked in a forum today, and my response was;

It never gets smaller, if you delete things out of it, it just creates more ‘whitespace’ within the database, unless you;

a) Take it offline, and defragment it using eseutil.
b) Move the mailboxes out of it, to another database and delete it.

Which is true, but even Microsoft say you should not need to defragment a database! Before you do anything make sure you have a good backup of Exchange and the mailbox databases!

Defragment an Exchange Database

Stop! Why are you doing this, if it’s because you are running out of room, then migrating mailboxes out of a database into another database, on another piece of storage with more room is what you should be doing, and does not involve long periods of downtime!

If you have just deleted hundreds of GB from a mailbox database, and you simply want to compress the DB, and you have a BIG window for downtime, (allow 1 hour for every 9GB of database size). Then you are in about the only use case scenario I can think of to want to do this!

Before You start: This process creates a temporary mailbox database, (you need to tell it where), if you are pressed for room, I suggest you add another volume/drive and put it there. (Though in my example I have room in the same folder). Allow for the entire database’s existing size plus ten percent to be on the safe side.

Let’s have a look, and see how  much room we might be able to reclaim (whitespace);

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

The database has to be dismounted before you can run Eseutil on it (downtime starts here).

Dismount –Database Database Name

Eseutil /d C:\Folder\DatabaseName.edb> /t T:\Folder\TempDB.edb>"

When complete, mount the datastore again, (downtime ends here).

Mount-Database Database Name

Mount Exchange Database

Hopefully you should see the whitespace has decreased.

Show whitespace Exchange after eseutil

Don’t forget to set off a full backup of the store as soon at it’s back online.

Move Mailboxes To Another Exchange Database (To Reclaim Space)

This is the much more elegant solution, create a shiny new database move everything  from the old database into the new one, and delete the old database.

Will This Impact My Users? Any user using their mailbox while it is getting moved wont be affected, until the move is complete then they will see a popup that looks like;

Administrator Change Restart Outlook

The Microsoft Exchange administrator has made a change that requires you quit and restart Outlook.

Cool eh! So lets start by creating a New Mailbox Database.

New-MailboxDatabase -Name New Database Name -EdbFilePath C:\Folder\DB-Name.edb -LogFolderPath C:\Folder\Folder\

Exchange Create New Database

Make sure you follow the advice and restart the information store, (yes you can mount the new DB and proceed, but Exchange does not allocate the resources correctly if you do this).

Restart-Service MSExchangeIS

Powershell Restart Information Store

Let’s move our ‘Normal’ mailboxes to the new DB.

Get-Mailbox -Resultsize Unlimited | New-MoveRequest -TargetDatabase Target Database Name

Move All Mailboxes to Another Database

Depending on how many (and how large) mailboxes there are this can take a while, (days for large databases!) When they’ve all completed you need to remove the  move requests, (if you have any failures, or speed issues use the search box above, I’ve had to cope with thousands of these things not working correctly in my time!)

Let’s assume we are all moved, so we want to remove the move requests.

Get-MoveRequest -MoveStatus Completed | Remove-MoveRequest

Remove all move requests

Now let’s see if we have any Arbitration Mailboxes, we do so let’s shift them;

Get-Mailbox -Database Source Database Name -Arbitration

Get-Mailbox -Database Source Database Name -Arbitration | New-MoveRequest -TargetDatabase Target Database Name

Move Arbitration Mailboxes

Again, when complete, remove the move requests.

Get-MoveRequest -MoveStatus Completed | Remove-MoveRequest

Remove Arbitration Mailbox move requests

Now let’s see if we have any Auditlog Mailboxes, we do so let’s shift them;

Get-Mailbox -Database Source Database Name -Auditlog

Get-Mailbox -Database Source Database Name -Auditlog | New-MoveRequest -TargetDatabase Target Database Name

Get-MoveRequest | Get-MoveRequestStatistics

Get-MoveRequest -MoveStatus Completed | Remove-MoveRequest

Move Auditlog Mailboxes

Now let’s see if we have any Archive Mailboxes, we do NOT so I will skip them, let’s check for Monitoring Mailboxes, we have those so let’s move them;

Get-Mailbox -Database Source Database Name -Archive

Get-Mailbox -Database Source Database Name -Monitoring

Get-Mailbox -Database Source Database Name -Monitoring | New-MoveRequest -TargetDatabase Target Database Name

Move Archive and Monitoring Mailboxes

And clean those up as before.

Get-MoveRequest | Get-MoveRequestStatistics

Get-MoveRequest -MoveStatus Completed | Remove-MoveRequest

emove Archive and Monitoring move requests

Finally let’s see if we have any Public Folder Mailboxes, we have one of those so let’s move that;

Get-Mailbox -Database Source Database Name -PublicFolder

Get-Mailbox -Database Source Database Name -PublicFolder | New-MoveRequest -TargetDatabase Target Database Name

Move Public Folder Mailboxes

We now need to remove the ‘Source‘ Database but first we need to dismount it.

Dismount-Database OLD Database Name

Remove-MailboxDatabase -Identity OLD Database Name

Dismount and delete Mailbox Database

I get an error message saying I cant delete the database.

 

Related Articles, References, Credits, or External Links

NA

Author: PeteLong

Share This Post On

Submit a Comment

Your email address will not be published.