AlwaysOn 可用性组概述 (SQL Server)Overview of Always On Availability Groups (SQL Server)

适用对象:是SQL Server 否Azure SQL 数据库 否Azure Synapse Analytics (SQL DW) 否并行数据仓库 APPLIES TO: yesSQL Server noAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

本主题介绍用于在 Always On 可用性组Always On availability groups 中配置和管理一个或多个可用性组的核心 SQL Server 2019 (15.x)SQL Server 2019 (15.x)概念。This topic introduces the Always On 可用性组Always On availability groups concepts that are central for configuring and managing one or more availability groups in SQL Server 2019 (15.x)SQL Server 2019 (15.x). 有关可用性组提供的优势的摘要和 Always On 可用性组Always On availability groups 术语的概述,请参阅 AlwaysOn 可用性组 (SQL Server)For a summary of the benefits offered by availability groups and an overview of Always On 可用性组Always On availability groups terminology, see Always On Availability Groups (SQL Server).

可用性组支持的复制环境适用于一组离散用户数据库,称为“可用性数据库” 。An availability group supports a replicated environment for a discrete set of user databases, known as availability databases. 可以创建可用性组以实现高可用性 (HA) 或读取缩放。You can create an availability group for high availability (HA) or for read-scale. HA 可用性组是一组共同实现故障转移的数据库。An HA availability group is a group of databases that fail over together. 读取缩放可用性组是一组复制到其他 SQL Server 实例以实现只读工作负荷的数据库。A read-scale availability group is a group of databases that are copied to other instances of SQL Server for read-only workload. 一个可用性组支持一组主数据库以及一至八组对应的辅助数据库。An availability group supports one set of primary databases and one to eight sets of corresponding secondary databases. 辅助数据库 不是 备份。Secondary databases are not backups. 应继续定期备份您的数据库及其事务日志。Continue to back up your databases and their transaction logs on a regular basis.

提示

您可以创建主数据库的任何类型的备份。You can create any type of backup of a primary database. 也可以创建辅助数据库的日志备份和仅复制完整备份。Alternatively, you can create log backups and copy-only full backups of secondary databases. 有关详细信息,请参阅活动次要副本:次要副本备份(Always On 可用性组)For more information, see Active Secondaries: Backup on Secondary Replicas (Always On Availability Groups).

每组可用性数据库都由一个“可用性副本” 承载。Each set of availability database is hosted by an availability replica. 有两种类型的可用性副本:一个“主副本” 和一到四个“辅助副本”。Two types of availability replicas exist: a single primary replica. 它承载主数据库和一至八个“辅助副本” ,其中每个副本承载一组辅助数据库,并用作可用性组的潜在故障转移目标。which hosts the primary databases, and one to eight secondary replicas, each of which hosts a set of secondary databases and serves as a potential failover targets for the availability group. 可用性组在可用性副本级别进行故障转移。An availability group fails over at the level of an availability replica. 可用性副本仅在数据库级别提供冗余(针对一个可用性组中的该组数据库)。An availability replica provides redundancy only at the database level-for the set of databases in one availability group. 故障转移不是由诸如因数据文件丢失或事务日志损坏而使数据库成为可疑数据库等数据库问题导致的。Failovers are not caused by database issues such as a database becoming suspect due to a loss of a data file or corruption of a transaction log.

主副本使主数据库可用于客户端的读写连接。The primary replica makes the primary databases available for read-write connections from clients. 主副本将每个主数据库的事务日志记录发送到每个辅助数据库。The primary replica sends transaction log records of each primary database to every secondary database. 此过程(称为“数据同步”)在数据库级别运行 。This process - known as data synchronization - occurs at the database level. 每个次要副本缓存事务日志记录(“硬化” 日志),然后将它们应用到相应的辅助数据库。Every secondary replica caches the transaction log records (hardens the log) and then applies them to its corresponding secondary database. 主数据库与每个连接的辅助数据库独立进行数据同步。Data synchronization occurs between the primary database and each connected secondary database, independently of the other databases. 因此,一个辅助数据库可以挂起或失败而不会影响其他辅助数据库,一个主数据库可以挂起或失败而不会影响其他主数据库。Therefore, a secondary database can be suspended or fail without affecting other secondary databases, and a primary database can be suspended or fail without affecting other primary databases.

