Table of Contents hide

1. Introduction to SQL Server Always On

1.1 What is SQL Server Always On?

SQL Server Always On is Microsoft’s comprehensive high availability and disaster recovery solution introduced with SQL Server 2012. It represents a significant advancement over previous technologies like database mirroring and log shipping, ensuring continuous access to data while minimizing downtime and data loss.

1.2 Why Businesses Need Always On Solutions

In today’s digital economy, database downtime directly translates to lost revenue, damaged reputation, and regulatory compliance issues. Organizations require high availability solutions that can guarantee near-continuous uptime while protecting against various failure scenarios.

Traditional backup and restore procedures are insufficient for modern business requirements. When a critical database fails, businesses cannot afford the hours required to restore from backups. Always On solutions provide automated failover that can restore service in seconds or minutes rather than hours, dramatically reducing the impact of system failures.

Beyond basic availability, businesses need to offload read-intensive workloads from production databases, perform maintenance without downtime, and protect against site-level disasters. SQL Server Always On addresses all these requirements through a unified architecture that scales from small deployments to globally distributed systems.

Infographic showing why businesses need SQL Server always on solutions.

1.3 Always On Terminology and Key Concepts

Understanding SQL Server Always On requires familiarity with several fundamental concepts that define how high availability and disaster recovery solutions are measured and implemented.

1.3.1 Recovery Time Objective and Recovery Point Objective

Recovery Time Objective (RTO) defines the maximum acceptable duration of downtime following a failure. It represents the time between when a failure occurs and when normal operations resume. For example, an RTO of 5 minutes means the database must be available again within 5 minutes of a failure. RTO directly impacts business operations and customer experience.

Recovery Point Objective (RPO) defines the maximum acceptable amount of data loss measured in time. It represents the age of the most recent data that must be recoverable following a failure. An RPO of zero means no data loss is acceptable, while an RPO of 15 minutes means losing up to 15 minutes of recent transactions is acceptable. RPO requirements drive decisions about synchronization modes and backup strategies.

Different availability modes in SQL Server Always On provide different RTO and RPO characteristics. Synchronous commit mode provides zero data loss (RPO = 0) with automatic failover capabilities for minimal RTO, while asynchronous commit mode accepts potential data loss in exchange for lower impact on primary database performance.

Infographic of Recovery Time Objective (RTO) and Recovery Point Objective (RPO) in SQL Server Always On

1.3.2 High Availability vs. Disaster Recovery

High Availability  (HA) focuses on minimizing downtime caused by routine failures such as hardware malfunctions, software crashes, or planned maintenance. An HA solution typically keeps systems running within the same data center using redundant components and automatic failover mechanisms. The goal is to achieve the highest possible uptime, often measured in “nines” of availability.

Disaster Recovery (DR) addresses catastrophic events that affect entire data centers, such as natural disasters, power outages, or large-scale infrastructure failures. DR solutions maintain copies of data at geographically separate locations, enabling business continuity when the primary site becomes unavailable. While HA focuses on minimizing downtime, DR focuses on ensuring data protection and business continuity during major incidents.

SQL Server Always On supports both HA and DR scenarios within a single unified architecture, allowing organizations to configure replicas for local high availability and additional replicas for remote disaster recovery.

Infographic of High Availability (HA) and Disaster Recovery (DR) in SQL Server Always On

2. Understanding SQL Server Always On Technologies

SQL Server Always On consists of two main technologies: Always On Failover Cluster Instances (FCI) and Always On Availability Groups (AG). This guide will introduce both, but focus on Always On Availability Groups, the more widely adopted solution for database-level high availability.

Infographic of the comparison of two main SQL Server Always On technologies.

2.1 Always On Failover Cluster Instances

Always On Failover Cluster Instances (FCI) provides instance-level high availability using shared storage accessible by all nodes in a Windows Server Failover Cluster. When a SQL Server instance fails on one node, the cluster automatically restarts it on another node using the same shared storage, ensuring continuity at the instance level.

While FCI provides solid instance-level failover, it does not offer readable secondary replicas, flexible geographic distribution, or database-level granularity. These limitations make Always On Availability Groups the preferred solution for most modern high availability requirements.

2.2 Always On Availability Groups

Always On Availability Group (AG) is a container for a set of user databases that fail over together as a single unit. Unlike instance-level solutions, AG operate at the database level, allowing different databases on the same SQL Server instance to participate in different AG with different failover policies.

Each AG consists of a primary replica that hosts read-write databases and one to eight secondary replicas that maintain synchronized copies. The primary replica sends transaction log records to secondary replicas, which apply these changes to maintain database consistency. This architecture enables automatic failover, manual failover, and read-scale scenarios.

3. Always On Availability Groups Architecture

