Basic Always On Availability Groups in SQL Server Standard
Basic Always On Availability Groups in SQL Server Standard
liv790 Menu
Introduction
In this walkthrough, we will be setting up a Basic Availability Group in SQL Server
Standard edition as a base for HA. This is a group of SQL servers that work
together to ensure high availability of applications and services. Any HA platform
in SQL Server runs in WSFC (albeit for FCI or AG).
Acronym Description
HA High Availability
AG Availability Groups
Maximums:
Nodes 2 9
Of which:
• Primary 1 1
• Read-only Secondary 0 2
Replicas
• Synchronised Secondary 1 3
Replicas with Automatic
Failover
• Synchronised Secondary 1 5
Replicas with Manual
Failover
• Asynchronous Secondary 1 5
Replicas with Manual /
Forced Failover
This functionality therefore ensures that a copy of the current primary is always
available, with the following caveats:
• For Synchronised Sencondary replicas, the more replicas in the group, the
longer it will take to �nalise each entry (incrementally higher latency), i.e. all
secondaries in the chain need to have hardened their logs before the primary
records the transaction as successful. Therefore:
◦ Location is important, the closer to the primary the better.
Limitations
• Limit of two replicas (primary and secondary). Basic Availability Groups for
SQL Server on Linux support an additional con�guration only replica.
• No support for replicas hosted on servers running a version of SQL Server prior
to SQL Server 2016 Community Technology Preview 3 (CTP3).
• Basic availability groups are only supported for Standard Edition servers.
• You may have multiple Basic availability groups connected to a single instance
of SQL Server.
• Both nodes have the same version and edition of SQL server installed, with the
same level of patching.
• WSFC has been set up and is correctly con�gured, and both nodes are
members thereof.
▪ File Server
• A popup noti�cation will appear to state that the changes will be applied but
will only take effect after the service is restarted. Click on OK.
Right Click on the SQL Server instance and select Restart. The Stopping and
starting pane will brie�y appear
Endpoints:
Backup Preference:
Listener:
We are going with Join only, as a backup and restore was done on the secondary.
This will take us to the validation page:
Summary:
We can check that the Virtual Network Node for the listener has been created in
the domain:
• ◦ AG Dashboard:
• ◦ AD Dashboard:
• On Active Directory:
◦ Computers:
Here is the entire script applied, at each server as highlighted, to activate BADR:
BEGIN
ALTER EVENT SESSION [AlwaysOn_health] ON SERVER STATE=START;
END
GO
:Connect DBSERV02
IF (SELECT state FROM sys.endpoints WHERE name = N'Hadr_endpoint') <> 0
BEGIN
ALTER ENDPOINT [Hadr_endpoint] STATE = STARTED
END
GO
use [master]
GO
GRANT CONNECT ON ENDPOINT::[Hadr_endpoint] TO [MyDomain\SQLService]
GO
:Connect DBSERV02
IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name='AlwaysOn_health'
BEGIN
ALTER EVENT SESSION [AlwaysOn_health] ON SERVER WITH (STARTUP_STATE=ON
END
IF NOT EXISTS(SELECT * FROM sys.dm_xe_sessions WHERE name='AlwaysOn_health'
BEGIN
ALTER EVENT SESSION [AlwaysOn_health] ON SERVER STATE=START;
END
GO
:Connect DBSERV01
USE [master]
GO
CREATE AVAILABILITY GROUP [HR_AG]
WITH (AUTOMATED_BACKUP_PREFERENCE = PRIMARY,
BASIC,
DB_FAILOVER = ON,
DTC_SUPPORT = NONE,
REQUIRED_SYNCHRONIZED_SECONDARIES_TO_COMMIT = 0)
FOR DATABASE
if (serverproperty('IsHadrEnabled') = 1)
and (isnull((select member_state from master.sys.dm_hadr_cluster_members
and (isnull((select state from master.sys.database_mirroring_endpoints
begin
select @group_id = ags.group_id from master.sys.availability_groups
select @replica_id = replicas.replica_id from master.sys.availability_replicas
while @conn <> 1 and @count > 0
begin
set @conn = isnull((select connected_state from master.sys.dm_hadr_availabili
if @conn = 1
begin
-- exit loop when the replica is connected, or if the query cannot find t
break
end
waitfor delay '00:00:10'
set @count = @count - 1
end
end
end try
begin catch
-- If the wait loop fails, do not stop execution of the alter database statement
end catch
ALTER DATABASE