Note:

Deploy Microsoft SQL Server Always On Availability Groups for HA and DR on OCI

Introduction

The deployment of Microsoft SQL Server is a common use case in Oracle Cloud Infrastructure (OCI). As is often the case in an OCI deployment, customers look for highly resilient architectures that address their business continuity requirements. Therefore, understanding how to deploy SQL Server for high availability and disaster recovery becomes an imperative for these customers.

There are several SQL Server business continuity solutions. The solution discussed in this tutorial is widely adopted by SQL Server administrators Always On availability groups. Solutions like SQL Server Always On Failover Cluster Instances (FCI) can also be deployed on OCI, but are excluded from this tutorial.

This tutorial is inspired by customer use cases and differentiates itself by centralizing three key elements of SQL Server Always On availability groups deployment on OCI in a single document.

Architecture

This tutorial uses the following architecture:

Architecture

Objectives

Create and configure the following:

Prerequisites

Exclusions for this Tutorial

Task 1: Configure the Secondary IPs

For each SQL Server node VM, create the secondary IP needed for the Windows Server Failover Cluster and for the Always On availability groups listener.

  1. In the OCI Console, go to the SQL Server node 1 VM, and select the Attached VNICs in the Resources menu.

    VNIC Selection

  2. Select the primary VNIC and then select IPv4 Addresses in the Resources menu.

    VNIC Details

    VNIC IPv4 Addresses

  3. Select Add Secondary Private IP Address and enter the details for adding a new private IP to the VNIC. Click Create and we will see a new secondary IP associated with this VNIC. This is the WSFC IP.

    VNIC IPv4 Addresses

  4. Repeat steps 1 to 3 in the same VNIC for creating another secondary IP for the Always On availability groups listener.

  5. Repeat steps 1 to 4 for the other SQL Server node VM.

Task 2: Create a SQL Server Service Account

SQL Server needs to use a dedicated domain account. In this task, we will create this account. Later in the tutorial, we use this account to configure the SQL Server service at each of the nodes.

  1. Log in to the Domain Controller using the domain administrator account, and navigate to Active Directory Users and Computers.

    OpenAD

  2. Expand the domain you configured for this tutorial.

    ExpandAD

  3. Right-click on Users and select New User to create a new user.

    New User

  4. Enter the following details and click Next.

    New User Details

  5. Enter the password for this domain account and click Next.

    New User Password

  6. Review the details and click Finish.

    New User Finish

Task 3: Configure a Witness File Share

As mentioned, the architecture in this tutorial uses a file share witness to implement the quorum witness. In this task, we will create a shared folder. In a subsequent task, we will use this shared folder to configure the Windows Server Failover Cluster.

  1. Log in to the Quorum VM using the domain administrator account and create a witness folder.

    Witness Folder Created

  2. Right-click on the folder you created and select Properties. On the Sharing tab, click Share and select Everyone to share the folder. If you prefer to be more strict, select the SQL Server service account created in Task 2.

    Witness Folder Sharing

  3. We will see that the folder has been shared, click Done.

    Witness Folder Shared

Task 4: Configure a Windows Server Failover Cluster

SQL Server Always On availability groups runs on Windows Server Failover Cluster (WSFC) technology. In this task, we will:

Task 4.1: Add WSFC Roles to the SQL Server VMs

  1. Log in to SQL Server node 1 VM using the domain administrator, open Server Manager and on the Dashboard, click Add roles and features.

    WSFC Add roles and features

  2. Click Next to proceed to the Installation Type.

    WSFC Add roles and features

  3. Select Role-based or feature-based installation and click Next.

    WSFC Role-based or feature-based installation

  4. In Select destination server, select the server from the server pool and the SQL Server node 1, and click Next to proceed.

    WSFC Server Selection

  5. In Features, select Failover Clustering. When you do, a window will appear, then click Add Features.

    WSFC Feature Selection

    WSFC Add Features

  6. In Confirm installation selection, review the details and click Install to confirm the installation.

    WSFC Features Installation

  7. When the installation is finished, close the wizard.

    WSFC Features Installation Finished

  8. To confirm the installation, type Failover Cluster Manager on the search bar. You can open it and see it contains no clusters yet.

    WSFC Search and Confirm

    WSFC Ready

  9. Repeat steps 1 to 8 in the other SQL Server node VM.