3.1 Core Components and Concepts

3.1.1 Availability Databases

Availability databases are the user databases that participate in an availability group. These databases must meet specific requirements: they must use the full recovery model, have a full backup, and exist on the primary replica before being added to an availability group.

When a database joins an availability group, it becomes part of a synchronized set that fails over as a unit. All databases in an availability group share the same failover state, meaning if the primary replica fails, all databases fail over to the same secondary replica simultaneously. This ensures consistency for applications that rely on multiple related databases.

3.1.2 Availability Replicas

Availability replicas are SQL Server instances that host copies of availability databases. Each replica maintains its own physical copy of the databases, synchronized through transaction log record shipping. An availability group can contain up to nine replicas: one primary replica and up to eight secondary replicas.

3.1.3 Primary Replica

The primary replica hosts the read-write copy of the availability databases. All data modifications (INSERT, UPDATE, DELETE) occur on the primary replica. Client applications connect to the primary replica for all write operations and, by default, for read operations as well.

3.1.4 Secondary Replicas

Secondary replicas host read-only copies of the availability databases, maintained through continuous application of transaction log records received from the primary replica. Each secondary replica receives, hardens, and applies log records to keep its database copies synchronized with the primary.

Infographic of core components and concepts of SQL Server always on availability groups

3.2 Availability Modes

3.2.1 Synchronous-Commit Mode

Synchronous-commit mode provides zero data loss protection by requiring the primary replica to wait for confirmation that transaction log records have been hardened on the secondary replica before committing transactions. This mode is essential for high availability configurations where data loss is unacceptable.

3.2.2 Asynchronous-Commit Mode

Asynchronous-commit mode prioritizes primary replica performance by allowing transactions to commit without waiting for secondary replicas to acknowledge log hardening. This mode is appropriate for disaster recovery replicas or when network latency makes synchronous commit impractical.

The trade-off is potential data loss during failover. If the primary replica fails, some committed transactions may not have reached the secondary replica. The amount of potential data loss depends on network bandwidth, secondary replica performance, and the timing of the failure. Organizations must accept this risk when using asynchronous mode.

Infographic of SQL Server always on availability modes, including synchronous-commit mode and asynchronous-commit mode.

3.3 Failover Types

3.3.1 Automatic Failover

Automatic failover enables the availability group to detect primary replica failure and automatically promote a secondary replica to primary without administrator intervention. This capability minimizes RTO by eliminating the need for manual response to failures.

Automatic failover requires synchronous-commit mode to ensure zero data loss. When enabled, the availability group continuously monitors the health of the primary replica. If the primary becomes unresponsive or fails, the Windows Server Failover Cluster initiates automatic failover to a designated secondary replica.

3.3.2 Manual Failover

Manual failover allows administrators to intentionally switch the primary replica role to a secondary replica, typically for planned maintenance or testing purposes. Unlike automatic failover, manual failover requires explicit administrator action to initiate.

Manual failover without data loss is available for synchronous-commit replicas. The administrator initiates the failover through SQL Server Management Studio, Transact-SQL, or PowerShell. The primary replica finishes processing current transactions, sends all remaining log records to the target secondary, and waits for confirmation before transferring the primary role.

Manual failover can also occur with asynchronous-commit replicas, but this requires forced failover with potential data loss. Administrators should use forced manual failover only during actual disaster scenarios when the primary replica is unavailable and data loss is acceptable compared to extended downtime.

3.3.3 Forced Failover

Forced failover allows failover to an asynchronous secondary replica or to a secondary that is not fully synchronized, with the explicit acknowledgment of potential data loss. This option serves as a last resort when the primary replica is unavailable and no synchronized secondary exists.

Infographic of SQL Server always on failover types, including automatic failover, manual failover and forced failover.

3.4 Data Synchronization

3.4.1 How Data Synchronization Works

Data synchronization in Always On Availability Groups occurs through continuous transaction log record shipping from the primary replica to all secondary replicas. This log-based synchronization ensures consistency while allowing independent storage for each replica.

3.4.2 Transaction Log Records and Hardening

Transaction log hardening is the critical step where log records are written to durable storage on secondary replicas. Hardening ensures that log records survive secondary replica failures and can be replayed during recovery.

Infographic of SQL Server always on data synchronization process.

3.5 Read-Scale and Readable Secondary Replicas

3.5.1 Offloading Read-Only Workloads

Readable secondary replicas enable organizations to offload read-intensive workloads from the primary replica, improving overall system performance and resource utilization. This read-scale capability is one of the key advantages of availability groups over older high availability solutions.

Organizations should consider read-only workload requirements when designing availability group configurations. Multiple readable secondaries can distribute reporting load across several servers. Read-only routing lists define the order in which secondaries receive read-intent connections, enabling load balancing strategies.

