Reporting Database Whitespace for All Exchange Servers

Thursday, September 9, 2010
The physical size of an Exchange database normally grows as data is added to it.  When data is removed the amount of data is reduced, but the physical database size (the amount of space taken up on the disk) does not shrink.  This empty space in the database file is called whitespace.

For example, if you move half of the mailboxes from DB01 to DB02, DB01 will remain the same physical size on the disk, but half of it will be whitespace.  Normally this is not a big deal, but it might be important to you if you need to reclaim that unused disk space.  Also, some backup software backs up the entire database, including whitespace.  That means you might be wasting backup tapes and time backing up empty data.

Exchange has always reported the database whitespace in the Application event log as Event ID 1221 during scheduled online maintenance, as shown below:


However with Exchange 2010 and its 24x7 ESE scanning, this event is no longer logged since online database maintenance runs all the time by default.  You can view the amount of whitespace in any given database using the following cmdlet in the Exchange Managment Shell:
Get-MailboxDatabase Database1 -Status | FT Name,AvailableNewMailboxSpace
The output looks like this:
 
 
Unfortunately, this cmdlet doesn't work on previous versions of Exchange, so I leveraged some code by Shay Levy to write a Powershell script that collects the data from the 1221 events on each server in the Org and exports it to a CSV file.
 
Click here to download the Get-ExchangeWhitespace script.
 
The script must be run from the Exchange Management Shell (EMS).  It creates a collection of all the Exchange servers (except Edge Transport servers) from AD, and connects to each server's Application log using WMI.  It then collects the data from the 1221 events from the previous day's online maintenance schedule and exports it to a file called 'Exchange Whitespace.csv'.  Despite all these steps, it's really fast to execute.

If you want to reclaim the whitespace in a database, you need to perform an offline defrag.  You will dismount the database and run the Eseutil /D command, as detailed here.  Be aware that this can take quite a long time and you need sufficient free space on the volume to run it.

6 comments:

  1. That PowerShell comamnd doesn't report all the whitespace. This only reports the whitespace at the root of the B-Tree structure.

    Another FYI is that the transport database still uses 1221.

    There are some performance counters to view some of this information.

    More on all the above here:
    I blogged a lot about this here:
    http://www.shudnow.net/2009/10/25/exchange-2010-24x7-online-defragmentation-and-online-database-scanning/

    ReplyDelete
  2. Thanks, Elan, that's a great post! However, my understanding is that 1221 has been replaced with event 7007. There are no 1221 events on any of the Exchange 2010 servers I've checked.

    ReplyDelete
  3. Interesting. I created my post when Exchange 2010 RTM was in the TAP but NDA was released so that may have been removed as well. I posted to the TAP alias and asked where 1221's for mailbox databases which is where I learned of its departure but 1221 for transport databases at that time were most definitely still there at that time.

    I didn't know about any 7007. I'll have to check that out on my server.

    Thanks!

    ReplyDelete
  4. It's now 18 months since you were going to "check that on your server". Event ID's 1221 don't exist on an Exchange 2010 Mailbox server. Why not take down the miss-information you're posting here?

    ReplyDelete
  5. Great work!!! you saved my day...

    ReplyDelete
  6. Thx a lot for this. I modified this command and I got a also a nice list but there is MB and GB mixed and I want to have all in MB. I tried another script I use for checking mailboxsizes but then I don't get amounts displayed. The command was:

    Get-MailboxDatabase MMEVM* -Status | Select-Object name,databasesize, @{Name="AvailableNewMailboxSpaceMB";Expression={$_.AvailableNewMailboxSpace.Value.ToMB()}}

    I get 3 rows with Name of the DBs, the total size, and the whitespace but under whitespace the amounts are missing! How can I solve this?

    Oh it's a Exchange 2010 Server.

    Thanks!
    T.Kraft

    ReplyDelete

Thank you for your comment! It is my hope that you find the information here useful. Let others know if this post helped you out, or if you have a comment or further information.