或者,您可以配置一个或多个辅助副本以支持对辅助数据库进行只读访问,并且可以将任何辅助副本配置为允许对辅助数据库进行备份。Optionally, you can configure one or more secondary replicas to support read-only access to secondary databases, and you can configure any secondary replica to permit backups on secondary databases.

SQL Server 2017 引入了用于可用性组的两种不同的体系结构。SQL Server 2017 introduces two different architectures for availability groups. “AlwaysOn 可用性组”提供高可用性、灾难恢复和读取缩放均衡 。Always On availability groups provide high availability, disaster recovery, and read-scale balancing. 这些可用性组需要群集管理器。These availability groups require a cluster manager. 在 Windows 中,故障转移群集提供群集管理器。In Windows, failover clustering provides the cluster manager. 在 Linux 中可以使用 Pacemaker。In Linux, you can use Pacemaker. 另一个体系结构是“读取缩放可用性组” 。The other architecture is a read-scale availability group. 读取缩放可用性组为只读工作负荷提供副本,但不提供高可用性。A read scale availability group provides replicas for read-only workloads but not high availability. 读取缩放可用性组中没有群集管理器。In a read-scale availability group there is no cluster manager.

在 Windows 上为 HA 部署 Always On 可用性组Always On availability groups 需要 Windows Server 故障转移群集 (WSFC)。Deploying Always On 可用性组Always On availability groups for HA on Windows requires a Windows Server Failover Cluster(WSFC). 给定可用性组的每个可用性副本必须位于相同 WSFC 的不同节点上。Each availability replica of a given availability group must reside on a different node of the same WSFC. 唯一的例外是在迁移到另一个 WSFC 群集时,此时一个可用性组可能会暂时跨两个群集。The only exception is that while being migrated to another WSFC cluster, an availability group can temporarily straddle two clusters.

备注

有关 Linux 上可用性组的信息,请参阅 Linux 上的 SQL Server 的 AlwaysOn 可用性组For information about availability groups on Linux, see Always On availability group for SQL Server on Linux.

HA 配置中会为创建的每个可用性组创建一个群集角色。In an HA configuration, a cluster role is created for every availability group that you create. WSFC 群集将监视此角色,以便评估主要副本的运行状况。The WSFC cluster monitors this role to evaluate the health of the primary replica. 针对 Always On 可用性组Always On availability groups 的仲裁基于 WSFC 群集中的所有节点,而与某一给定群集节点是否承载任何可用性副本无关。The quorum for Always On 可用性组Always On availability groups is based on all nodes in the WSFC cluster regardless of whether a given cluster node hosts any availability replicas. 与数据库镜像相反,在 Always On 可用性组Always On availability groups中没有见证服务器角色。In contrast to database mirroring, there is no witness role in Always On 可用性组Always On availability groups.

备注

有关 SQL Server AlwaysOn 组件与 WSFC 群集的关系的信息,请参阅 Windows Server 故障转移群集 (WSFC) 与 SQL ServerFor information about the relationship of SQL Server Always On components to the WSFC cluster, see Windows Server Failover Clustering (WSFC) with SQL Server.

下图显示的是一个包含一个主要副本和四个次要副本的可用性组。The following illustration shows an availability group that contains one primary replica and four secondary replicas. 支持最多八个辅助副本,包括一个主副本和两个同步提交辅助副本。Up to eight secondary replicas are supported, including one primary replica and two synchronous-commit secondary replicas.

有五个副本的可用性组Availability group with five replicas

可用性数据库Availability Databases

若要将数据库添加到可用性组,该数据库必须是联机的读写数据库,它位于承载主副本的服务器实例上。To add a database to an availability group, the database must be an online, read-write database that exists on the server instance that hosts the primary replica. 当您添加一个数据库时,它将作为主数据库加入可用性组,同时保持可用于客户端。When you add a database, it joins the availability group as a primary database, while remaining available to clients. 除非新的主数据库的备份还原到承载辅助副本(使用 RESTORE WITH NORECOVERY)的服务器实例,否则不存在对应的辅助数据库。No corresponding secondary database exists until backups of the new primary database are restored to the server instance that hosts the secondary replica (using RESTORE WITH NORECOVERY). 新的辅助数据库处于 RESTORING 状态,直至其加入可用性组。The new secondary database is in the RESTORING state until it is joined to the availability group. 有关详细信息,请参阅本主题后面的 启动 AlwaysOn 辅助数据库的数据移动 (SQL Server)For more information, see Start Data Movement on an Always On Secondary Database (SQL Server).