3.5.2 Backup Operations on Secondary Replicas

Running backups on secondary replicas reduces the I/O and CPU load on the primary replica, allowing it to focus on transactional workloads. This capability helps organizations meet backup requirements without impacting production performance.

SQL Server supports full database backups, differential backups, and transaction log backups on secondary replicas. Backup preferences can be configured to prefer secondary replicas, prefer primary, secondary only, or any replica. The backup system automatically selects an appropriate replica based on these preferences and current availability.

For more details on SQL Server backup, see our comprehensive guide.

Infographic of read-scale and readable secondary replicas in SQL Server Always On

3.6 Availability Group Listeners

3.6.1 What is a Listener?

An availability group listener is a virtual network name (VNN) and IP address that client applications use to connect to availability group databases. The listener automatically redirects connections to the current primary replica, eliminating the need for applications to track which server is currently primary.

3.6.2 Client Connection Routing

Client connection routing through the listener supports both read-write and read-only connection intents. The listener examines the connection request and routes it to the appropriate replica based on the application’s intent.

Infographic of SQL Server always on availability group listeners.

4. Prerequisites and Requirements

4.1 Windows Server Failover Clustering for Availability Groups

4.1.1 Windows Server Failover Clustering Fundamentals

Windows Server Failover Clustering (WSFC) provides the foundation for Always On Availability Groups by managing cluster membership, health monitoring, and failover orchestration. Unlike Failover Cluster Instances, availability groups use WSFC only for cluster coordination, not for shared storage management.

Each SQL Server instance participating in an availability group must be a node in a WSFC cluster. The cluster manages quorum voting, node health detection, and availability group resource state. When the primary replica fails, WSFC coordinates the failover process and updates cluster resources to reflect the new primary replica.

Infographic of Windows Server Failover Clustering (WSFC) fundamentals for SQL Server Always On Availability Groups

4.1.2 Cluster Quorum Configuration

Cluster quorum determines which nodes can operate when network connectivity issues occur, preventing split-brain scenarios where multiple nodes independently claim to be primary. The quorum configuration defines what constitutes a majority vote for cluster decisions.

Several quorum modes are available for availability groups:

  • Node Majority uses only cluster node votes and works well for clusters with an odd number of nodes.
  • Node and File Share Majority adds a file share witness vote, suitable for even-numbered node clusters.
  • Node and Disk Majority uses a disk witness but is less common for availability groups since shared storage is not required.

Infographic of Cluster Quorum Configuration for SQL Server Always On Availability Groups

4.1.3 Multi-Subnet Clustering

Multi-subnet clustering enables availability group replicas to span different network subnets, supporting geographically distributed deployments across data centers. This capability is essential for disaster recovery configurations where replicas exist in separate locations.

Infographic of Multi-Subnet Clustering in SQL Server Always On Availability Groups

4.2 SQL Server Edition Requirements

4.2.1 Enterprise Edition Features

SQL Server Enterprise Edition provides full availability groups functionality without limitations. Enterprise edition supports up to eight secondary replicas, readable secondaries, automatic seeding, distributed availability groups, and all advanced features.

4.2.2 Standard Edition Features (Basic Availability Groups)

SQL Server 2016 Standard edition and later support Basic Availability Groups with significant limitations. Basic availability groups provide core high availability functionality at a lower cost, suitable for organizations with simpler requirements.

5. Configuring Always On Availability Groups

5.1 Preparing the Environment

Before creating an availability group, the environment must be properly prepared with Active Directory accounts, server configurations, and network infrastructure in place.

5.1.1 Domain Controller Setup

The Active Directory domain controller must be configured to support the availability group cluster and SQL Server service accounts.

  1. Log into the domain controller with domain administrator credentials.
  2. Open Server Manager and navigate to Tools -> Active Directory Users and Computers.
  3. Create an organizational unit for SQL Server objects if one does not exist.
  4. Verify that computer objects for all cluster nodes exist in Active Directory.
  5. Ensure DNS services are properly configured and all server names resolve correctly.

Set active directory domain controller in Active Directory Users and Computers.

5.1.2 Creating Service Accounts

Create dedicated Active Directory service accounts for SQL Server services on each node.

  1. Open Active Directory Users and Computers on the domain controller.
  2. Right-click the appropriate organizational unit and select New -> User.
  3. Enter the service account name (for example, svc_SQLServer) and set the User logon name.
  4. Click Next and enter a strong password.
  5. Select User cannot change password and Password never expires.
  6. Click Next and then Finish to create the account.
  7. Repeat for any additional service accounts needed (SQL Server Agent, SSRS, etc.).

Create new active directory user account.

