Q: Is there a way to script Exchange 2010 Database Availability Groups so that mailbox databases automatically fail back to their preferred node?
A: In short, yes.
I’ve been asked whether there is a way to script or automate the failover (or more accurately, switchover) of the mailbox databases in an Exchange 2010 Database Availability Group.
The goal is to always return mailbox databases to their preferred node within the DAG after business hours, when something during the day has caused them to failover to different nodes.
Why would you want to do this? There could be several reasons:
- to balance out the performance of each server by ensuring no one server is handling more databases than others
- to return databases to the most well-connected locations relevant to the user population
- to return databases to the correct DAG nodes for backups to run successfully and in a supported manner
So in order to do this you can use the RedistributeActiveDatabases.ps1 script provided by Microsoft in Exchange 2010 SP1 (and later) to rebalance databases in a DAG. See a demonstration of that script here. All you would need to do is run that script as a scheduled task using an account with the required Exchange administrative privileges.
However, if you have that script running every night as a scheduled task you face the possible situation where rebalancing the DAG is not a desirable outcome.
Consider that databases in a DAG may failover due to server hardware failure, such as a disk or memory within a server. Even though the server is up again, doesn’t necessarily mean that the memory fault is resolved, or that the disk isn’t running in a degraded state.
So how do you prevent an unhealthy server from hosting active mailbox databases if the rebalancing of the DAG is automated?
The solution is to block activation on the unhealthy server. There are two ways you can do this.
The first method is to use Set-MailboxServer with the -DatabasecopyAutoActivationPolicy parameter. For example here is server with an unrestricted activation policy, so it is capable of activating passive databases.
[PS] C:\>Get-MailboxServer HO-EX2010-MB2 | ft name,databasecopy* -auto Name DatabaseCopyAutoActivationPolicy ---- -------------------------------- HO-EX2010-MB2 Unrestricted
By setting the activation policy to “Blocked” the server will not activate any databases when the DAG is rebalanced.
[PS] C:\>Set-MailboxServer ho-ex2010-mb2 -DatabaseCopyAutoActivationPolicy Blocked
The second method is actually the same underlying technique, but adds a few more steps that are worth performing. If a server is unhealthy then it probably shouldn’t be hosting any active databases, so you also want to move any other active databases off the server as well.
You can achieve this by running the StartDagServerMaintenance.ps1, the same script used to manage installation of updates on DAG members.
[PS] C:\>cd $exscripts [PS] C:\...\>.\StartDagServerMaintenance.ps1 ho-ex2010-mb2
Either of those methods will prevent the DAG member from hosting active databases until you’ve had a chance to resolve the server health issue.
[adrotate banner=”49″]
HI,
A useful article. I’m looking at running the RedistributeActiveDatabases.ps1 nightly to ensure my database are on the preferred servers, but am concerned that the preferred server may not be in an optimal state when this script is run.
[Quote]However, if you have that script running every night as a scheduled task you face the possible situation where rebalancing the DAG is not a desirable outcome.[/Quote]
How would I automatically check if the preferred server is in an optimal state before running?
Thanks
Best regards
Interesting article, but what caught my attention was the return to rebalance and clicking, tells me that the page has been found.
If you could send me or share this article would appreciate it you:
https://www.practical365.com/how-to-rebalance-mailbox-databases-in-a-dag-with-exchange-server-2010-sp1
The correct URL is https://www.practical365.com/how-to-rebalance-mailbox-databases-in-exchange-server-dag/ and I’ve fixed up the redirect on that broken URL, thanks.
Pingback: Automate Rebalancing a Database Availability Group | Insiko – WebBlog
Hi Paul,
Thanks for all your efforts you made through your forums…..it is great help and we learned a lot from it
I have some question we have 2 server in DAG my question is as follows
I would like know if in case of failure 1 member of DAG lets say primary does other member become active automatically…..other day i was restarting Exchange information store service of primary mailbox server i found all my outlook clients disconnected it takes less than minute but there is disconnection
i would like to know how the situation if in case of database of server failure
Thanks
Ehsan
Hi Ehsan, I’ve replied to your forums thread.
https://www.practical365.com/forums/exchange-server-2010/1235-exchange-server-2010-sp1-dag.html#post2273
Are there ways to re-distribute mailboxes across a DAG? For example, if i wanted to spread by username(like A-F on database 1, etc.)