加入后,辅助数据库将进入 ONLINE 状态,并启动与对应主数据库之间的数据同步。Joining places the secondary database into the ONLINE state and initiates data synchronization with the corresponding primary database. “数据同步” 是在辅助数据库上重新生成对主数据库的更改的过程。Data synchronization is the process by which changes to a primary database are reproduced on a secondary database. 数据同步涉及主数据库将事务日志记录发送到辅助数据库。Data synchronization involves the primary database sending transaction log records to the secondary database.

重要

可用性数据库在 Transact-SQLTransact-SQL、PowerShell 和 SQL Server 管理对象 (SMO) 名称中有时候被称作“数据库副本” 。An availability database is sometimes called a database replica in Transact-SQLTransact-SQL, PowerShell, and SQL Server Management Objects (SMO) names. 例如,“数据库副本”一词用于返回与可用性数据库有关的信息的 AlwaysOn 动态管理视图的名称中:sys.dm_hadr_database_replica_statessys.dm_hadr_database_replica_cluster_statesFor example, the term "database replica" is used in the names of the Always On dynamic management views that return information about availability databases: sys.dm_hadr_database_replica_states and sys.dm_hadr_database_replica_cluster_states. 但在 SQL Server 联机丛书中,“副本”一词通常表示可用性副本。However, in SQL Server Books Online, the term "replica" typically refers to availability replicas. 例如,“主副本”和“辅助副本”始终表示可用性副本。For example, "primary replica" and "secondary replica" always refer to availability replicas.

可用性副本Availability Replicas

每个可用性组定义一个包含两个或更多故障转移伙伴(称为可用性副本)的集合。Each availability group defines a set of two or more failover partners known as availability replicas. “可用性副本”是可用性组的组件。Availability replicas are components of the availability group. 每个可用性副本都承载可用性组中的可用性数据库的一个副本。Each availability replica hosts a copy of the availability databases in the availability group. 对于某个给定可用性组,可用性副本必须位于某一 WSFC 群集的不同节点上的单独 SQL ServerSQL Server 实例上。For a given availability group, the availability replicas must be hosted by separate instances of SQL ServerSQL Server residing on different nodes of a WSFC cluster. 必须为 AlwaysOn 启用这些服务器实例中的每个实例。Each of these server instances must be enabled for Always On.

对于每个可用性组,一个给定实例只能承载一个可用性副本。A given instance can host only one availability replica per availability group. 但是,每个实例可用于多个可用性组。However, each instance can be used for many availability groups. 给定的实例可以是独立实例或 SQL ServerSQL Server 故障转移群集实例 (FCI)。A given instance can be either a stand-alone instance or a SQL ServerSQL Server failover cluster instance (FCI). 如果您要求服务器级别的冗余,则使用故障转移群集实例。If you require server-level redundancy, use Failover Cluster Instances.

每个可用性副本都被分配一个初始角色(“主角色”或“辅助角色”),角色由该副本的可用性数据库继承 。Every availability replica is assigned an initial role-either the primary role or the secondary role, which is inherited by the availability databases of that replica. 给定副本的角色确定它承载的是读写数据库还是只读数据库。The role of a given replica determines whether it hosts read-write databases or read-only databases. 其中一个副本(称为“主要副本” )被分配主角色,它承载读写数据库(称为“主数据库” )。One replica, known as the primary replica, is assigned the primary role and hosts read-write databases, which are known as primary databases. 至少一个其他副本(称为“辅助副本” )被分配辅助角色。At least one other replica, known as a secondary replica, is assigned the secondary role. 辅助副本承载只读数据库(称为辅助数据库)。A secondary replica hosts read-only databases, known as secondary databases.

备注

如果可用性副本的角色是不确定的(如在故障转移过程中),则其数据库将临时处于 NOT SYNCHRONIZING 状态。When the role of an availability replica is indeterminate, such as during a failover, its databases are temporarily in a NOT SYNCHRONIZING state. 其角色设置为 RESOLVING,直至可用性副本的角色已解析。Their role is set to RESOLVING until the role of the availability replica has resolved. 如果可用性副本解析为主角色,则其数据库将成为主数据库。If an availability replica resolves to the primary role, its databases become the primary databases. 如果可用性副本解析为辅助角色,则其数据库将成为辅助数据库。If an availability replica resolves to the secondary role, its databases become secondary databases.