5.1.3 Configuring Administrator Permissions

Service accounts and the accounts used to configure SQL Server must have appropriate permissions on all cluster nodes.

  1. Log into each cluster node server.
  2. Open Computer Management from the Start menu or Server Manager.
  3. Expand Local Users and Groups and select Groups.
  4. Right-click Administrators and select Properties.
  5. Click Add and enter the service account name.
  6. Click Check Names to validate the account, then click OK.
  7. Click OK to close the Administrators Properties dialog.
  8. Repeat on all cluster nodes.

Configure the administrator permissions for the new active directory user account.

5.2 Installing and Configuring WSFC

Windows Server Failover Clustering must be installed and configured on all nodes before enabling Always On Availability Groups.

5.2.1 Installing Failover Clustering Feature

Install the Failover Clustering feature on each server that will participate in the availability group.

  1. Open Server Manager on the first cluster node.
  2. Click Manage -> Add Roles and Features.
  3. Click Next through the introduction screens.
  4. Select Role-based or feature-based installation and click Next.
  5. Select the local server and click Next.
  6. Skip the Roles screen and click Next.
  7. On the Features screen, select Failover Clustering.
  8. Click Add Features when prompted to include management tools.
  9. Click Next and then Install.
  10. Wait for installation to complete and click Close.
  11. Repeat on all servers that will participate in the cluster.

Install Failover Clustering for SQL Server Always On

5.2.2 Creating the Failover Cluster

After installing the Failover Clustering feature on all nodes, create the cluster from one node.

  1. Open Failover Cluster Manager from Server Manager -> Tools.
  2. Click Create Cluster in the Actions pane.
  3. Click Next on the Before You Begin page.
  4. Click Browse and add all servers that will be cluster nodes.
  5. Click Next after adding all nodes.
  6. Leave Run all tests (recommended) selected and click Next.
  7. Review validation test results and address any errors or warnings.
  8. Click Finish after validation completes successfully.
  9. Enter a name for the cluster and IP address.
  10. Uncheck Add all eligible storage to the cluster as shared storage is not required.
  11. Click Next and review the confirmation.
  12. Click Finish to create the cluster.

Create the Failover Cluster in the Failover Cluster Manager.

5.2.3 Validating the Cluster Configuration

Validate the cluster configuration to ensure all nodes can communicate properly and the cluster operates correctly.

  1. In Failover Cluster Manager, right-click the cluster name.
  2. Select Validate Cluster from the menu.
  3. Click Next on the Before You Begin page.
  4. Select Run all tests (recommended) and click Next.
  5. Click Next to begin validation tests.
  6. Review the validation report when tests complete.
  7. Address any failures or warnings identified in the report.
  8. Click Finish to close the wizard.

Validate the Failover Cluster in the Failover Cluster Manager.

5.3 Installing SQL Server for Availability Groups

Install SQL Server on each node that will participate in the availability group using the standalone installation option.

  1. Run the SQL Server installation media on the first node.
  2. Select New SQL Server stand-alone installation.
  3. Enter the product key or select the evaluation edition.
  4. Accept the license terms and click Next.
  5. Complete prerequisite checks and address any issues.
  6. On the Feature Selection page, select Database Engine Services.
  7. Configure instance name (use the same instance name on all nodes).
  8. On the Server Configuration page, specify the service account credentials.
  9. Configure service startup types as Automatic.
  10. On the Database Engine Configuration page, select authentication mode.
  11. Add administrator accounts.
  12. Configure data directories using consistent paths across all nodes.
  13. Complete the installation and verify success.
  14. Repeat installation on all other cluster nodes with identical settings.

New SQL Server stand-alone installation

5.4 Enabling Always On Availability Groups Feature

After installing SQL Server on all nodes, enable the Always On Availability Groups feature on each instance.

5.4.1 Enabling via SQL Server Configuration Manager

Use SQL Server Configuration Manager to enable Always On Availability Groups through the graphical interface.

  1. Open SQL Server Configuration Manager on the first node.
  2. Expand SQL Server Services in the left pane.
  3. Right-click the SQL Server instance and select Properties.
  4. Click the AlwaysOn High Availability tab.
  5. Check Enable AlwaysOn Availability Groups.
  6. Verify the Windows failover cluster name is correct.
  7. Click OK to save the changes.
  8. Click OK on the warning that the service must be restarted.
  9. Right-click the SQL Server service and select Restart.
  10. Wait for the service to restart successfully.
  11. Repeat on all cluster nodes.

Enable SQL Server Always On Availability Groups in SQL Server Configuration Manager

5.4.2 Enabling via PowerShell

