Monitoring and Scheduling Exchange 2007 Database Online Maintenance

To keep the Exchange database healthy, it is important to make sure that online maintenance and online maintenance and online defragmentation are running properly, or are at least conforming to Microsoft's recommendations. Ben shows how easy it is to automate the maintenance and monitor the defragmentation task.

Exchange database maintenance is an important part of keeping Exchange healthy. Exchange Server automates online maintenance tasks and runs them based on the schedule specified by the Exchange administrator.

The online maintenance tasks are:

  • Purge mailbox database and public folder database indexes
  • Maintain tombstones
  • Clean up the deleted items dumpster
  • Remove public folders that have exceeded the expiry time
  • Remove deleted public folders that have exceeded the tombstone lifetime
  • Clean up conflicting public folder messages
  • Update server versions
  • Check Schedule+ Free Busy and Offline Address Book folders
  • Clean up deleted mailboxes
  • Clean up reliable event tables

For detailed information on these tasks you can refer to Microsoft TechNet: Maintaining Mailbox Databases and Public Folder Databases

If one of these maintenance tasks is performed on a database then online defragmentation will be performed on that database.

If the online maintenance tasks are unable to complete in a single schedule window the tasks will be suspended and then resumed in the next window. In this way maintenance is guaranteed to eventually complete, however it is important to make sure that the scheduled maintenance windows are properly configured so that the maintenance tasks are able to complete regularly.

When scheduling online maintenance there are several guidelines to consider:

  • Online maintenance should be scheduled for times when there is little activity on the database.
  • Online maintenance must not run at the same time as a backup (online defragmentation cannot start while a backup is in progress).
  • Online defragmentation should be able to complete at least once every two weeks.
  • Online maintenance schedules for databases in the same storage group should not overlap (Microsoft recommends a 15 minute gap between maintenance schedules).

The default online maintenance schedule is nightly from 1am to 5am. To aid in customizing the online maintenance schedule, the Windows event log can be used to see how often online defragmentation is completing and Performance Monitor counters can be used to check the efficiency of online defragmentation. This data can be used to adjust the online maintenance schedule to give more or less time.

Event Log Entries for Online Defragmentation

There are five events relating to online defragmentation starting and stopping. The events are logged in the Application log with a source of ‘ESE’ and a category of ‘Online Defragmentation’.

787-BenLye_1.jpg

Events 701 and 703 indicate a complete pass. In the case of event 703, completion of a resumed pass, the event text will include information about how long defragmentation took to complete, and how many times it was invoked.

787-BenLye_2.jpg

To make it easier to check how often online maintenance completes the Exchange Management Console and a PowerShell script can be used to parse the Application log.

This script will search the event log for online defragmentation messages for each database on the server on which it’s run (or the clustered mailbox server if running on a cluster node) and return the amount of time taken to complete online defragmentation of each database.

Microsoft recommends that in large organisations with large databases (150 – 200GB) and many storage groups (up to 20) on a single server online defragmentation should complete at least once every two weeks for each database. In smaller organizations with smaller databases it should complete more often.

In either case, if online defragmentation is completing within two days then it is probably safe to shorten the online maintenance window for the database. If defragmentation is not completing within 14 days the online maintenance window should be lengthened.

Performance Monitor Counters for Online Defragmentation

Exchange 2007 includes the following performance counters for monitoring online defragmentation:

  • MSExchange Database ==> Instances\Online Defrag Average Log Bytes
  • MSExchange Database ==> Instances \Online Defrag Log Records/sec
  • MSExchange Database ==> Instances \Online Defrag Pages Dirtied/sec
  • MSExchange Database ==> Instances \Online Defrag Pages Preread/sec
  • MSExchange Database ==> Instances \Online Defrag Pages Read/sec
  • MSExchange Database ==> Instances \Online Defrag Pages Re-Dirtied/sec
  • MSExchange Database ==> Instances \Online Defrag Pages Referenced/sec

Exchange 2007 Service Pack 1 adds these two additional counters

  • MSExchange Database ==> Instances \Online Defrag Pages Freed/Sec
  • MSExchange Database ==> Instances \Online Defrag Data Moves/Sec

