Wednesday, March 6, 2024
0 comments

Configuring Always-On High Availability Groups on SQL Server

3:37 PM



 



In this article, we’ll walk you through a step-by-step guide on how to install and configure Always On Availability Groups on SQL Server running on Windows Server 2019, discuss failover scenarios, and some other related topics.

Always On Availability Groups provide high availability in MIcrosoft SQL Server. Always On appeared in MSSQL 2012 release.


Features of Always On Availability Groups in SQL Server

What can you use SQL Server availability groups for?

  • MS SQL high availability and automatic failover;
  • Load balancing of SELECT queries between nodes (secondary replicas may be readable);
  • Backup from secondary replicas;
  • Data redundancy. Each replica keeps copies of the availability group database.

Always On is based on Windows Server Failover Cluster (WSFC). WSFC monitors availability group nodes and provides automatic failover. Starting from MS SQL Server 2017, Always On may be used without WSFC and in Linux hosts as well. When building a Linux-based cluster, you can use Pacemaker instead of WSFC.

Always On is available in the Standard edition, but it has some restrictions:

  • It is limited to 2 replicas (primary and secondary);
  • The secondary replica cannot be used to read data;
  • The secondary replica cannot be used to backup MS SQL;
  • Only 1 database per availability group is supported.

There are no restrictions in the Enterprise edition.
Let’s consider the terms.

  • Always On Availability Group is a set of replicas and databases;
  • Replica is an SQL Server instance in the availability group. A replica may be primary or secondary. Each replica may contain one or more databases.

Always On is based on WSFC. Each availability group node must be a member of a Windows failover cluster. Each SQL Server instance can have multiple availability groups. Each availability group may have up to 8 secondary replicas.

If a primary replica fails, the cluster will vote for a new primary replica, and Always On will make one of the secondary replicas a primary one. Since users connect to the Listener (a special cluster IP address and the corresponding DNS name) when working with Always On, it will become possible to run write queries again. The Listener is also responsible for balancing SELECT queries between secondary replicas.


Configure Windows Failover Cluster for Always On Availability Group

First of all, we must configure a failover cluster on all nodes used by Always On.

Here is my configuration:

  • 2 virtual machines running Windows Server 2019
  • 2 SQL Server 2019 Enterprise instances
  • Node hostnames are testnode1 and testnode2. The SQL Server instance names are node1 and node2.

Add the Failover Clustering role using the Server Manager

install the Failover Clustering role on Windows Server 2019

The installation is automatic, and you don’t need to configure anything yet. Run the Failover Cluster Manager snap-in (FailoverClusters.SnapInHelper.msc) and create a new cluster.

create failover cluster

Add the names of the hosts that you want to join to your cluster.

Then the wizard offers to take some tests. To do it, select the first item.

validate windows failover cluster

Specify the cluster name, select a network, and a cluster IP address. The cluster name will appear in DNS automatically; you don’t need to create a DNS record manually. In my case, the cluster name is ClusterAG.

set cluster name and ip address

Uncheck the options Add all eligible storage to the cluster since we can add disks later.

don't add all eligible storage to the cluster

There are only two nodes in the cluster, so you must configure Cluster Quorum. The Cluster Quorum is a casting vote. For example, if one of the cluster nodes becomes unavailable, the cluster must detect, which nodes are actually online and can see each other. The Cluster Quorum provides cluster consistency (Cluster -> More Actions -> Configure Cluster Quorum Settings).

Configure Cluster Quorum Settings

Select the quorum witness option.

enable quorum witness

Then select the witness type: a file share witness.

enable a a file share witness

Specify a UNC path to the shared folder. Create the directory yourself. It must be present on a server outside your failover cluster.

set file share witness UNC path

When you configure your cluster, you may see the following error:

There was an error configuring the file share witness. Unable to save property changes for File Share Witness. The system cannot find the file specified.

It is likely that a user account, under which the cluster is running, doesn’t have NTFS permissions to access the shared folder. By default, the cluster is running under a local user account. You can grant privileges on the folder to all cluster computers or change the account for the cluster service and grant it the relevant privileges.

The basic Windows Failover Cluster configuration is over.

Configuring Always On Availability Group on MS SQL Server

After the typical SQL Server instance installation, you can enable and configure Always On Availability Groups. Enable them in the instance properties of SQL Server Configuration Manager. As you can see in the screenshot, SQL Server has already detected that it belongs to a WSFC cluster. Check Enable Always On Availability Groups and restart the MSSQL instance service. Do the same for the second instance.


0 comments:

 
Toggle Footer