PowerShell provides a scripted method to enable Always On Availability Groups across multiple nodes.

  1. Open PowerShell as Administrator on the first node.
  2. Import the SQL Server PowerShell module:
    Import-Module SQLPS -DisableNameChecking
  3. Enable Always On Availability Groups:
    Enable-SqlAlwaysOn -ServerInstance "ServerName\InstanceName" -Force
  4. The service will automatically restart when using the Force parameter.
  5. Verify the feature is enabled:
    Get-ItemProperty "SQLSERVER:\SQL\ServerName\InstanceName" | Select-Object IsHadrEnabled
  6. Repeat for each cluster node, substituting the appropriate server and instance names.

5.4.3 Verifying the Feature is Enabled

Verify that Always On Availability Groups is enabled on all instances before proceeding with configuration.

  1. Connect to each SQL Server instance using SQL Server Management Studio.
  2. Open a new query window and execute:
    SELECT SERVERPROPERTY('IsHadrEnabled')
  3. Verify the result is 1 (enabled).
  4. Check that the SQL Server instance appears in Failover Cluster Manager under cluster roles.
  5. Verify the availability group endpoint exists by executing:
    SELECT * FROM sys.endpoints WHERE type_desc = 'DATABASE_MIRRORING'
  6. If the endpoint does not exist, it will be created during availability group creation.

5.5 Preparing Databases for Availability Groups

Databases must meet specific requirements before they can be added to an availability group.

5.5.1 Database Recovery Model Requirements

Change the database recovery model to FULL on the primary replica before adding it to an availability group.

  1. Connect to the primary replica using SQL Server Management Studio.
  2. Right-click the database and select Properties.
  3. Select the Options page.
  4. Change Recovery model to Full.
  5. Click OK to save the change.
  6. Alternatively, use Transact-SQL:
    ALTER DATABASE DatabaseName SET RECOVERY FULL;

Change the database recovery model to full

5.5.2 Taking Full Database Backups

Take a full database backup to establish the backup chain required for availability groups.

  1. In SQL Server Management Studio, right-click the database.
  2. Select Tasks -> Back Up.
  3. Verify Backup type is set to Full.
  4. Select a backup destination or add a new destination.
  5. Click OK to perform the backup.
  6. Alternatively, use Transact-SQL:
    BACKUP DATABASE DatabaseName TO DISK = 'C:\Backup\DatabaseName.bak';

Create a full backup of a SQL Server database in SQL Server Management Studio.

5.5.3 Taking Transaction Log Backups

Take a transaction log backup to ensure the log chain is established and minimize initialization time.

  1. In SQL Server Management Studio, right-click the database.
  2. Select Tasks -> Back Up.
  3. Change Backup type to Transaction Log.
  4. Select a backup destination.
  5. Click OK to perform the backup.
  6. Alternatively, use Transact-SQL:
    BACKUP LOG DatabaseName TO DISK = 'C:\Backup\DatabaseName.trn';

Create a transaction log backup of a SQL Server database in SQL Server Management Studio.

5.6 Creating the Availability Group

Create the availability group using one of several available methods depending on your preferences and automation requirements.

5.6.1 Using the New Availability Group Wizard

The New Availability Group Wizard provides a graphical interface for creating availability groups.

  1. In SQL Server Management Studio, connect to the instance that will host the primary replica.
  2. Expand AlwaysOn High Availability in Object Explorer.
  3. Right-click Availability Groups and select New Availability Group Wizard.
    Start the new availability group wizard to create a new SQL Server always on availability group
  4. Click Next on the Introduction page.
  5. Enter a name for the availability group and click Next.
  6. On the Select Databases page, select the databases to include.
  7. Verify that databases meet all prerequisites and click Next.
  8. On the Specify Replicas page, click Add Replica.
  9. Connect to each secondary replica instance.
  10. Configure replica properties for each instance (availability mode, failover mode).
  11. Click the Endpoints tab and review endpoint configuration.
  12. Click the Backup Preferences tab and configure backup priorities.
  13. Click the Listener tab and optionally create a listener.
  14. Click Next and select the data synchronization method.
  15. Review validation results and address any issues.
  16. Click Next and review the summary.
  17. Click Finish to create the availability group.
  18. Monitor progress and verify successful creation.

5.6.2 Using Transact-SQL

Create availability groups using Transact-SQL for scriptable, repeatable deployments.

  1. Create the availability group on the primary replica:
    CREATE AVAILABILITY GROUP AG_Name
    FOR DATABASE DatabaseName
    REPLICA ON
      'PrimaryServer\Instance' WITH
        (ENDPOINT_URL = 'TCP://PrimaryServer:5022',
         AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
         FAILOVER_MODE = AUTOMATIC,
         SECONDARY_ROLE(ALLOW_CONNECTIONS = ALL)),
      'SecondaryServer\Instance' WITH
        (ENDPOINT_URL = 'TCP://SecondaryServer:5022',
         AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
         FAILOVER_MODE = AUTOMATIC,
         SECONDARY_ROLE(ALLOW_CONNECTIONS = ALL));
  2. Join the secondary replica to the availability group:
    ALTER AVAILABILITY GROUP AG_Name JOIN;
  3. Join the secondary database:
    ALTER DATABASE DatabaseName SET HADR AVAILABILITY GROUP = AG_Name;

