Microsoft SQL Server Documentation

Always On Availability Groups

Always On Availability Groups (AGs) are a high-availability and disaster-recovery solution that provides an enterprise-level of data protection for a set of user databases, known as availability databases. An availability group supports a set of primary databases and one to eight sets of corresponding secondary databases.

Note: Always On Availability Groups was introduced in SQL Server 2012 and has been enhanced in subsequent releases.

Key Components and Concepts

Diagram of Always On Availability Groups
Conceptual overview of an Always On Availability Group setup.

Benefits of Always On Availability Groups

Prerequisites and Considerations

Configuring an Availability Group

Configuring an Availability Group typically involves the following steps:

  1. Ensure prerequisites are met (WSFC, SQL Server editions, recovery model).
  2. Enable the Always On Availability Groups feature on each participating SQL Server instance.
  3. Create a new Availability Group using SQL Server Management Studio (SSMS) or Transact-SQL (T-SQL).
  4. Add databases to the Availability Group.
  5. Configure availability replicas (endpoints, availability modes, failover modes).
  6. Create an Availability Group Listener for client connectivity.
  7. Configure backup preferences for secondary replicas.

T-SQL Example: Creating an Availability Group


CREATE AVAILABILITY GROUP MyAG
WITH (
    AUTOMATED_BACKUP_PREFERENCE = SECONDARY,
    DB_FAILOVER = ON,
    DTC_SUPPORT = NONE
)
REPLICA ON
    'ServerA' WITH (
        ENDPOINT_URL = 'TCP://ServerA.contoso.com:5022',
        AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
        FAILOVER_MODE = AUTOMATIC,
        BACKUP_PRIORITY = 60,
        SECONDARY_ROLE (ALLOW_CONNECTIONS = READ_ONLY)
    ),
    'ServerB' WITH (
        ENDPOINT_URL = 'TCP://ServerB.contoso.com:5022',
        AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
        FAILOVER_MODE = AUTOMATIC,
        BACKUP_PRIORITY = 50,
        SECONDARY_ROLE (ALLOW_CONNECTIONS = READ_WRITE)
    );
GO

ALTER AVAILABILITY GROUP MyAG
MODIFY REPLICA ON 'ServerA' WITH (PRIMARY_ROLE = (READ_WRITE, PRIMARY_BETA = 10));
GO
            

Monitoring and Troubleshooting

Effective monitoring is crucial for maintaining the health of your Availability Groups. SQL Server Management Studio provides dynamic management views (DMVs) and built-in dashboards for this purpose. Key DMVs include:

Tip: Regularly review SQL Server error logs and Windows Event Logs for any cluster or AG-related events.

Further Reading