SQL Always On Step by Step SQL 2019
SQL Always On Step by Step SQL 2019
com/2022/09/28/sql-always-on-step-by-step/
This article will walk through a basic install and configuration for SQL Always On, to be
leveraged by SCOM for higher availability.
This is no way aligned to Clustering and SQL best practices – just an example on how to set
one up for a simple testing deployment.
First, deploy two Virtual Machines running Windows Server 2022, with the following names:
SQL01
SQL02
I’ll set the Disk Configuration to have the following volumes:
C: 128GB (OS)
D: 128GB (APPS)
G: 200GB (DATA)
L: 100GB (LOGS)
I’ll format the D:, G: and L: volumes with 64k allocation unit sizes, which is optimized for
SQL.
Next I will:
Next I will:
Now I will log on to each server using a domain account that is a SQL Administrator, so I can
Install SQL and configure the Cluster.
Next I will pre-create the Cluster Computer Account in the domain for the Cluster Name
Object (CNO). Normally your Active Directory administrators would do this.
I need to disable the account and assign FULL CONTROL to the user account performing
the cluster installation on the CNO. My CNO will be named “SQLCL01”. My user account
doing the install of SQL and Clustering is OPSMGR\sqladmin.
Then I can create the cluster. Run this ONLY ON ONE OF THE NODES.
# ONLY ON ONE NODE
# Precreate the Virtual Cluster Computer Account (CNO) in the domain and disable computer account
# Assign the user installing the cluster to have FULL CONTROL to Cluster Computer Account in the
domain.
New-Cluster –Name SQLCL01 –StaticAddress 10.10.10.152 –Node SQL01,SQL02
You can open Failover Cluster Administrator and see your new Cluster at this point:
We need to configure a File Share Witness for the cluster. Create a share and a folder for this
cluster. Assign FULL CONTROL rights to the folder, for the CNO:
At this point I will enforce my TLS 1.2 only communications, which is a best practice. This
is not a requirement.
# Disable everything except TLS 1.2
Next – we need to enable Always On for the SQL instance on each node:
$ServerInstance = 'SQL01\INST01' #this should be in format SERVERNAME\INSTANCENAME or just use
servername for default instance
Enable-SqlAlwaysOn -ServerInstance $ServerInstance -Force
Configure SQL Always On Availability Group
Now – we need to configure the Always On availability group.
FIRST – we need to pre-stage a Computer Account in the Domain for the Always On
Availability Group Listener. Once we create this account (SQLAGL01$), we need to assign
FULL CONTROL on this object to the CNO Computer account (SQLCL01$).
This will allow the Cluster to be able to manage the computer account for the AG Listener.
Next – open SQL Management studio from anywhere you have it installed.
Go to Databases, right click, and choose New Database. Name the Database “TESTDB”
and click OK.
Right click the TESTDB database, and choose Properties, then select Options. Make sure
the Recovery Model is FULL. Click OK.
Right click the TESTDB database, and choose Tasks > Backup. Run a FULL backup.
Now expand “Always On High Availability”, and Right Click “Availability Groups” and
choose “New Availability Group Wizard”
Assign an Availability Group name. This isn’t terribly important. I will use “SQLAG01”
then check the box next to “Database Level Health Detection” and click Next.
Check the box next to your Test Database and click Next.
Add a replica, and choose your other server, SQL02. Check the boxes next to Auto failover
and Synchronous commit on both servers.
On the Listener tab, select “Create an availability group listener”. I will use “SQLAG01”
I will use port 1764 (use whatever your standard is).
Choose Static IP and ADD and input your predetermined static IP for your Availability
Group Listener.
Click Next.
Choose Automatic Seeding to automatically sync the database and click Next:
The most common failures are creating the Availability Group Listener. This is almost
always a failure to pre-stage the computer account and apply the rights needed. Please see the
section “To pre-stage an account for a clustered service or application” at: Failover Cluster
Step-by-Step Guide: Configuring Accounts in Active Directory | Microsoft Learn
You will see the availability group on SQL01 switch to Secondary. SQL02 is now the
primary:
Download the MaintenanceSolution.sql from there and then open it in SQL management
studio. Then read the instructions at https://ola.hallengren.com/frequently-asked-
questions.html
In SQL Management Studio – we need to edit this file and configure our settings for file
cleanup time in hours and backup directory:
Defaults:
Then I Execute this file to create all the jobs. Run this on BOTH SQL servers/instances:
Run the “DatabaseBackup – USER_DATABASES – FULL” by right clicking and start job at
step….
And verify the backup was a success:
Repeat this for TLOGS, Index Maintenance, and Output File Cleanup jobs.
In SQL Management Studio, under SQL Server Agent – Right Click “Jobs” and choose
“Manage Schedules”
Daily at 9 PM
Daily at 10 PM
Daily at 11 PM
Hourly
Then schedule each job by opening the job, and Picking an existing schedule – according to
the following:
Repeat the schedule creation and job scheduling on the second node.
Testing connectivity
Lastly – test connectivity to the listener, as all applications connecting to a Database replica in
an AG should use the listener. In my case, my connect string t is
“SQLAGL01.opsmgr.net,1764”
When I install SCOM, I will point the SCOM database setup page to this connect string. I
will still need to go back and set the SCOM database to full recovery model, back it up, and
then add it to the Availability group.