5.6.3 Using PowerShell

PowerShell provides scripting capabilities for availability group creation and management.

  1. Create the availability group object:
    $AG = New-SqlAvailabilityGroup -Name "AG_Name" -Path "SQLSERVER:\SQL\PrimaryServer\Instance"
  2. Add databases:
    Add-SqlAvailabilityDatabase -Path "SQLSERVER:\SQL\PrimaryServer\Instance\AvailabilityGroups\AG_Name" -Database "DatabaseName"
  3. Configure replicas with desired properties using New-SqlAvailabilityReplica cmdlet.
  4. Join secondary replicas using Join-SqlAvailabilityGroup cmdlet.

5.7 Adding Replicas to the Availability Group

Configure replica-specific properties that control how each instance participates in the availability group.

5.7.1 Configuring Replica Properties

Set properties for each replica to define its role and capabilities within the availability group.

  1. In SQL Server Management Studio, expand AlwaysOn High Availability -> Availability Groups.
  2. Expand the availability group and then expand Availability Replicas.
    Availability Replicas in SQL Server Always On Availability Groups
  3. Right-click a replica and select Properties.
  4. Review and modify connection settings for the primary and secondary roles.
  5. Configure session timeout values if needed.
  6. Click OK to save changes.

5.7.2 Setting Availability Modes

Configure availability mode to control synchronization behavior between replicas.

  1. Right-click the availability group and select Properties.
  2. In the General page, go to the Availability Replicas section.
  3. For each replica, select Synchronous commit or Asynchronous commit from the dropdown.
  4. Use synchronous commit for local high availability replicas.
  5. Use asynchronous commit for geographically distant disaster recovery replicas.
  6. Click OK to save the configuration.

Setting Availability Modes for Availability Replicas

5.7.3 Setting Failover Modes

Configure failover mode to control how failover occurs for each replica.

  1. Right-click the availability group and select Properties.
  2. In the General page, go to the Availability Replicas section.
  3. For synchronous commit replicas, select Automatic or Manual failover mode.
  4. Automatic failover requires synchronous commit mode and enables unattended failover.
  5. For asynchronous commit replicas, only manual failover is available.
  6. Configure up to three replicas for automatic failover (one primary and two secondaries).
  7. Click OK to apply the settings.

Set the failover modes for availability replicas

5.7.4 Configuring Backup Preferences

Set backup preferences to control where backup operations should occur.

  1. Right-click the availability group and select Properties.
  2. Select Backup Preferences in the left pane.
  3. Choose one of the backup preferences:
    • Prefer Secondary: Backups on secondary if available, otherwise primary
    • Secondary only: Backups only on secondary replicas
    • Primary: Backups only on primary replica
    • Any Replica: Backups on any available replica
  4. Set backup priority values for each replica (0-100).
  5. Higher priority values indicate preferred backup targets.
  6. Click OK to save the preferences.

Configure the backup preferences for availability group

5.8 Configuring the Availability Group Listener

Create a listener to provide a single connection point that automatically redirects to the current primary replica.

5.8.1 Creating the Listener

Add a listener to the availability group for client connection management.

  1. In SQL Server Management Studio, expand the availability group.
  2. Right-click Availability Group Listeners and select Add Listener.
    Add listener to the availability group
  3. Enter a DNS name for the listener (for example, AG_Listener).
  4. Enter the port number (default is 1433).
  5. Select Static IP for the network mode.
  6. Click Add to add an IP address for each subnet.
  7. Enter the IP address and select the subnet.
  8. Click OK to create the listener.
  9. Verify the listener appears in Object Explorer and is online.

5.8.2 Configuring DNS and IP Settings

Verify DNS registration and network configuration for the listener.

  1. Open DNS Manager on the domain controller.
  2. Verify that the listener name has been registered with all IP addresses.
  3. Test DNS resolution from client machines:
    nslookup ListenerName
  4. Verify all configured IP addresses are returned.
  5. In Failover Cluster Manager, expand Roles and select the availability group.
  6. Verify the IP address resources are online.
  7. Check that the network name resource is online.
    Verify the IP address and network name resource of the listener.

5.8.3 Testing Listener Connectivity

