Sunday, August 17, 2014

Database Mirroring in SQL Server - Introduction (Part - 2)

In my previous post, I've introduced Database Mirroring with its requirements and operating modes. As said, in this post I'll discuss about the importance and impact of configuring Witness in Mirroring.

Impact of Witness in Database Mirroring


The main job of Witness is monitoring the partners that are participating in Mirroring session. It checks frequently whether both Principal and Mirror are in working state. A single witness can be used to monitor more than one mirroring session.

In High Safety Mode


If a Witness is configured in a Mirroring Session then Quorum is needed. Quorum is a relationship that exists when two or more instances in a Database Mirroring Session are connected to each other. If any instance is not connected then that particular instance loses quorum. If no instance is connected then the whole session loses quorum hence the databases become unavailable.

There are three types of Quorum,

Full Quorum - Consists of both the partners and witness.

Witness to Partner Quorum - Consists of any one partner and Witness.

Partner to Partner Quorum - Consists of only partners.

These quorums are supported in High Safety Mode. When there is a Full Quorum, all the instances act according to their roles until a manual failover is performed.

Suppose Principal is down and loses connection with Witness and Mirror and if Witness and Mirror remain connected then they both form a quorum and an automatic failover occurs. Now Mirror becomes Principal and starts servicing the clients.

Suppose Witness becomes unavailable and steps out of Quorum, the partners remain connected to each other, this is called Partner to Partner Quorum. In this case, a manual failover is possible.

If all the server instances become disconnected from each other, the session is said to have lost quorum. As server instances reconnect to each other, they regain quorum with each other.
  • If the principal server reconnects with either of the other server instances, the database becomes available.
  • If the principal server remains disconnected, but the mirror and witness reconnect to each other, automatic failover cannot occur because data loss might occur. Therefore, the database remains unavailable, until the principal server rejoins the session.
  • When all three server instances have reconnected, full quorum is regained, and the session resumes its regular operation.
To have a detailed explanation of how a Quorum affects database availability, follow the official documentation of Microsoft,


In High Performance Mode


While using High Performance Mode, it is recommended to set the Witness to OFF because a witness can be set in this mode but it serves no purpose. If a witness is configured in this mode, it requires a quorum which should consist of at least two instances connected to each other.

If the witness is disconnected from the quorum when any of the partners goes down then the database becomes unavailable. When mirror goes down, the principal should be connected to witness otherwise the principal's database goes offline until mirror or witness rejoins the session. As said earlier, in this mode only forced failover is possible. When a witness is configured, if principal is down then it requires mirror and witness to be connected to each other to perform a forced failover.

For a detailed explanation of Database Mirroring Operating Modes, read Microsoft's documentation,

http://msdn.microsoft.com/en-us/library/dd207006.aspx

How a Witness performs Automatic Failover


When the partners get disconnected from each other, witness ensures whether one of them is available for the clients. In High Safety Mode, if a Mirror loses the connection with Principal after getting synchronized with it completely but still remains connected with Witness then no failover occurs and Principal keeps on serving its database to clients. In this case, the Principal keeps on accumulating log records that have to be sent to mirror once it joins mirroring session.

If Principal gets disconnected from Witness then Mirror server knows that principal is down and immediately initiates an automatic failover. If mirror is disconnected from principal and witness then no failover occurs and the state of Principal is not considered in this case.

To know more about a Witness, follow the following link,

http://msdn.microsoft.com/en-us/library/ms175191.aspx

No comments:

Post a Comment