May 28, 2013

Defrag a database in Exchange 2010

At some point after moving mailboxes around your exchange organization, it is recommended practice (as from our Exchange 2003 days) to defragment your databases to free up any white space and to shrink your database size as it approaches its max size.
Luckily the procedure to defrag a mailbox database, still uses a tool called eseutil.

When planning to defrag, the thing to consider is that users with mailboxes on that database will not be able to send receive email during the time the database is being defragmented. Choose to perform a defrag outside of production hours. You can either move the mailboxes to another database if email downtime is not an option.

Pre-Check step:
Browse to the folder of where your Database is installed on your exchange server (default is
C:\Program Files\Microsoft\Exchange Server\V14\Mailbox\Mailbox Database <random number>). Check the following files are present before defragmentation:

<mailbox name>.edb - database file
E00.log - a log file that is currently in use by the database engine
E00.chk -  checkpoint file, contains information between the database file and the log files
E00000003A.log, E00000003B.log, E00000003C.log… - log files.
E00tmp.log - a log file that is currently being written

These steps are for a database that are not part of a DAG. 

The general steps are:
1: Check the status of the database file size

 [PS] Get-MailboxDatabase -Status | ft name,databasesize,availablenewmailboxspace -auto

2: Move mailboxes from database to a new empty Database. You can move these mailboxes from Exchange Management Console.

3: Dismount database (DB01 for example):

 [PS] Dismount-Database DB01

4: Perform offline defrag on dismounted database. (Eseutil /d [database name])
In Powershell window, browse to the folder location of your database. (Typical location is C:\Program Files\Microsoft\Exchange Server\V14\Mailbox\Mailbox Database <random number>)

First navigate to the folder containing the Database (eg: MB01) in powershell
eg):  cd C:\Program Files\Microsoft\Exchange Server\V14\Mailbox\MB01

Then defrag database 
eg): Eseutil /D [Database Name]

 [PS] C:\Program Files\Microsoft\Exchange Server\V14\Mailbox\MB01>eseutil /D MB01.edb

5: Mount Database (DB01 for example):

 [PS] Mount-Database DB01

6:Check space availability:

 [PS] Get-MailboxDatabase -Status | ft name,databasesize,availablenewmailboxspace -auto

7: Move mailboxes back to original database using the Exchange Management Console.

NB: The /D switch used with eseutil is for defragmentation. Below are a list of other switches that can be used with eseutil. Be aware that eseutil is a powerful tool and care and caution is needed when using this tool.

  • ESEUTIL /D – Used for offline defragmentation of a Database
  • ESEUTIL /R – Used for recovery purposes of a Database
  • ESEUTIL /g – Performs an integrity check  of a Database
  • ESEUTIL /k – Performs a checksum test of a Database
  • ESEUTIL /p – Repairs a Database when it’s corrupt (and beyond recovery)
  • ESEUTIL /m – can dump header information of a Database and Log Files
  • ESEUTIL /y – can copy large files like Mailbox Database files efficiently
  • ESEUTIL /c – Is used to ‘hard recover’ a database during an online backup

No comments:

Post a Comment