The two interesting counters are ‘Online Defrag Pages Read/sec’ and ‘Online Defrag Pages Freed/Sec’. These two counters can be monitored during an online maintenance window and the average values compared to determine if the window should be increased or decreased.

If the ratio of Pages Read:Pages Freed is greater than 100:1 then the online maintenance window can be decreased, if the ratio is less than 50:1 then the maintenance window should be increased, and if the ratio is between 100:1 and 50:1 there is no need to change the window.

To use these counters extended ESE performance counters must be enabled, which is done by adding a new registry value.

Note: Incorrectly editing the registry can cause serious problems that may require you to reinstall your operating system. Problems resulting from editing the registry incorrectly may not be able to be resolved. Before editing the registry, back up any valuable data.

  1. Start the registry editor on your Exchange 2007 Mailbox server.

  2. Locate the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ESE\Performance registry key.

  3. Right-click Performance, select “New”, and then select “DWORD value”.

  4. Name the new DWORD value “Show Advanced Counters”.

  5. Double-click “Show Advanced Counters”.

  6. In the “Value data” field, enter 1.

  7. Close the registry editor.

Once the extended ESE performance counters are enabled Performance Monitor can be used to log the counter data to a file.

  1. Start Performance Monitor on the Exchange 2007 mailbox server (or the active cluster node in a CCR cluster) by clicking Start -> Programs -> Administrative Tools -> Performance.

  2. Expand “Performance Logs and Alerts” and select “Counter Logs”.

  3. Right-click “Counter Logs” and select “New log settings”.

  4. Enter a name for the new counter, such as “EDB Defrag”, and click “OK”.

787-BenLye_3.jpg

  1. Click the “Add Counters” button, and then select “MS Exchange Database ==> Instances” from the “Performance object” drop-down.

  2. Select the “Online Defrag Pages Freed/sec” and the “Online Defrag Pages Read/sec” counters from the list, select the Information Store storage groups, and click the “Add” button.

787-BenLye_4.jpg

  1. Click “Close”

  2. On the “Log Files” tab change the “Log file type” to “Text File (Comma delimited)” and uncheck “End file names with”.

787-BenLye_5.jpg

  1. On the schedule tab se the start time to a few minutes before the start of the next run of online maintenance and the end time to a few minutes after the end.

787-BenLye_6.jpg

  1. Click “OK” and then close Performance Monitor.

The next time online maintenance runs the performance counter data will be gathered. This data can then be analyzed by looking at the average ratio of pages read to pages freed.

The resulting CSV file will look similar to this:

787-BenLye_7.jpg

To determine the Pages Read:Pages Freed ratio the data is averaged over the duration of the maintenance window, and the average Pages Read/sec is divided by the average Pages Freed/sec. This gives the number of pages freed/sec for every one page read/sec.

For example, if the average Pages Read/sec is 545, and the average Pages Freed/Sec 6, the ratio is 90:1 and the online defragmentation window is appropriately set.

Setting the Online Maintenance Window

The online maintenance window is configured per database and can be set using either the Exchange Management Console or the Exchange Management Shell.

To configure the maintenance window using the console:

  1. Launch the Exchange Management Console.

  2. Expand “Server Configuration” and select the “Mailbox” node.

  3. Select the server where the database is located then select the database.

  4. Right-click the database and select “Properties”.

  5. Select a predefined schedule from the “Maintenance Schedule” list or to create a custom schedule, select “Use Custom Schedule”, and then click “Customize”.

  6. Click OK to close the properties window.

Alternatively, use the Set-MailboxDatabase PowerShell cmdlet to set the maintenance window. This command will configure the maintenance window of the database “Mailbox Database” on server SERVER01 to run every day from 3am to 4am local time using the shell:

With a relatively small amount of monitoring and analysis it is reasonably easy to ensure that online maintenance is running effectively and efficiently, helping to ensure that your Exchange databases stay in good shape.

The techniques I’ve shown here should help you to check that online maintenance and online defragmentation are running optimally, or are at least conforming to Microsoft’s recommendations.