Verify that client applications can connect through the listener.

  1. From a client machine, open SQL Server Management Studio.
  2. Connect using the listener name instead of a server name.
  3. Execute a query to verify connection to the current primary replica:
    SELECT @@SERVERNAME;
  4. Test read-intent routing by adding ApplicationIntent=ReadOnly to the connection string.
  5. Verify connection redirects to a readable secondary replica.
  6. Test failover by manually failing over the availability group and verifying reconnection.

5.9 Data Synchronization Methods

Choose a data synchronization method to initialize secondary replicas with database copies.

5.9.1 Automatic Seeding

Automatic seeding transfers database data over the network without requiring manual backups and restores.

  1. During availability group creation, select Automatic seeding as the synchronization method.
    Automatic seeding in availability group
  2. Ensure network connectivity and sufficient bandwidth between replicas.
  3. The primary replica automatically streams database data to secondary replicas.
  4. Monitor seeding progress using the availability group dashboard or DMVs.
  5. Automatic seeding requires SQL Server 2016 or later.
  6. For large databases, consider network impact and schedule during low-usage periods.

5.9.2 Manual Seeding (Backup and Restore)

Manual seeding involves taking backups on the primary and restoring them on secondary replicas.

  1. On the primary replica, take a full backup:
    BACKUP DATABASE DatabaseName TO DISK = '\\SharePath\DatabaseName.bak';
  2. Take a transaction log backup:
    BACKUP LOG DatabaseName TO DISK = '\\SharePath\DatabaseName.trn';
  3. On each secondary replica, restore the full backup:
    RESTORE DATABASE DatabaseName FROM DISK = '\\SharePath\DatabaseName.bak' WITH NORECOVERY;
  4. Restore the log backup:
    RESTORE LOG DatabaseName FROM DISK = '\\SharePath\DatabaseName.trn' WITH NORECOVERY;
  5. Join the database to the availability group:
    ALTER DATABASE DatabaseName SET HADR AVAILABILITY GROUP = AG_Name;
  6. Verify synchronization begins and the database reaches the SYNCHRONIZED state.

5.9.3 Database Snapshot Files

Use database snapshot files to initialize secondary replicas from existing database files.

  1. Detach or backup the database on the primary replica.
  2. Copy database files to each secondary replica using the same file paths.
  3. On secondary replicas, attach the database or restore without recovery.
  4. Ensure the database is in RESTORING state.
  5. Join the database to the availability group.
  6. This method is useful for very large databases where network transfer would be impractical.

6. FAQ

6.1 General Questions

Q: What is the difference between Always On FCI and Always On AG?

A: Always On Failover Cluster Instances provide instance-level high availability using shared storage, while Always On Availability Groups provide database-level high availability without shared storage. AG offers readable secondaries and more flexible geographic distribution.

Q: Can I use Always On Availability Groups with SQL Server Standard Edition?

A: Yes, SQL Server 2016 Standard Edition and later support Basic Availability Groups with limitations including one database per AG, two replicas maximum, and no readable secondary support.

Q: Do I need shared storage for Always On Availability Groups?

A: No, availability groups do not require shared storage. Each replica maintains independent copies of databases on local storage, synchronized through transaction log shipping.

Q: What is the maximum number of replicas in an availability group?

A: SQL Server Enterprise Edition supports up to nine replicas (one primary and eight secondaries). Distributed availability groups can support up to 18 total replicas across two availability groups.

6.2 Configuration Questions

Q: How do I choose between synchronous and asynchronous commit modes?

A: Use synchronous commit for zero data loss requirements within the same data center or low-latency networks. Use asynchronous commit for distant disaster recovery replicas where synchronous commit would impact performance.

Q: Can I mix synchronous and asynchronous replicas in the same availability group?

A: Yes, availability groups support mixed configurations with both synchronous and asynchronous replicas. This enables local high availability with synchronous replicas and distant disaster recovery with asynchronous replicas.

Q: What happens to my connections during failover?

A: Existing connections are dropped when failover occurs. Applications with connection retry logic automatically reconnect to the new primary through the listener. The failover process typically completes within seconds to minutes.

Q: Do I need to synchronize logins and jobs across replicas?

A: In SQL Server 2019 and earlier, yes – logins, SQL Agent jobs, and linked servers must be manually synchronized. SQL Server 2022 introduces contained availability groups that automatically include these objects.

6.3 Management Questions

Q: Can I run backups on secondary replicas?

A: Yes, secondary replicas support full, differential, and transaction log backups. Configure backup preferences to offload backups from the primary replica and reduce its resource utilization.

Q: How do I patch SQL Server with minimal downtime?

A: Use rolling upgrades by patching secondary replicas first, then performing a manual failover to a patched secondary, and finally patching the former primary. This minimizes downtime to the failover duration.