可用性模式Availability Modes

可用性模式是每个可用性副本的一个属性。The availability mode is a property of each availability replica. 可用性模式确定主副本是否在给定的辅助副本将事务日志记录写入磁盘(强制写入日志)之前,等待提交数据库上的事务。The availability mode determines whether the primary replica waits to commit transactions on a database until a given secondary replica has written the transaction log records to disk (hardened the log). Always On 可用性组Always On availability groups 支持两种可用性模式:“异步提交模式”和“同步提交模式” 。supports two availability modes-asynchronous-commit mode and synchronous-commit mode.

  • 异步提交模式Asynchronous-commit mode

    使用此可用性模式的可用性副本称为“异步提交副本” 。An availability replica that uses this availability mode is known as an asynchronous-commit replica. 在异步提交模式下,主副本无需等待确认异步提交辅助副本已硬化日志,便可提交事务。Under asynchronous-commit mode, the primary replica commits transactions without waiting for acknowledgement that an asynchronous-commit secondary replica has hardened the log. 异步提交模式可最大限度地减少辅助数据库上的事务滞后时间,但允许它们滞后于主数据库,因此可能会导致某些数据丢失。Asynchronous-commit mode minimizes transaction latency on the secondary databases but allows them to lag behind the primary databases, making some data loss possible.

  • 同步提交模式Synchronous-commit mode

    使用此可用性模式的可用性副本称为“同步提交副本” 。An availability replica that uses this availability mode is known as a synchronous-commit replica. 在同步提交模式下,在提交事务之前,同步提交主副本要等待同步提交辅助副本确认它已完成硬化日志。Under synchronous-commit mode, before committing transactions, a synchronous-commit primary replica waits for a synchronous-commit secondary replica to acknowledge that it has finished hardening the log. 同步提交模式可确保在给定的辅助数据库与主数据库同步时,充分保护已提交的事务。Synchronous-commit mode ensures that once a given secondary database is synchronized with the primary database, committed transactions are fully protected. 这种保护的代价是延长事务滞后时间。This protection comes at the cost of increased transaction latency.

有关详细信息,请参阅 可用性模式(AlwaysOn 可用性组)For more information, see Availability Modes (Always On Availability Groups).

故障转移类型Types of Failover

在主副本和辅助副本之间的对话上下文中,通过称为“故障转移” 的过程,主角色和辅助角色是潜在可互换的。Within the context of a session between the primary replica and a secondary replica, the primary and secondary roles are potentially interchangeable in a process known as failover. 在故障转移期间,目标辅助副本转换为主角色,成为新的主副本。During a failover the target secondary replica transitions to the primary role, becoming the new primary replica. 新的主副本使其数据库作为主数据库联机,而客户端应用程序可以连接到这些数据库。The new primary replica brings its databases online as the primary databases, and client applications can connect to them. 如果以前的主副本可用,则它将转换为辅助角色,成为辅助副本。When the former primary replica is available, it transitions to the secondary role, becoming a secondary replica. 以前的主数据库成为辅助数据库,且数据同步恢复。The former primary databases become secondary databases and data synchronization resumes.