Task 4.2: Create a Cluster

  1. Log in to the SQL Server node 1 VM using the domain administrator account, and open the Failover Cluster Manager. You will find there are no clusters running.

    WSFC Cluster Creation Start

  2. Right-click on Failover Cluster Manager and select Create Cluster…, this will open a Create Cluster Wizard.

    WSFC Cluster Create

  3. Once the Create Cluster Wizard opens, click Next to proceed.

    WSFC Cluster Create Wizard

  4. Click Browse and select the SQL Server node 1 and SQL Server node 2 VMs.

    WSFC Cluster Create Browse nodes

  5. Confirm that you have selected the appropriate nodes and then click Next.

    WSFC Cluster Create Confirm nodes

  6. Select Yes, When I click Next, run the configuration tests, and then return to the process of creating the cluster and click Next.

    WSFC Cluster Create Run Validation

  7. Select Run all tests and click Next.

    WSFC Cluster Create Run All Tests

  8. In the Confirmation window, click Next.

    WSFC Cluster Create Confirm All Tests

    Wait till all tests are finished.

    WSFC Cluster Create Tests Running

  9. Click Finish.

    WSFC Cluster Create Tests Finished

  10. Enter a Cluster Name and consider the NetBIOS constraints.

    WSFC Cluster Create Name

  11. Confirm the cluster before creating and then click Next.

    WSFC Cluster Create Confirm Settings

  12. When the cluster is successfully created, click Finish.

    WSFC Cluster Create Finish

  13. Open the Failover Cluster Manager and you will be able to see the newly created cluster.

    WSFC Newly Created Cluster

  14. Notice that the status of the cluster is Offline in Cluster Core Resources section. Expand the resources and find the cluster IP addresses not yet configured. We will do it in a few steps from now.

    WSFC Cluster Offline

Task 4.3: Configure a Cluster

  1. Before setting up the cluster IPs, we will configure the quorum witness. Right-click on the cluster name, select More Actions and Configure Cluster Quorum Settings…. This will open up a configuration wizard.

    WSFC Cluster Quorum

  2. In the Configure Cluster Quorum Wizard window, click Next to proceed.

    WSFC Cluster Quorum Start

  3. Select the Select the quorum witness and click Next.

    WSFC Cluster Quorum Configuration Option

  4. Select the Configure a file share witness and click Next.

    WSFC Cluster Quorum Select Witness

  5. Enter the File Share Path configured in Task 3 and click Next.

    WSFC Cluster Quorum File Share Path

  6. Review the quorum configuration settings and click Next.

    WSFC Cluster Quorum Review Settings

  7. The quorum witness will be configured. When the configuration is successfully completed, click Finish to close the wizard.

    WSFC Cluster Quorum Configuration Finish

  8. We will associate the IPs created in Task 1 to the cluster. This will bring the cluster up and make it operational. On the Failover Cluster Manager, expand the Cluster Core Resources and right-click on the IP address with Failed status and then click Properties.

    WSFC Cluster IP Properties

  9. In the General tab, specify the Static IP Address configured for this node in Task 1 and click Apply.

    WSFC Cluster IP Setting

  10. Repeat steps 8 and 9 for the other IP. You will have the cluster properly set up. When the cluster name resource comes online, it updates the domain controller server with a new Active Directory computer object. We are now ready to move on to the Always On availability groups configuration.

    WSFC Cluster IP Setting Finish

Task 5: Configure an Always On Availability Groups for a sample database

In this task, we will:

Task 5.1: Grant permissions to the Cluster Domain Computer Object

  1. Log in to the Domain Controller using the domain administrator account, and open the Active Directory Users and Computers.

    Always On availability groups Open AD

  2. Click View and select Advanced Features to view advanced features.

    Always On availability groups AD View Advanced Features

  3. Right-click on Computers and select Properties.

    Always On availability groups AD Computers Properties

  4. Go to the Security tab and click Add.

    Always On availability groups AD Computers Add

  5. In the Users, Computers, Service Accounts, or Groups wizard, click Object Types….

    Always On availability groups AD Object Types

  6. Select Computers and click OK.

    Always On availability groups AD Computer Object

  7. Enter the name of the cluster and click OK. We will now see the cluster computer object in the list of groups or user names.

    Always On availability groups AD Cluster Object Name

  8. Select the cluster computer object and click Advanced to configure permissions.

    Always On availability groups AD Cluster Computer Object Advanced Settings

  9. On the Permissions tab, select your cluster computer object and click Edit.

    Always On availability groups AD Cluster Computer Object Permissions

  10. Select the Create Computer objects permission entry and click OK.

    Always On availability groups AD Create Computer Objects

  11. We are now back at the Advanced Security Settings for Computers and click Apply and then OK. With this, the computer account of the cluster has the necessary permissions for Always On availability groups to work.

    Always On availability groups AD Back at Advanced Security Settings for Computers

    Always On availability groups AD Back at Computers Properties