Q: Can I add databases to an existing availability group?

A: Yes, databases can be added to running availability groups. The database must be in full recovery model with a full backup, and secondary replicas must be seeded using automatic seeding or manual backup and restore.

Q: What is automatic seeding and should I use it?

A: Automatic seeding transfers database data over the network to initialize secondary replicas without manual backups. Use it for smaller databases or when network bandwidth is sufficient. For very large databases, manual seeding may be faster.

Q: Where should I run DBCC CHECKDB in an availability group?

A: You should run DBCC CHECKDB on secondary replicas to reduce load on the primary replica. Database consistency checks can execute against secondary databases without affecting primary replica performance.

For more details on DBCC CHECKDB, see our comprehensive guide.

6.4 Troubleshooting Questions

Q: Why is my database in NOT SYNCHRONIZING state?

A: Common causes include network connectivity issues, suspended data movement, insufficient disk space on secondary replicas, or endpoint problems. Check the synchronization health description and SQL Server error logs for specific details.

Q: How do I force failover when the primary is unavailable?

A: Connect to a secondary replica and execute ALTER AVAILABILITY GROUP AG_Name FORCE_FAILOVER_ALLOW_DATA_LOSS. This acknowledges potential data loss and promotes the secondary to primary immediately.

Q: Why can’t clients connect to my listener?

A: Verify the listener is online in Failover Cluster Manager, DNS registration succeeded, all listener IPs are reachable from clients, and firewall rules allow traffic to the listener port.

Q: What does a large redo queue mean?

A: A large redo queue indicates the secondary replica cannot apply log records as fast as they arrive. This may indicate disk I/O bottlenecks, CPU constraints, or blocking from read-only queries on the secondary.

6.5 Licensing and Cost Questions

Q: How is Always On Availability Groups licensed?

A: SQL Server licensing depends on the edition and deployment model. Enterprise Edition availability groups require Enterprise licenses on all replicas. Passive secondary replicas may qualify for free licensing under certain conditions.

Q: Can I use SQL Server Developer Edition for availability groups?

A: Yes, Developer Edition includes all Enterprise Edition features including full availability groups support. However, it is licensed only for development and testing, not production use.

Q: Do readable secondaries require additional licenses?

A: Licensing depends on the scenario. Passive secondaries for disaster recovery typically do not require licenses. Active secondaries serving read-only workloads generally require licenses, though specific terms vary.

Q: Is there a free way to get high availability with SQL Server?

A: SQL Server Express Edition does not support availability groups. SQL Server Standard Edition supports Basic Availability Groups starting with SQL Server 2016, providing basic high availability at Standard Edition licensing costs.

Q: What are Distributed Availability Groups?

A: Distributed availability groups are a special type of availability group that spans two separate availability groups, enabling scenarios that exceed the capabilities of traditional availability groups. Introduced in SQL Server 2016, distributed availability groups address scaling and geographic distribution requirements.

7. Conclusion

7.1 Summary of Key Points

SQL Server Always On Availability Groups represent Microsoft’s premier high availability and disaster recovery solution for mission-critical databases. They provide database-level failover without shared storage requirements, readable secondary replicas for offloading workloads, and flexible geographic distribution for comprehensive data protection.

7.2 When to Use Always On Availability Groups

Choose availability groups when requiring database-level high availability with automatic failover capabilities. Organizations needing zero data loss protection for critical databases benefit from synchronous commit replicas with automatic failover. Applications requiring read-scale capabilities leverage readable secondary replicas to distribute query workloads.

7.3 Getting Started with Your Implementation

Begin availability group planning by assessing business requirements including RTO, RPO, and budget constraints. Document current database infrastructure, application dependencies, and high availability gaps. Design an availability group architecture that addresses requirements while remaining within resource constraints.

References


About the Author

Yuan Sheng is a senior database administrator (DBA) with over 10 years of experience in SQL Server environments and enterprise database management. He has successfully resolved hundreds of database recovery scenarios across financial services, healthcare, and manufacturing organizations.

Yuan specializes in SQL Server database recovery, high availability solutions, and performance optimization. His extensive hands-on experience includes managing multi-terabyte databases, implementing Always On Availability Groups, and developing automated backup and recovery strategies for mission-critical business systems.

Through his technical expertise and practical approach, Yuan focuses on creating comprehensive guides that help database administrators and IT professionals solve complex SQL Server challenges efficiently. He stays current with the latest SQL Server releases and Microsoft’s evolving database technologies, regularly testing recovery scenarios to ensure his recommendations reflect real-world best practices.

Have questions about SQL Server recovery or need additional database troubleshooting guidance? Yuan welcomes feedback and suggestions for improving these technical resources.