Multiple Subnet AG Groups in SQL Server-Overview
Multiple Subnet AG Groups in SQL Server-Overview
In SQL Server, Always On Availability Groups (AG) provide high availability and disaster recovery solutions.
A common implementation of AGs involves creating multiple availability groups to support different subnets,
typically in a multi-subnet or multi-site deployment. This can be especially useful for geographically distributed
applications where you want to ensure high availability and resilience across data centers.
https://www.sqldbachamps.com
for each subnet.
4. Replicas:
○ SQL Server replicas are instances of SQL Server that host a copy of the databases in the AG.
○ In multi-subnet scenarios, replicas can reside in different subnets, typically in different locations or
data centers.
5. Auto-Failover:
○ One of the benefits of Always On AGs is automatic failover between replicas, which can be
cross-subnet (even across data centers).
○ This failover process requires careful configuration to handle differences in network latency and
ensure that client applications can quickly reconnect to a new primary replica.
To set up a multi-subnet availability group, several steps must be followed. Here’s an outline:
1. Prerequisites
● You first create an Availability Group with multiple replicas. This can be done using SQL Server
Management Studio (SSMS) or via Transact-SQL (T-SQL).
REPLICA ON
● When configuring the replicas, ensure each replica is located in a different subnet.
● Multi-Subnet Listener: For a multi-subnet environment, configure the Availability Group Listener to
https://www.sqldbachamps.com
support multiple subnets. The listener will have a DNS name, but it will be associated with multiple IP
addresses—one for each subnet.
● You need to set up multiple IP addresses for the listener, typically via DNS and SQL Server’s
configuration.
○ Example of listener configuration:
■ Listener DNS name: AGListener.domain.com
■ Listener IP addresses:
■ IP for Subnet 1: 10.0.0.100
■ IP for Subnet 2: 10.1.0.100
● In SQL Server, when creating the availability group listener, you specify these IPs:
PORT = 1433);
https://www.sqldbachamps.com Praveen Madupu +91 98661 30093
Sr SQL Server DBA, Dubai
[email protected]
● DNS and Routing: Configure the DNS records so that the listener resolves to the correct IP based on the
client’s location. This often involves setting up DNS round-robin or geo-DNS to resolve to the appropriate
IP address based on the client’s subnet.
● Health Detection: Ensure that the health detection of the Availability Group is appropriately configured,
especially since network latency and split-brain scenarios can occur across subnets. SQL Server uses
quorum votes from the WSFC (Windows Server Failover Cluster) to make failover decisions.
● Latency and Network Considerations: When you deploy across multiple subnets or data centers,
consider the network latency between the replicas. Higher latency can increase the time required for
failover and impact the performance of synchronous commit mode (if used).
● Quorum Settings: In a multi-subnet configuration, it’s important to set quorum appropriately to avoid
split-brain scenarios. The cluster’s quorum configuration determines how the nodes in the cluster
communicate to make decisions when network connectivity is lost.
● Failover Mode:
○ Automatic Failover: You can configure automatic failover between replicas, but automatic failover
requires that all replicas are synchronous and that the primary replica and its mirrored secondary
replica can communicate reliably.
○ Manual Failover: For multi-subnet environments, you may choose to use manual failover when
https://www.sqldbachamps.com
you want more control over the failover process, especially in cases where network latencies or
transient issues may impact failover behavior.
● Regularly test the failover process to ensure that the application can automatically reconnect to the new
primary replica if the current primary goes down.
● Monitor the AG using Extended Events, SQL Server Management Studio (SSMS), or Dynamic
Management Views (DMVs) to ensure that the replication health is maintained and that failovers occur as
expected.
● Since the replicas are spread across subnets (and possibly different data centers), backup strategies
should be tailored to handle geographical distribution.
● Leverage SQL Server’s Backup to URL or Cloud Storage if necessary for off-site disaster recovery.
https://www.sqldbachamps.com Praveen Madupu +91 98661 30093
Sr SQL Server DBA, Dubai
[email protected]
Example of Monitoring AG Status:
You can use the following DMV to check the status of the Always On Availability Groups:
SELECT
ag.name AS AGName,
ar.replica_server_name AS ReplicaServerName,
ar.availability_mode_desc AS AvailabilityMode,
ar.failover_mode_desc AS FailoverMode,
drs.database_state_desc AS DatabaseState,
drs.synchronization_state_desc AS SyncState
FROM sys.availability_groups ag
https://www.sqldbachamps.com
Summary
Implementing a multi-subnet Always On Availability Group in SQL Server provides high availability and disaster
recovery in geographically dispersed environments.
However, it requires careful network, DNS, and quorum configuration to ensure that failovers are smooth and that
applications can reliably connect to the active replica.
Always consider network latency, DNS resolution, and failover mechanisms to optimize the performance and
reliability of your multi-subnet AG setup.