有三种故障转移形式:自动、手动和强制(可能造成数据丢失)。Three forms of failover exist-automatic, manual, and forced (with possible data loss). 给定辅助副本支持的故障转移形式取决于其可用性模式,对于同步提交模式来说,取决于主副本和目标辅助副本的故障转移模式,如下所示。The form or forms of failover supported by a given secondary replica depends on its availability mode, and, for synchronous-commit mode, on the failover mode on the primary replica and target secondary replica, as follows.

  • 同步提交模式支持两种故障转移形式:“计划的手动故障转移”和“自动故障转移”(如果目标次要副本当前与主副本同步) 。Synchronous-commit mode supports two forms of failover-planned manual failover and automatic failover, if the target secondary replica is currently synchronized with the primary replica. 对这些故障转移形式的支持取决于故障转移伙伴上的“故障转移模式属性” 的设置。The support for these forms of failover depends on the setting of the failover mode property on the failover partners. 如果在主副本或辅助副本上将故障转移模式设置为“手动”,则对于该辅助副本仅支持手动故障转移。If failover mode is set to "manual" on either the primary or secondary replica, only manual failover is supported for that secondary replica. 如果同时在主副本和辅助副本上将故障转移模式设置为“自动”,则该辅助副本同时支持自动故障转移和手动故障转移。If failover mode is set to "automatic" on both the primary and secondary replicas, both automatic and manual failover are supported on that secondary replica.

    • 计划的手动故障转移 (无数据丢失)Planned manual failover (without data loss)

      手动故障转移在数据库管理员发出故障转移命令之后发生,它将导致已同步的辅助副本转换为主角色(同时确保数据受到保护),而主副本转换为辅助角色。A manual failover occurs after a database administrator issues a failover command and causes a synchronized secondary replica to transition to the primary role (with guaranteed data protection) and the primary replica to transition to the secondary role. 手动故障转移要求主副本和目标辅助副本都在同步提交模式下运行,并且辅助副本必须已同步。A manual failover requires that both the primary replica and the target secondary replica are running under synchronous-commit mode, and the secondary replica must already be synchronized.

    • 自动故障转移 (无数据丢失)Automatic failover (without data loss)

      自动故障转移是为了响应导致已同步的辅助副本转换为主角色(同时确保数据受到保护)的故障而执行的。An automatic failover occurs in response to a failure that causes a synchronized secondary replica to transition to the primary role (with guaranteed data protection). 如果以前的主副本变为可用,则它将转换为辅助角色。When the former primary replica becomes available, it transitions to the secondary role. 自动故障转移要求主副本和目标辅助副本都在同步提交模式下运行,并且故障转移模式设置为“自动”。Automatic failover requires that both the primary replica and the target secondary replica are running under synchronous-commit mode with the failover mode set to "Automatic". 此外,次要副本必须已同步并具有 WSFC 仲裁,且满足由可用性组的 灵活故障转移策略指定的条件。In addition, the secondary replica must already be synchronized, have WSFC quorum, and meet the conditions specified by the flexible failover policyof the availability group.

      重要

      SQL Server 故障转移群集实例 (FCI) 不支持通过可用性组来自动进行故障转移,因此,只能为手动故障转移配置任何由 FCI 承载的可用性副本。SQL Server Failover Cluster Instances (FCIs) do not support automatic failover by availability groups, so any availability replica that is hosted by an FCI can only be configured for manual failover.

    备注

    请注意,如果对已同步的辅助副本发出强制故障转移命令,则辅助副本的行为与计划的手动故障转移时的行为相同。Note that if you issue a forced failover command on a synchronized secondary replica, the secondary replica behaves the same as for a planned manual failover.

  • 在异步提交模式下,唯一的故障转移形式为强制手动故障转移(可能造成数据丢失),通常称作“强制故障转移” 。Under asynchronous-commit mode, the only form of failover is forced manual failover (with possible data loss), typically called forced failover. 强制故障转移被认为是一种手动故障转移,因为它只能手动启动。Forced failover is considered a form of manual failover because it can only be initiated manually. 强制故障转移是一个灾难恢复选项。Forced failover is a disaster recovery option. 当目标辅助副本与主副本不同步时,强制故障转移是唯一可能的故障转移形式。It is the only form of failover that is possible when the target secondary replica is not synchronized with the primary replica.

有关详细信息,请参阅 故障转移和故障转移模式(AlwaysOn 可用性组)概念。For more information, see Failover and Failover Modes (Always On Availability Groups).

客户端连接Client Connections

您可以通过创建一个可用性组侦听器来提供到给定可用性组的主副本的客户端连接。You can provide client connectivity to the primary replica of a given availability group by creating an availability group listener. “可用性组侦听器” 提供一组附加到给定可用性组的资源,以便将客户端连接定向到相应的可用性副本。An availability group listener provides a set of resources that is attached to a given availability group to direct client connections to the appropriate availability replica.

