When you first deploy an Exchange Server 2016 database availability group, or any time later when you add a new member to the DAG, there will be some steps required to manage the database copies within the DAG.
As an example, I’ve created a new Exchange 2016 DAG with two members. Before they were added to the DAG the server EX2016SRV1 hosted one database named DB05, and EX2016SRV2 hosted one database named DB06. I’ve then created an additional two databases on EX2016SRV1 named DB07 and DB08. At present the databases have a single copy within the DAG, which looks like this.
To view this in PowerShell we can run the Get-MailboxDatabaseCopyStatus cmdlet.
[PS] C:\>Get-MailboxDatabaseCopyStatus * | sort name | ft -auto Name Status CopyQueueLength ReplayQueueLength LastInspectedLogTime ContentIndexState ---- ------ --------------- ----------------- -------------------- ----------------- DB05\EX2016SRV1 Mounted 0 0 Healthy DB06\EX2016SRV2 Mounted 0 0 Healthy DB07\EX2016SRV1 Mounted 0 0 Crawling DB08\EX2016SRV1 Mounted 0 0 Crawling
In this article I will demonstrate how to:
- Add database copies to a DAG member
- Remove database copies from a DAG member
- Balance active database copies across a DAG
Adding Database Copies to an Exchange Server 2016 DAG Member
The objective in this scenario is to add database copies so that each database has two copies for high availability, one on each DAG member. To achieve this we use the Add-MailboxDatabaseCopy cmdlet. For example, this command will add a copy of DB06 (currently hosted on EX2016SRV2) to the DAG member EX2016SRV1.
[PS] C:\>Add-MailboxDatabaseCopy -Identity DB06 -MailboxServer EX2016SRV1
Adding the new database copy will automatically start the seeding process (copying the database and log files to the new server) and begin the continuous replication process. The new database copy will automatically be configured with the next available activation preference for copies of that database (which I’ll explain later in the section about balancing database copies across a DAG).
The seeding time will depend on the amount of data that needs to be copied and the network bandwidth that is available. The seeding will occur from the database copy that is currently active. If you’re seeding across a slower WAN connection and there is already another passive copy in that datacenter that would be faster to seed from because it is closer, you can modify the command shown above to postpone seeding.
[PS] C:\>Add-MailboxDatabaseCopy -Identity DB06 -MailboxServer EX2016SRV1 -SeedingPostponed
Then, manually start the seeding process using Update-MailboxDatabaseCopy and specify which DAG member to seed from.
[PS] C:\>Update-MailboxDatabaseCopy -Identity DB06\EX2016SRV1 -SourceServer EX2016SRV2
You can repeat the commands above to add copies of multiple databases to a new server, however that gets a bit tedious. Instead, we can use PowerShell to add multiple database copies in a single command. For example, here is the list of database copies on EX2016SRV1.
[PS] C:\>Get-MailboxDatabaseCopyStatus -Server EX2016SRV1 Name Status CopyQueue ReplayQueue Length Length ---- ------ --------- ----------- DB05\EX2016SRV1 Mounted 0 0 DB06\EX2016SRV1 Healthy 0 0 DB07\EX2016SRV1 Mounted 0 0 DB08\EX2016SRV1 Mounted 0 0
We know that DB05, DB07, and DB08 are yet to be added to EX2016SRV2. One way to show only the databases in the DAG that are yet to be added to EX2016SRV2 is as follows.
[PS] C:\>Get-MailboxDatabase | Where {$_.MasterServerOrAvailabilityGroup -eq "EX2016DAG01" -and $_.Servers -notcontains "EX2016SRV2"} Name Server Recovery ReplicationType ---- ------ -------- --------------- DB05 EX2016SRV1 False None DB07 EX2016SRV1 False None DB08 EX2016SRV1 False None
So we can simply pipe that into Add-MailboxDatabaseCopy to add copies to EX2016SRV2.
[PS] C:\>Get-MailboxDatabase | Where {$_.MasterServerOrAvailabilityGroup -eq "EX2016DAG01" -and $_.Servers -notcontains "EX2016SRV2"} | Add-MailboxDatabaseCopy -MailboxServer EX2016SRV2
Run Get-MailboxDatabaseCopyStatus to see the results.
[PS] C:\>Get-MailboxDatabaseCopyStatus * | sort name Name Status CopyQueue ReplayQueue Length Length ---- ------ --------- ----------- DB05\EX2016SRV1 Mounted 0 0 DB05\EX2016SRV2 Healthy 0 0 DB06\EX2016SRV1 Healthy 0 0 DB06\EX2016SRV2 Mounted 0 0 DB07\EX2016SRV1 Mounted 0 0 DB07\EX2016SRV2 Healthy 0 0 DB08\EX2016SRV1 Mounted 0 0 DB08\EX2016SRV2 Healthy 0 0
Removing Database Copies from an Exchange Server 2016 DAG Member
When you are planning to decommission a DAG member you will need to remove all of the database copies from the server before it can be removed from the DAG member list. To remove database copies we use the Remove-MailboxDatabaseCopy.
For example, to remove the copy of DB05 from the DAG member EX2013SRV2 we run this command.
[PS] C:\>Remove-MailboxDatabaseCopy DB05\EX2016SRV2 Confirm Are you sure you want to perform this action? Removing database copy for database "DB05" on server "EX2016SRV2". [Y] Yes [A] Yes to All [N] No [L] No to All [?] Help (default is "Y"): y
To remove all of the database copies from a DAG member without being prompted for confirmation use the following command.
[PS] C:\>Get-MailboxDatabaseCopyStatus -Server EX2016SRV2 | Remove-MailboxDatabaseCopy -Confirm:$false
If you try to remove a database copy that is currently active it will fail with an error message similar to this.
The database “DB06” is currently hosted on server “EX2016SRV2”. Use Move-ActiveMailboxDatabase to move the active copy of the database to a different server. You can use the Remove-MailboxDatabase task if this is the only copy.
If you were doing this as part of a server decommission you would simply move the active database copy to another server, then re-run Remove-MailboxDatabaseCopy.
Balancing Active Database Copies for an Exchange Server 2016 DAG
The first copy of a database in a DAG is configured with an activation preference of 1. As you add new copies of that database the copies are configured with activation preference values in order. So the second copy is AP=2, the third is AP=3, and so on. Activation preference and the impact is can have on DAG operations is explained in more detail in my article Why Did My Database Failover to the Wrong Server?
Depending on how you first built your DAG you may have an unbalanced distribution of activation preferences across your database copies. For example in my DAG this is the current layout of the AP values. When all active database copies are the AP=1 copy the DAG will generally function just fine, but the storage IOPS will not be even and it’s possible that some operations such as an unplanned failover may take longer.
We can balance our activation preferences using some PowerShell scripts, which I’ve previously written about in my article on PowerShell Scripts for Balancing Database Availability Groups. Following the guidance in that article I can run the following command to balance my AP distribution.
[PS] C:\>cd $exscripts [PS] C:\Program Files\Microsoft\Exchange Server\V15\scripts>.\RedistributeActiveDatabases.ps1 -DagName ex2016dag01 -BalanceActivationPreferences
With the AP values more evenly distributed, but now it means some of my active database copies are not the most preferred copy. This in itself is not a problem, but as mentioned earlier a balanced DAG has benefits.
I can rebalance the active database copies with this command.
[PS] C:\Program Files\Microsoft\Exchange Server\V15\scripts>.\RedistributeActiveDatabases.ps1 -DagName ex2016dag01 -BalanceDbsByActivationPreference -Confirm:$false
Summary
In this tutorial I’ve demonstrated how to add and remove database copies from Exchange Server 2016 database availability group members. I’ve also demonstrated the concept of activation preference, and how to balance activation preferences across your DAG members.
This article Managing Database Copies for an Exchange Server 2016 Database Availability Group is © 2015 ExchangeServerPro.com
Get more Exchange Server tips at ExchangeServerPro.com