SQL 2014新功能介绍系列9 - AlwaysOn 可用性组

AlwaysOn对于SQL Server 2014已经不再是新名词,现在也有越来越多的客户还是使用并且钟情于AlwaysOn。它继承了数据库镜像和故障转移群集的优点,使得SQL Server具有更好的高可用性。在SQL 2014中AlwaysOn的特性有哪些加强呢?

1. 和Hekaton (In-memory OLTP)相结合

In-memory OLTP是SQL 2014中最闪亮的新特性了, 而AlwaysOn也同样可以很好地兼容他。你可以在已经定义在AlwaysOn的Availability Group的数据库中启用Memory-optimized table,不过需要注意以下几点:

1) 对于Non-durable memory-optimized tables,如果定义在了AlwaysOn的数据库中,只会将架构同步到Secondary副本上,而不会同步数据

2) 当数据库服务重新启动时,Memory-optimized table会被初始化,整个数据表会载入到内存中,并创建响应的索引。这段过程可能会造成AlwaysOn数据同步的延迟。

2. Secondary副本增加到9个(包括primary副本)

3. 可读Secondary的功能加强

在SQL 2012中,连接到Secondary副本的只读连接会因为以下网络原因而中断:

  • Geo-distributed environment 跨地理环境
  • Hybrid Deployments 混合部署
  • Quorum Lost 仲裁丢失

这时Secondary副本会处于RESOLIVING状态,只读连接中断。

在SQL 2014中,当发生上述问题时,secondary副本还是会被置成RESOLVING状态,但是:

  • 只读连接会被保留而不中断
  • 对Listener的自动定向路由功能不支持,但是可以通过直连方式连到Primary副本。
  • 在Secondary副本上还是可以检查一些DMV,来确定目前处于RESOLVING状态下的AlwaysOn的同步状态

4. 增加了Azure副本的支持

  • 可以将AlwaysOn副本放在Windows Azure SQL Database上
  • 可以自动或手动完成从本地OnPremise到云端Azure的AlwaysOn切换

 

5. SQL Server AlwaysOn支持Windows Cluster Shared Volume(CSV)

  • 不再有24个盘符的限制
  • 提升了I/O读写的灵活性
  • 提升了故障切换的灵活性(磁盘不在需要Mounted/Unmounted)

6. SQL Server AlwaysOn 故障排查相关的提升

  • SQL Server 2012 XEL Log Reader会自动把XEL log变成机器的本地时间,这和ERRORLOG,cluster的时间转换会变得很麻烦。SQL Server 2014直接可以查看UTC时间,使得故障排查更加方便。

  • 可以通过新引入的函数sys.fn_hadr_is_primary_replica([database_name]) 来检查当前节点是不是primary节点

  • 在SQL 2012时,Message 32566只显示了连接中断时的Replica ID,这个很难去确认具体是哪一个replica。需要到sys.availability_replicas检查并匹配,才可以确认。在SQL 2014中,添加了Replica的名字,方便确认。 

  • 在SQL 2014中,当replica发生角色转换时,比如转成Secondary或Resolving,都会记录Hardened Lsn,Commit LSN,Commit Time,这样可以方便确认数据的同步情况

  • 在SQL 2014中,如果AlwaysOn的启动是通过/FORCEQUORUM办法来操作的话,会有特别的信息记录。这样可以方便确认AlwaysOn的启动是否使用了Force Quorum

  • 在SQL Server 2012中,对于AlwaysOn Group处于Resolving状态的原因显示的非常模糊,只提供了所有的可能性,但是没有提供具体明确的原因。这给故障排查带来一定的难度。

2014-03-11 08:41:53.20 spid12s The state of the local availability replica in availability group 'ag1' has changed from 'NOT_AVAILABLE' to 'RESOLVING_NORMAL'. The replica state changed because of either a startup, a failover, a communication issue, or a cluster error. For more information, see the availability group dashboard, SQL Server error
log, Windows Server Failover Cluster management console or Windows Server Failover Cluster log.

2014-03-11 09:20:39.83 spid57 The state of the local availability replica in availability group 'ag1' has changed from 'PRIMARY_NORMAL' to 'RESOLVING_NORMAL'. The replica state changed because of either a startup, a failover, a communication issue, or a cluster error. For more information, see the availability group dashboard, SQL Server error log,
Windows Server Failover Cluster management console or Windows Server Failover Cluster log.

在SQL Server 2014中,明确了每一次AlwaysOn Group变成Resolving而导致不可用/可用的原因。 

2014-03-11 10:50:27.95 spid20s The state of the local availability replica in availability group 'agnew' has changed from 'NOT_AVAILABLE' to 'RESOLVING_NORMAL'. The state changed because the local instance of SQL Server is starting up. For more information, see the SQL Server error log, Windows Server Failover Clustering (WSFC) management console, or WSFC log.

2014-03-11 12:18:16.57 spid62 The state of the local availability replica in availability group 'agnew' has changed from 'PRIMARY_NORMAL' to 'RESOLVING_NORMAL'. The state changed because the availability group is going offline. The replica is going offline because the associated availability group has been deleted, or the user has taken the associated availability group offline in Windows Server Failover Clustering (WSFC) management console, or the availability group is failing over to another SQL Server instance. For more information, see the SQL Server error log, Windows Server Failover Clustering (WSFC) management console, or WSFC log.

这是我们SQL 2014新功能介绍系列的最后一篇文章,希望对您有所帮助。更多SQL Server内容请持续关注本博客。