问题:
用户早上反馈应用程序连不上数据库,手动将Always on可用性组切换到辅助副本后正常。然后用户想要知道是什么原因应用程序连不上数据库。
检查SQL Server错误日志时发现06/04/2021 08:16:47开始出现下面的日志,Always on可用性组处于RESOLVING状态。
06/04/2021 08:16:47,Server,Unknown,The state of the local availability replica in availability group 'Team_AG' has changed from 'PRIMARY_NORMAL' to 'RESOLVING_NORMAL'. The state changed because the lease between the local availability replica and Windows Server Failover Clustering (WSFC) has expired. For more information<c/> see the SQL Server error log<c/> Windows Server Failover Clustering (WSFC) management console<c/> or WSFC log.
06/04/2021 08:16:47,Server,Unknown,Always On: The local replica of availability group 'Team_AG' is going offline because either the lease expired or lease renewal failed. This is an informational message only. No user action is required.
06/04/2021 08:16:47,Server,Unknown,The lease between availability group 'Team_AG' and the Windows Server Failover Cluster has expired. A connectivity issue occurred between the instance of SQL Server and the Windows Server Failover Cluster. To determine whether the availability group is failing over correctly<c/> check the corresponding availability group resource in the Windows Server Failover Cluster.
06/04/2021 08:16:47,Server,Unknown,Error: 19407<c/> Severity: 16<c/> State: 1.
06/04/2021 08:16:47,Server,Unknown,SQL Server hosting availability group 'Team_AG' did not receive a process event signal from the Windows Server Failover Cluster within the lease timeout period.
06/04/2021 08:16:47,Server,Unknown,Error: 19421<c/> Severity: 16<c/> State: 1.
原因分析:
1)租约超时原因 - SQL Server 转储诊断
SQL Server 可能会检测到内部运行状况问题,例如访问冲突或死锁调度程序,并通过生成 SQL Server 进程的小型转储文件进行响应以进行诊断。在将小型转储写入磁盘时,这会“冻结”SQL Server 数秒。在此期间,SQL Server 进程中的所有线程都处于“冻结”状态,包括 SQL Server 资源 DLL 监视的租用线程,从而导致租用超时。
2)租约超时原因 - 100 % CPU 利用率
如果 CPU 利用率在一段时间内非常高,这可能会导致租用超时。
以上两种可能都会导致租约到期,导致Always ON角色处于RESOLVING状态。根据用户数据库的实际情况是,每天早上刚上班的时候,大量用户同时使用系统,导致数据库服务器CPU使用率经常100%的现象。由于没有监控,推测是CPU使用率100%导致的。(因为手工切换到辅助副本后,监控CPU使用率还是可以看到经常100%的现象)
解决方案:
检查数据库的配置,发现max degree of parallelism的值为0,也就是不限制。cost threshold for parallelism的值为3,默认值为5,调整为3,说明数据库很容易出现并行的情况。
建议将cost threshold for parallelism的值调高,此处调整为50了。调整后服务器的CPU使用率降至80%以下。
或者将max degree of parallelism的值调整为1,使数据库不并行。
或者通过下面方法减轻租约超时的现象
暂时调整可用性组租用超时属性,同时研究和解决 SQL Server 转储诊断报告的问题。
- 启动故障转移群集管理器。
- 在左窗格中,单击角色。
- 在中间窗格中,右键单击可用性组群集资源,然后单击属性。
- 单击“属性”选项卡并以毫秒为单位增加 LeaseTimeout。最大值为 100,000 毫秒。