Task 5.2: Enable Always On availability groups in the nodes

  1. Log in to the SQL Server node 1 VM using the domain administrator account, and open the SQL Server Configuration Manager.

    Always On availability groups Open SQL Server Configuration Manager

  2. Click SQL Server Services, right-click on the SQL Server (MSSQL SERVER) and select Properties.

    Always On availability groups SQL Server Service Properties

  3. On the Always On Availability Groups tab, select Enable Always On Availability Groups. Notice the name of the cluster already created in Task 4.2, the Windows Server Failover Cluster and click Apply. A warning message to restart the service is displayed. Click OK to apply the changes. The service will be restarted.

    Always On availability groups Checkmark Enable Always On availability groups

  4. If the SQL Server service is not restarted automatically, we can restart it manually, right-click on the SQL Server service and click Restart.

    Always On availability groups Restart Service Message

  5. Right-click on the SQL Server service, select Properties and go to the Log On tab. Select This account and enter the SQL Server account details created in Task 2. Click Apply and then click OK.

    Always On availability groups Service Account Configuration

  6. Repeat steps 1 to 5 for the SQL Server node 2 VM.

Task 5.3: Create and Back up a Sample Database for Always On Availability Groups

  1. Log in to the SQL Server node 1 VM using the domain administrator account, open SQL Server Management Studio and connect to the SQL Server instance in that node.

    Always On availability groups Open SQL Server Mgmt Studio

  2. Select NEW Query and create a sample database using a create database query as shown in the following image.

    Always On availability groups New Query

    Always On availability groups Create Database

  3. Expand Databases on the Object Explorer and we will find the sample database created in the step 2. Right-click on it, click Tasks and then click Backup….

    Always On availability groups Sample Database Backup

  4. Select Full as the Backup Type. Review and confirm the backup destination and click OK.

    Always On availability groups Sample Database Full Backup

  5. We will see a message informing the successful completion of the backup. Click OK.

    Always On availability groups Sample Database Successful Backup

Task 5.4: Create an Availability Groups for the Sample Database

  1. The backup is created, we are ready to start configuring an availability group. Right-click on Always On High Availability and select New Availability Group Wizard….

    Always On availability groups New AG Wizard

  2. In Create a new availability group, click Next to proceed.

    Always On availability groups New AG Wizard Next

  3. Enter an Availability group name, select Windows Server Failover Cluster as the Cluster Type and click Next.

    Always On availability groups New AG Name

  4. Select the sample database created in Task 5.3 and click Next.

    Always On availability groups New AG Select Database

  5. In the Specify Replicas window, click Specify Replicas and Add Replica… to select the node 2 replica. On the window, enter the name of the node 2 server VM, then click Connect.

    Always On availability groups New AG Select Replica

  6. We will now see both replicas, one with the primary role and the other with the secondary role. We can change the availability mode depending on requirements. Click Next and we will notice the Listener tab. For now skip it. We will configure a listener later in this tutorial.

    Always On availability groups New AG Selected Replicas

  7. In Select Data Synchronization, select Automatic seeding and click Next.

    Always On availability groups New AG Automatic Seeding

  8. A validation of the configurations will be run. We can see that all the validation results are successful except the listener configuration. Click Next.

    Always On availability groups New AG Validation

  9. In Summary, click Finish to complete the creation and configuration of the availability group.

    Always On availability groups New AG Finish Configuration

  10. In Results, we will see a message informing you of the successful completion of the availability group configuration. Click Close.

    Always On availability groups New AG Successful Configuration

The availability group is created and we can see its details on the Object Explorer.

Always On availability groups New AG Consult Details

Task 5.5: Create an Availability Group Listener

In this task, we will create a Listener for the availability group created in Task 5.4. The listener is a virtual network name that provides connectivity to the database on an Always On availability groups configuration. It allows a client to connect to a replica without having to know the physical instance name of the SQL Server. Since the listener routes traffic, the client connection string does not need to be modified after a failover occurs.

  1. On the Object Explorer, expand the Availability Groups and the availability group created in Task 5.4 and right-click on Availability Group Listener and select Add Listener….

    Always On availability groups Add Listener

  2. Enter a Listener DNS Name for the Listener, specify port 1433 and Static IP in the Network Mode. Click Add… to add the listener IPs created in Task 1.

    Always On availability groups Listener Name Port

  3. Make sure the subnet of the node you are connected to is the selected subnet and enter the IPv4 Address with the secondary IP created for the listener in Task 1 and click OK.

    Always On availability groups Listener IPs

  4. To add the second IP, click Add… again. Make sure the subnet selected is the subnet of the other node and enter the IP address of the secondary IP created for the other node in Task 1. Click OK.

  5. Confirm that you can see both IPs configured and click OK to finish the listener creation.

    Always On availability groups Configured IPs

  6. Go to the Object Explorer and confirm the listener appears on the Availability Group Listeners folder.

    Always On availability groups Listener on Object Explorer

In SQL Server Management Studio, we can now connect to the listener just as you will to any of the SQL Server nodes. Your Always On availability groups configuration is finished and you have a listener to facilitate application connectivity. Your deployment is now ready for failover, which you can perform manually.

Always On availability groups Listener Connect

Acknowledgments

More Learning Resources

Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.

For product documentation, visit Oracle Help Center.