Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server
This topic describes how to remove a secondary replica from an Always On availability group by using SQL Server Management Studio, Transact-SQL, or PowerShell in SQL Server.
Requires ALTER AVAILABILITY GROUP permission on the availability group, CONTROL AVAILABILITY GROUP permission, ALTER ANY AVAILABILITY GROUP permission, or CONTROL SERVER permission.
To remove a secondary replica
In Object Explorer, connect to the server instance that hosts the primary replica, and expand the server tree.
Expand the Always On High Availability node and the Availability Groups node.
Select the availability group, and expand the Availability Replicas node.
This step depends on whether you want to remove multiple replicas or only one replica, as follows:
To remove multiple replicas, use the Object Explorer Details pane to view and select all the replicas that you want to remove. For more information, see Use the Object Explorer Details to Monitor Availability Groups (SQL Server Management Studio).
To remove a single replica, select it in either the Object Explorer pane or the Object Explorer Details pane.
Right-click the selected secondary replica or replicas, and select Remove from Availability Group in the command menu.
In the Remove Secondary Replicas from Availability Group dialog box, to remove all the listed secondary replicas, click OK. If you do not want to remove all the listed replicas, click Cancel.
To remove a secondary replica
Connect to the server instance that hosts the primary replica.
Use the ALTER AVAILABILITY GROUP statement, as follows:
ALTER AVAILABILITY GROUP group_name REMOVE REPLICA ON 'instance_name' [,...n]
where group_name is the name of the availability group and instance_name is the server instance where the secondary replica is located.
The following example removes a secondary replica from the MyAG availability group. The target secondary replica is located on a server instance named HADR_INSTANCE on a computer named COMPUTER02.
ALTER AVAILABILITY GROUP MyAG REMOVE REPLICA ON 'COMPUTER02\HADR_INSTANCE';
To remove a secondary replica
Change directory (cd) to the server instance that hosts the primary replica.
Use the Remove-SqlAvailabilityReplica cmdlet.
For example, the following command removes the availability replica on the server MyReplica
from the availability group named MyAg
. This command must be run on the server instance that hosts the primary replica of the availability group.
Remove-SqlAvailabilityReplica `
-Path SQLSERVER:\SQL\PrimaryServer\InstanceName\AvailabilityGroups\MyAg\AvailabilityReplicas\MyReplica
Note
To view the syntax of a cmdlet, use the Get-Help cmdlet in the SQL Server PowerShell environment. For more information, see Get Help SQL Server PowerShell.
To set up and use the SQL Server PowerShell provider
If you specify a replica that is currently unavailable, when the replica comes online, it will discover that it has been removed.
Removing a replica causes it to stop receiving data. After a secondary replica confirms that it has been removed from the global store, the replica removes the availability group settings from its databases, which remain on the local server instance in the RECOVERING state.
Overview of Always On Availability Groups (SQL Server)
Add a Secondary Replica to an Availability Group (SQL Server)
Remove an Availability Group (SQL Server)
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayTraining
Module
Explore IaaS and PaaS solutions for high availability and disaster recovery - Training
Explore IaaS and PaaS solutions for high availability and disaster recovery