Monday, 28 December 2015

Exchange 2016 - Balance Active Mailbox Databases


When you’ve had a failover and your mailbox databases are now not on your preferred servers, it can take a bit of time to work out which server each database should be mounted on and then move the active copy if you have a large number of mailbox servers and databases. This is where the RedistributeActiveDatabases.ps1 script comes in handy.
For more information on Exchange 2016 Database Availailability Group setup, see here.

Lab setup

In this lab, I have two Exchange 2016 mailbox servers configured in a Database Availabliity Group:

  • LITEX01
  • LITEX02

There are four mailbox databases:

  • MDB01
  • MDB02
  • MDB03
  • MDB04

Each mailbox database has a copy on LITEX01 and LITEX02.

Activation Preference

On each mailbox database, there is an ActivePreference property. This lists all the mailbox servers that host a copy of the mailbox database and for each mailbox server it includes a number. Mailbox servers with lower numbers are preferred over other servers when it comes to selecting a server to mount the database on in case of a failover.

This is handy when you have a multi-site DAG (with a production and disaster recovery site) and you’d prefer to have your mailbox databases fail over to a mailbox server in the production site in preference to the DR site where users would need to connect to it across the WAN.

To find out the ActivationPreference property for our mailbox databases, we run the command:

Get-MailboxDatabase | sort Name | fl Name,ActivationPreference


From the ActivationPreference property, we see that the preferred mailbox database copy for MDB01 and MDB02 is on LITEX01 and the preferred mailbox database copy for MDB03 and MDB04 is on LITEX02.

Mailbox database copy status

To find out where our maibox databases are mounted, we can use the Get-MailboxDatabaseCopyStatus cmdlet against each of our mailbox servers:

Get-MailboxDatabaseCopyStatus -Server litex01


Get-MailboxDatabaseCopyStatus -Server litex02


Here we can see that all the mailbox databases are mounted on LITEX02 which, in my case, was the result of a mailbox server failover.

Re-distribute mailbox databases

The RedistributeActiveDatabases.ps1 script allows us to re-balance the mailbox servers by distributing the mailbox databases. You can either balance databases in two different ways:

  • BalanceDbsByActivationPreference - this moves the databases to the server that is marked as the most preferred copy (based on ActivationPreference)
  • BalanceDbsBySiteAndActivationPreference - this balances databases to their most preferred copy but also tries to balance the databases between the AD sites (useful for multi-site DAGs where both sites have active users)

In our case, we only have two servers in one AD site so we’ll use BalanceDbsByActivationPreference. The script is located in “C:\Program Files\Microsoft\Exchange Server\V15\scripts” by default so we first need to change directory. We can use this neat shortcut to do this:

cd $exscripts


Now we’ll run our script to balance the databases according to ActivationPreference and then output the results using the -ShowFinalDatabaseDistribution switch:

.\RedistributeActiveDatabases.ps1 -BalanceDbsByActivationPreference -ShowFinalDatabaseDistribution


In the first part of the output, under the heading “Starting Server Distribution”, we can see that the script has worked out that we have 4 mailbox databases and that they’re all mounted on LITEX02.

Under the heading “Starting Database Moves”, the script then moves MDB01 and MDB02 to LITEX01 as it has worked out that LITEX02 has an ActivationPreference (AP) of 2 and LITEX01 has an AP of 1 for these mailbox databases. We’re prompted to confirm each move unless we use the -Confirm:$false parameter.

Once the databases are moved, we can see an output stating that there are two active and two passive databases on each mailbox server.


In the next part of the output, we can see a summary of the moves where it states each server and the AP of the copy that is active at the start and finish of the script. We can see that MDB01 and MDB02 were activated on LITEX01 and MDB03 and MDB04 were not moved. 


In this post, I've demonstrated how to balance your mailbox databases among your Exchange 2016 mailbox servers. 

No comments:

Post a comment