删除可用性组 (SQL Server)Remove 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 StudioTransact-SQLTransact-SQL或 PowerShell 在 SQL Server 2017SQL Server 2017中删除 AlwaysOn 可用性组。This topic describes how to delete (drop) 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. 如果在删除某一可用性组时承载可用性副本之一的服务器实例处于脱机状态,则在联机后,该服务器实例将删除本地可用性副本。If a server instance that hosts one of the availability replicas is offline when you delete an availability group, after coming online, the server instance will drop the local availability replica. 删除可用性组时,将删除任何关联的可用性组侦听器。Dropping an availability group deletes any associated availability group listener.

请注意,如果需要,您可以从拥有某一可用性组的正确安全凭据的任何 Windows Server 故障转移群集 (WSFC) 节点删除该可用性组。Note that, if necessary, you can drop an availability group from any Windows Server Failover Clustering (WSFC) node that possesses the correct security credentials for the availability group. 因此,在某一可用性组未保留任何可用性副本时,您可以删除该可用性组。This enables you to delete an availability group when none of its availability replicas remain.

重要

如果可能,请仅在连接到承载主副本的服务器实例时删除此可用性组。If possible, remove the availability group only while connected to the server instance that hosts the primary replica. 从主副本中删除此可用性组时,允许对以前的主数据库进行更改(不具有高可用性保护)。When the availability group is dropped from the primary replica, changes are allowed in the former primary databases (without high availability protection). 从辅助副本中删除可用性组会使主副本处于 RESTORING 状态,且不允许对此数据库进行更改。Deleting an availability group from a secondary replica leaves the primary replica in the RESTORING state, and changes are not allowed on the databases.

限制和建议Limitations and Recommendations

  • 当可用性组处于联机状态时,从辅助副本删除它会导致主副本转换为 RESTORING 状态。When the availability group is online, deleting it from a secondary replica causes the primary replica to transition to the RESTORING state. 因此,如果可能,请仅从承载主副本的服务器实例中删除此可用性组。Therefore, if possible, remove the availability group only from the server instance that hosts the primary replica.
  • 如果您从已被 WSFC 故障转移群集删除或逐出的计算机删除某一可用性组,则该可用性组仅在本地删除。If you delete an availability group from a computer that has been removed or evicted from the WSFC failover cluster, the availability group is only deleted locally.
  • 如果 Windows Server 故障转移群集 (WSFC) 群集没有仲裁,则避免删除可用性组。Avoid dropping an availability group when the Windows Server Failover Clustering (WSFC) cluster has no quorum. 如果在群集缺少仲裁时必须删除可用性组,则不删除群集中存储的元数据可用性组。If you must drop an availability group while the cluster lacks quorum, the metadata availability group that is stored in the cluster is not removed. 在群集重新获得仲裁后,将需要再次删除此可用性组以便将其从 WSFC 群集中删除。After the cluster regains quorum, you will need to drop the availability group again to remove it from the WSFC cluster.
  • 在辅助副本上,DROP AVAILABILITY GROUP 应仅用于紧急情况。On a secondary replica, DROP AVAILABILITY GROUP should only be used only for emergency purposes. 这是因为删除可用性组会使该可用性组脱机。This is because dropping an availability group takes the availability group offline. 如果您从辅助副本中删除该可用性组,则主副本无法确定出现 OFFLINE 状态是因为仲裁丢失、强制故障转移还是 DROP AVAILABILITY GROUP 命令。If you drop the availability group from a secondary replica, the primary replica cannot determine whether the OFFLINE state occurred because of quorum loss, a forced failover, or a DROP AVAILABILITY GROUP command. 主副本将转换为 RESTORING 状态以避免出现可能的裂脑情况。The primary replica transitions to the RESTORING state to prevent a possible split-brain situation. 有关详细信息,请参阅工作原理:DROP AVAILABILITY GROUP 行为(CSS SQL Server 工程师博客)。For more information, see How It Works: DROP AVAILABILITY GROUP Behaviors (CSS SQL Server Engineers blog).

权限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. 若要删除并非由本地服务器实例承载的某一可用性组,您需要针对该可用性组的 CONTROL SERVER 权限或 CONTROL 权限。To drop an availability group that is not hosted by the local server instance you need CONTROL SERVER permission or CONTROL permission on that Availability Group.

使用 SQL Server Management StudioUsing SQL Server Management Studio

删除可用性组To delete an availability group

  1. 在对象资源管理器中,连接到托管主要副本的服务器实例,如果可能,还可以连接到 WSFC 节点(该节点拥有可用性组的正确安全凭据)上为 AlwaysOn 可用性组启用的另一个服务器实例。In Object Explorer, connect to the server instance that hosts primary replica, if possible, or connect to another server instance that is enabled for Always On Availability Groups on a WSFC node that possess the correct security credentials for the availability group. 展开服务器树。Expand the server tree.

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

  3. 此步骤取决于您是要删除多个可用性组还是只删除一个可用性组,如下所示:This step depends on whether you want to delete multiple availability groups or only one availability group, as follows:

  4. 右键单击所选的可用性组,然后选择“删除” 命令。Right-click the selected availability group or groups, and select the Delete command.

  5. “删除可用性组” 对话框中,若要删除所有列出的可用性组,请单击 “确定”In the Remove Availability Group dialog box, to delete all the listed availability groups, click OK. 如果您不想删除所有列出的可用性组,请单击 “取消”If you do not want to remove all the listed availability groups, click Cancel.

使用 Transact-SQLUsing Transact-SQL

删除可用性组To delete an availability group

  1. 连接到托管主要副本的服务器实例,如果可能,还可以连接到 WSFC 节点(该节点拥有可用性组的正确安全凭据)上为 AlwaysOn 可用性组启用的另一个服务器实例。Connect to the server instance that hosts the primary replica, if possible, or connect to another server instance that is enabled for Always On Availability Groups on a WSFC node that possess the correct security credentials for the availability group.

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

    DROP AVAILABILITY GROUP group_nameDROP AVAILABILITY GROUP group_name

    其中, group_name 是要删除的可用性组的名称。where group_name is the name of the availability group to be dropped.

    下面的示例将删除 MyAG 可用性组。The following example deletes the MyAG availability group.

    DROP AVAILABILITY GROUP MyAG;  
    

使用 PowerShellUsing PowerShell

删除可用性组To delete an availability group

SQL ServerSQL Server PowerShell 提供程序中:In the SQL ServerSQL Server PowerShell provider:

  1. 将目录 (cd) 更改为托管主要副本的服务器实例,如果可能,还可以连接到为 WSFC 节点(该节点拥有可用性组的正确安全凭据)上的 AlwaysOn 可用性组启用的另一个服务器实例。Change directory (cd) to the server instance that hosts the primary replica, if possible, or connect to another server instance that is enabled for Always On Availability Groups on a WSFC node that possess the correct security credentials for the availability group.

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

    例如,下面的命令删除名为 MyAg的可用性组。For example, the following command removes the availability group named MyAg. 可以对承载可用性组的可用性副本的任何服务器实例执行此命令。This command can be executed on any server instance that hosts an availability replica for the availability group.

    Remove-SqlAvailabilityGroup `   
    -Path SQLSERVER:\Sql\Computer\Instance\AvailabilityGroups\MyAg  
    

    备注

    若要查看 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

相关内容Related Content

另请参阅See Also

AlwaysOn 可用性组概述 (SQL Server) Overview of Always On Availability Groups (SQL Server)
创建和配置可用性组 (SQL Server)Creation and Configuration of Availability Groups (SQL Server)