从可用性组中删除辅助副本 (SQL Server)Remove a Secondary Replica from an Availability Group (SQL Server)

适用对象: yesSQL ServeryesAzure SQL 数据库noAzure SQL 数据仓库no并行数据仓库APPLIES TO: yesSQL Server noAzure SQL Database noAzure SQL Data Warehouse noParallel Data Warehouse

本主题说明了如何通过在 SQL Server Management StudioSQL Server Management Studio中使用 Transact-SQLTransact-SQLSQL Server 2017SQL Server 2017或 PowerShell 从 AlwaysOn 可用性组中删除次要副本。This topic describes how to remove a secondary replica from an Always On availability group by using SQL Server Management StudioSQL Server Management Studio, Transact-SQLTransact-SQL, or PowerShell in SQL Server 2017SQL Server 2017.

限制和局限Limitations and Restrictions

  • 只有主副本支持该任务。This task is supported only on the primary replica.
  • 从可用性组中仅可删除辅助副本。Only a secondary replica can be removed from an availability group.

先决条件Prerequisites

  • 您必须连接到承载可用性组的主副本的服务器实例。You must be connected to the server instance that hosts the primary replica of the availability group.

权限Permissions

对可用性组要求 ALTER AVAILABILITY GROUP 权限、CONTROL AVAILABILITY GROUP 权限、ALTER ANY AVAILABILITY GROUP 权限或 CONTROL SERVER 权限。Requires ALTER AVAILABILITY GROUP permission on the availability group, CONTROL AVAILABILITY GROUP permission, ALTER ANY AVAILABILITY GROUP permission, or CONTROL SERVER permission.

使用 SQL Server Management StudioUsing SQL Server Management Studio

删除辅助副本To remove a secondary replica

  1. 在对象资源管理器中,连接到承载主副本的服务器实例,然后展开服务器树。In Object Explorer, connect to the server instance that hosts the primary replica, and expand the server tree.

  2. 依次展开“Always On 高可用性” 节点和“可用性组” 节点。Expand the Always On High Availability node and the Availability Groups node.

  3. 选择可用性组,然后展开 “可用性副本” 节点。Select the availability group, and expand the Availability Replicas node.

  4. 此步骤取决于您是要删除多个副本,还是只删除一个副本,如下所示:This step depends on whether you want to remove multiple replicas or only one replica, as follows:

  5. 右键单击选定的一个或多个次要副本,然后在命令菜单中选择“从可用性组中删除” 。Right-click the selected secondary replica or replicas, and select Remove from Availability Group in the command menu.

  6. “从可用性组删除辅助副本” 对话框中,要删除所有列出的辅助副本,请单击 “确定”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.

使用 Transact-SQLUsing Transact-SQL

删除辅助副本To remove a secondary replica

  1. 连接到承载主副本的服务器实例。Connect to the server instance that hosts the primary replica.

  2. 按如下所示使用 ALTER AVAILABILITY GROUP 语句:Use the ALTER AVAILABILITY GROUP statement, as follows:

    ALTER AVAILABILITY GROUP group_name REMOVE REPLICA ON 'instance_name ' [,...n ]ALTER AVAILABILITY GROUP group_name REMOVE REPLICA ON 'instance_name' [,...n]

    其中,group_name 为可用性组的名称,instance_name 为该次要副本所在的服务器实例。where group_name is the name of the availability group and instance_name is the server instance where the secondary replica is located.

    下面的示例将次要副本从 MyAG 可用性组中删除。The following example removes a secondary replica from the MyAG availability group. 目标次要副本位于名为 COMPUTER02 的计算机上的服务器实例(名为 HADR_INSTANCE )上。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';  
    

使用 PowerShellUsing PowerShell

删除辅助副本To remove a secondary replica

  1. 将目录 (cd) 更改为托管主副本的服务器实例。Change directory (cd) to the server instance that hosts the primary replica.

  2. 使用 Remove-SqlAvailabilityReplica cmdlet。Use the Remove-SqlAvailabilityReplica cmdlet.

    例如,下面的命令从名为 MyReplica 的可用性组中删除服务器 MyAg上的可用性副本。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  
    

    备注

    若要查看 cmdlet 的语法,请在 PowerShell 环境中使用 Get-Help SQL ServerSQL Server cmdlet。To view the syntax of a cmdlet, use the Get-Help cmdlet in the SQL ServerSQL Server PowerShell environment. 有关详细信息,请参阅 Get Help SQL Server PowerShellFor more information, see Get Help SQL Server PowerShell.

设置和使用 SQL Server PowerShell 提供程序To set up and use the SQL Server PowerShell provider

跟进:在删除次要副本之后Follow Up: After Removing a Secondary Replica

如果您指定一个当前不可用的副本,则在该副本联机时,将发现该副本已被删除。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. 在某个辅助副本确认其已从全局存储中删除之后,该副本将从其数据库(在本地服务器实例上保留为 RECOVERING 状态)中删除可用性组设置。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.

另请参阅See Also

AlwaysOn 可用性组概述 (SQL Server) Overview of Always On Availability Groups (SQL Server)
将次要副本添加到可用性组 (SQL Server) Add a Secondary Replica to an Availability Group (SQL Server)
删除可用性组 (SQL Server)Remove an Availability Group (SQL Server)