一个可用性组侦听器与一个唯一的 DNS 名称(用作虚拟网络名称 (VNN))、一个或多个虚拟 IP 地址 (VIP) 和一个 TCP 端口号关联。An availability group listener is associated with a unique DNS name that serves as a virtual network name (VNN), one or more virtual IP addresses (VIPs), and a TCP port number. 有关详细信息,请参阅 可用性组侦听程序、客户端连接和应用程序故障转移 (SQL Server)概念。For more information, see Availability Group Listeners, Client Connectivity, and Application Failover (SQL Server).

提示

如果一个可用性组仅拥有两个可用性副本,并且未配置为允许对次要副本进行读访问,则客户端可以通过使用 数据库镜像连接字符串连接到主要副本。If an availability group possesses only two availability replicas and is not configured to allow read-access to the secondary replica, clients can connect to the primary replica by using a database mirroring connection string. 从数据库镜像将数据库迁移到 Always On 可用性组Always On availability groups之后,这种方法暂时非常有用。This approach can be useful temporarily after you migrate a database from database mirroring to Always On 可用性组Always On availability groups. 在添加其他辅助副本之前,您需要为该可用性组创建一个可用性组侦听器,并更新您的应用程序以使用该侦听器的网络名称。Before you add additional secondary replicas, you will need to create an availability group listener the availability group and update your applications to use the network name of the listener.

活动辅助副本Active Secondary Replicas

Always On 可用性组Always On availability groups 支持活动辅助副本。supports active secondary replicas. 活动辅助功能包括对以下方面的支持:Active secondary capabilities include support for:

  • 对辅助副本执行备份操作Performing backup operations on secondary replicas

    次要副本支持对完整数据库、文件或文件组执行日志备份和 仅复制 备份。The secondary replicas support performing log backups and copy-only backups of a full database, file, or filegroup. 您可以配置可用性组,以便为备份指定一个首选位置。You can configure the availability group to specify a preference for where backups should be performed. 理解 SQL Server 不强制使用首选备份位置十分重要,因为它对即席备份没有影响。It is important to understand that the preference is not enforced by SQL Server, so it has no impact on ad-hoc backups. 对此首选备份位置的解释取决于您为给定可用性组中的每个数据库撰写作业脚本的逻辑(如果有)。The interpretation of this preference depends on the logic, if any, that you script into your back jobs for each of the databases in a given availability group. 对于单独的可用性副本,您可以指定对此副本(相对于同一可用性组中其他副本)执行备份的优先级。For an individual availability replica, you can specify your priority for performing backups on this replica relative to the other replicas in the same availability group. 有关详细信息,请参阅活动次要副本:次要副本备份(Always On 可用性组)For more information, see Active Secondaries: Backup on Secondary Replicas (Always On Availability Groups).

  • 对一个或多个辅助副本(可读辅助副本)的只读访问权限Read-only access to one or more secondary replicas (readable secondary replicas)

    可以对任何次要可用性副本进行配置,以便仅允许对其本地数据库进行只读访问,尽管不会完全支持某些操作。Any secondary availability replica can be configured to allow only read-only access to its local databases, though some operations are not fully supported. 这会阻止对次要副本进行读写连接尝试。This will prevent read-write connection attempts to the secondary replica. 还可以通过仅允许进行读写访问来阻止主要 副本上的只读工作负载。It is also possible to prevent read-only workloads on the primary replica by only allowing read-write access. 这会阻止对主要副本建立只读连接。This will prevent read-only connections from being made to the primary replica. 有关详细信息,请参阅活动次要副本:可读次要副本(Always On 可用性组)For more information, see Active Secondaries: Readable Secondary Replicas (Always On Availability Groups).

    如果某一可用性组当前拥有一个可用性组侦听程序以及一个或多个可读次要副本,则 SQL ServerSQL Server 可以将读意向连接请求路由到其中一个可读次要副本(只读路由)。If an availability group currently possesses an availability group listener and one or more readable secondary replicas, SQL ServerSQL Server can route read-intent connection requests to one of them (read-only routing). 有关详细信息,请参阅 可用性组侦听程序、客户端连接和应用程序故障转移 (SQL Server)概念。For more information, see Availability Group Listeners, Client Connectivity, and Application Failover (SQL Server).

会话超时期限Session-Timeout Period

会话超时期限是一个可用性副本属性,它决定在连接关闭前与另一个可用性副本的连接可处于不活动状态多长时间。The session-timeout period is an availability-replica property that determines how long connection with another availability replica can remain inactive before the connection is closed. 主副本和辅助副本相互 ping 以表示它们还处于活动状态。The primary and secondary replicas ping each other to signal that they are still active. 在超时期限内从其他副本收到 ping 指示连接仍是打开的,且服务器实例正在进行通信。Receiving a ping from the other replica during the timeout period indicates that the connection is still open and that the server instances are communicating. 收到 ping 后,可用性副本将重置此连接的会话超时计数器。On receiving a ping, an availability replica resets its session-timeout counter on that connection.

会话超时期限防止副本无限制等待接收来自另一个副本的 ping。The session-timeout period prevents either replica from waiting indefinitely to receive a ping from the other replica. 如果在会话超时期限内没有收到来自另一个副本的 ping,该副本将超时。连接将关闭,超时的副本进入 DISCONNECTED 状态。If no ping is received from the other replica within the session-timeout period, the replica times out. Its connection is closed, and the timed-out replica enters the DISCONNECTED state. 即使为同步提交模式配置了断开连接的副本,事务也将不等待该副本重新连接和重新同步。Even if a disconnected replica is configured for synchronous-commit mode, transactions will not wait for that replica to reconnect and resynchronize.

每个可用性副本的默认会话超时期限为 10 秒。The default session-timeout period for each availability replica is 10 seconds. 用户可配置此值,最小值为 5 秒。This value is user-configurable, with a minimum of 5 seconds. 通常我们建议您将超时期限保持为 10 秒或更长。Generally, we recommend that you keep the time-out period at 10 seconds or greater. 如果将值设置为低于 10 秒,则可能使高负荷系统声明虚假故障。Setting the value to less than 10 seconds creates the possibility of a heavily loaded system declaring a false failure.

备注

在“正在解析”角色中,会话超时期限不适用,因为不进行 ping。In the resolving role, the session-timeout period does not apply because pinging does not occur.

自动页修复Automatic Page Repair

每个可用性副本都通过解决阻止读取数据页的一定类型的错误,自动尝试从本地数据库上损坏的页中恢复。Each availability replica tries to automatically recover from corrupted pages on a local database by resolving certain types of errors that prevent reading a data page. 如果辅助副本无法读取某页,则该副本从主副本请求该页的新副本。If a secondary replica cannot read a page, the replica requests a fresh copy of the page from the primary replica. 如果主副本无法读取某页,该副本将向所有辅助副本广播索取新副本的请求,并从响应的第一个副本中获取该页。If the primary replica cannot read a page, the replica broadcasts a request for a fresh copy to all the secondary replicas and gets the page from the first to respond. 如果此请求成功,则将以新副本替换不可读的页,这通常会解决该错误。If this request succeeds, the unreadable page is replaced by the copy, which usually resolves the error.

有关详细信息,请参阅自动页修复(可用性组:数据库镜像)For more information, see Automatic Page Repair (Availability Groups: Database Mirroring).

相关任务Related Tasks

相关内容Related Content

另请参阅See Also

可用性模式(AlwaysOn 可用性组) Availability Modes (Always On Availability Groups)
故障转移和故障转移模式(AlwaysOn 可用性组) Failover and Failover Modes (Always On Availability Groups)
AlwaysOn 可用性组的 Transact-SQL 语句概述 (SQL Server) Overview of Transact-SQL Statements for Always On Availability Groups (SQL Server)
AlwaysOn 可用性组的 PowerShell Cmdlet 概述 (SQL Server) Overview of PowerShell Cmdlets for Always On Availability Groups (SQL Server)
对内存中 OLTP 数据库的高可用性支持 High Availability Support for In-Memory OLTP databases
针对 AlwaysOn 可用性组的先决条件、限制和建议 (SQL Server) Prerequisites, Restrictions, and Recommendations for Always On Availability Groups (SQL Server)
创建和配置可用性组 (SQL Server) Creation and Configuration of Availability Groups (SQL Server)
活动次要副本:可读次要副本(Always On 可用性组) Active Secondaries: Readable Secondary Replicas (Always On Availability Groups)
活动次要副本:次要副本备份(AlwaysOn 可用性组) Active Secondaries: Backup on Secondary Replicas (Always On Availability Groups)
可用性组侦听程序、客户端连接和应用程序故障转移 (SQL Server)Availability Group Listeners, Client Connectivity, and Application Failover (SQL Server)