always on

介绍 (Introduction)

In SQL Server Always On Availability Groups, we can add a database into an existing availability group using different methods. We get the following option in the Initial Data Synchronization wizard in SSMS.

在SQL Server始终可用的可用性组中,我们可以使用不同的方法将数据库添加到现有的可用性组中。 我们在SSMS的“初始数据同步”向导中获得以下选项。

  • Full Database and Log backup: It starts data synchronization by taking full and log backup for the availability group database. It restores these backups into each secondary replica and joins them to the availability group 完整数据库和日志备份 :它通过对可用性组数据库进行完整和日志备份来启动数据同步。 它将这些备份还原到每个辅助副本中,并将它们加入可用性组。
  • Join Only: If we have taken manual backups and restored them on the secondary server, we can use the Join Only method to add a database into an availability group 仅连接:如果我们已进行了手动备份并将其还原到辅助服务器上,则可以使用“仅连接”方法将数据库添加到可用性组中。
  • Skip Initial data synchronization: If we want to perform all database backup manually, restore them on each secondary replica, and join them manually on the secondary replica, we can select this option 跳过初始数据同步:如果我们要手动执行所有数据库备份,在每个辅助副本上还原它们,然后在辅助副本上手动加入它们,则可以选择此选项

Usually, DBA follows up the method Join Only after restoring the backups manually on each secondary replica. This approach is suitable for large databases as well.

通常,在每个辅助副本上手动还原备份之后,DBA都会采用仅连接方法。 这种方法也适用于大型数据库。

SQL Server 2016 introduces a new data synchronization method for databases in Always On Availability Groups – Automatic Seeding or direct seeding

SQL Server 2016为Always On可用性组中的数据库引入了一种新的数据同步方法- 自动 播种直接 播种

You need to connect SQL Server 2016 or later with SQL Server Management Studio 17.4 or later to see this option. You can still use this feature with the old SSMS version but not with the GUI method. I would recommend installing the latest SSMS version.

您需要将SQL Server 2016或更高版本与SQL Server Management Studio 17.4或更高版本连接才能看到此选项。 您仍然可以在旧版SSMS上使用此功能,但不能在GUI方法上使用。 我建议安装最新的SSMS版本。

In the previous article, SQL Server 2016 Always On Availability Group with Direct Seeding you can take an overview of automatic seeding configuration in Always On Availability Groups using t-SQL scripts. In this article, we will look at a few more aspects along with the GUI method of adding a database into AG.

在上一篇文章SQL Server 2016具有直接播种的Always On可用性组中,您可以使用t-SQL脚本概述AlwaysOn可用性组中的自动播种配置。 在本文中,我们将探讨更多方面以及将数据库添加到AG的GUI方法。

Environment prerequisites:

环境先决条件:

  • SQL Server 2016 or latest version SQL Server 2016或最新版本
  • SSMS 17.4 or later SSMS 17.4或更高版本
  • A database should have a full database backup to meet prerequisites at the database level. If you created a new database, take a full back up before proceeding for the next step 数据库应具有完整的数据库备份,以满足数据库级别的先决条件。 如果创建了新数据库,请进行完整备份,然后再继续下一步

在自动播种中为始终在线的可用性组启用跟踪标志以进行压缩 (Enable Trace Flag for compression in Automatic Seeding for Always On Availability Groups)

By default, compression is not enabled for the automatic seeding streaming. We can leverage trace flag 9657 to enable the compression. It is essentially good for large databases. You might notice an increase in the CPU of the primary replica.

默认情况下,自动播种流不启用压缩。 我们可以利用跟踪标志9657启用压缩。 对于大型数据库,它本质上是好的。 您可能会注意到主副本的CPU增加。

We can enable this trace flag either as a startup parameter or using DBCC TRACEON command. Execute the following command to enable the trace flag at a global level.

我们可以将此跟踪标志作为启动参数或使用DBCC TRACEON命令来启用。 执行以下命令以在全局级别启用跟踪标志。

DBCC TRACEON (9567,-1)

DBCC TRACEON(9567,-1)

If you want to add as a startup parameter, go to SQL Server Configuration Manager and open SQL Server Service properties. In the properties windows, go to startup parameter and add the trace flag

如果要添加为启动参数,请转到“ SQL Server配置管理器”并打开“ SQL Server服务”属性。 在属性窗口中,转到启动参数并添加跟踪标志

使用自动播种为Always On可用性组在AG中添加数据库的步骤 (Steps to add a database in AG using automatic seeding for Always On Availability Groups)

We can use the following steps to add a database in SQL Server Always On using Automatic Seeding.

我们可以使用以下步骤使用自动播种在SQL Server Always On中添加数据库。

Connect to primary replica and Right click on the availability group and click on Add database. It launches a wizard to add the database into an availability group.

连接到主副本,然后右键单击可用性组,然后单击“ 添加数据库” 。 它启动一个向导以将数据库添加到可用性组。

Click on Next and select a database to add to the existing availability group. This database should have a full backup to meet the prerequisite for the Always On Availability Groups.

单击下一步,然后选择一个数据库以添加到现有可用性组。 此数据库应具有完整备份,以满足“始终在线”可用性组的先决条件。

Connect to your secondary replicas in the next screen and specify Initial Data Synchronization as Automatic Seeding.

在下一个屏幕中连接到辅助副本,并将“初始数据同步”指定为“ 自动播种”。

You should have similar directories at both the primary and all secondary replicas. If there is any mismatch or directory that does not exist in secondary replicas, you get the following error message.

您在主副本和所有辅助副本上都应具有相似的目录。 如果辅助副本中不存在任何不匹配或目录,则会出现以下错误消息。

The following required directories do not exist on replica DBTest : D:\DBTest,D:\DBTest. (Microsoft.SqlServer.Management.HadrModel)

副本DBTest上不存在以下必需目录:D:\ DBTest,D:\ DBTest。 (Microsoft.SqlServer.Management.HadrModel)

You should have sufficient free space in the secondary replica as well for database copy similar to the primary replica of Always On Availability Groups.

与Always Always Availability组的主副本类似,辅助副本中的数据库副本也应具有足够的可用空间。

If you have any issues in the secondary replica, you get an Error message. You should fix it and rerun validations.

如果辅助副本中有任何问题,则会收到一条错误消息。 您应该修复它并重新运行验证。

Once all the validations are successful for each secondary replica, click Next and it adds a database to the availability group. You get the following message.

对每个辅助副本的所有验证均成功后,单击“ 下一步” ,它将数据库添加到可用性组。 您收到以下消息。

The synchronization might take time depending upon the database size, network bandwidth, disk speed etc. You should monitor the status of automatic seeding, especially for the large databases.

同步可能需要一些时间,具体取决于数据库大小,网络带宽,磁盘速度等。您应该监视自动播种的状态,尤其是对于大型数据库。

Always On可用性组中自动播种和监视的内部 (Internal of Automatic Seeding and Monitoring in Always On Availability Groups)

SQL Server performs the following steps to add a database using Automatic Seeding.

SQL Server执行以下步骤以使用“自动种子”添加数据库。

  • SQL Server performs a full database backup using Microsoft SQL Server Virtual Device Interface (VDI) full database SQL Server使用Microsoft SQL Server虚拟设备接口(VDI)完整数据库执行完整数据库备份
  • This VDI database backup is streamed through the network to all available secondary replicas 此VDI数据库备份通过网络流式传输到所有可用的辅助副本
  • Secondary replica restores this streamed backup 辅助副本还原此流备份
  • Once the database restoration is complete, it is added into the availability group 数据库还原完成后,将其添加到可用性组中

Usually, we check the database backup status using the DMV sys.dm_exec_requests. If you run this command on primary replica and check for command specific to backup, you did not get any output for the backup.

通常,我们使用DMV sys.dm_exec_requests检查数据库备份状态。 如果在主副本上运行此命令并检查特定于备份的命令,则不会获得任何备份输出。

As it executes a VDI backup, you need to run the following command on Primary replica to check the status of backup

在执行VDI备份时,您需要在主副本上运行以下命令以检查备份状态

SELECTr.session_id, r.status, r.command, r.wait_type, r.percent_complete, r.estimated_completion_time
FROM sys.dm_exec_requests r JOIN sys.dm_exec_sessions sON r.session_id = s.session_id
WHERE r.session_id <> @@SPID
AND s.is_user_process = 0
AND r.command like 'VDI%'
and wait_type ='BACKUPTHREAD'

In the following screenshot, you can see VDI_Client_WORKER command is executing backup and you can track the backup percentage completion.

在以下屏幕截图中,您可以看到VDI_Client_WORKER命令正在执行备份,并且可以跟踪备份完成百分比。

On the secondary replica of Always On Availability Groups, you can run the following command to check the status of REDO operation.

在Always On可用性组的辅助副本上,可以运行以下命令来检查REDO操作的状态。

SELECTr.session_id, r.status, r.command, r.wait_type, r.percent_complete, r.estimated_completion_time
FROM sys.dm_exec_requests r JOIN sys.dm_exec_sessions sON r.session_id = s.session_id
WHERE r.session_id <> @@SPID
AND s.is_user_process = 0
AND r.command like 'REDO%'
and wait_type ='BACKUPTHREAD'

Let’s view a few other methods to monitor the Automatic Seeding.

让我们查看其他一些方法来监视“自动播种”。

使用动态管理视图 (Using Dynamic Management Views)

We can monitor the progress of Automatic Seeding for Always On Availability Groups using the following dynamic management views.

我们可以使用以下动态管理视图来监视Always On可用性组的自动播种进度。

  • Sys .dm_hard_automatic_seeding: We can use this DMV as a summary for all successful, fail automatic seed information for each database and replica. If there are multiple attempts, it counts the retry. We can also see the related error and failure codes in case the automatic seeding failed Sys .dm_hard_automatic_seeding:我们可以将此DMV用作每个数据库和副本的所有成功,失败自动种子信息的摘要。 如果有多次尝试,它将计入重试次数。 如果自动播种失败,我们还可以查看相关的错误和失败代码
  • Sys .dm_hard_physical_seeding_stats: This DMV is useful to get the current state of automatic seeding including the transfer rate, estimated completion time, database size, compression enabled or not Sys .dm_hard_physical_seeding_stats:该DMV可用于获取自动播种的当前状态,包括传输速率,估计完成时间,数据库大小,是否启用压缩

Let’s execute the DMV to check the seeding status from the primary replica.

让我们执行DMV来检查主副本的种子状态。

select local_database_name
, remote_machine_name,role_desc ,internal_state_desc
,transfer_rate_bytes_per_second/1024/1024 as transfer_rate_MB_per_second ,transferred_size_bytes/1024/1024 as transferred_size_MB
,database_size_bytes/1024/1024/1024/1024 as Database_Size_TB,
is_compression_enabled     from sys.dm_hadr_physical_seeding_stats

In the following screenshot, you can see two rows returned. I have three nodes Always On Availability Groups in my environment. SQL server transfers the streaming backup to both the secondary replicas. We can see is_compress_enabled is set to 1 that shows trace flag 9567 is enabled for compression.

在以下屏幕截图中,您可以看到返回了两行。 我的环境中有三个节点Always On可用性组。 SQL Server将流式备份传输到两个辅助副本。 我们可以看到is_compress_enabled设置为1,表明跟踪标志9567已启用压缩。

使用Windows Performance Monitor (Using Windows Performance Monitor)

You can also use performance monitor to get the information about the network speed during the automatic seeding. On the primary replica, use Bytes sent per the second parameter to check network speed.

您还可以使用性能监视器来获取有关自动播种期间网络速度的信息。 在主副本上,使用第二个参数发送的字节数检查网络速度。

Byte Sent per Second on primary Replica

主副本上每秒发送的字节数

Similarly, for a secondary replica in Always On Availability Groups, we can use bytes received per second performance parameter to check the network speed at the secondary replica end.

同样,对于Always On可用性组中的辅助副本,我们可以使用每秒接收的字节性能参数来检查辅助副本端的网络速度。

Byte Received per Second on Secondary Replica

辅助副本上每秒收到的字节数

使用扩展事件 (Using Extended Events)

We can configure useful extended event session to monitor automatic seeding progress in Always On Availability Groups with the following events

我们可以配置有用的扩展事件会话,以监视具有以下事件的Always On可用性组中的自动播种进度

  • hard_automatic_seeding_start: It captures the start of an automatic seeding operation hard_automatic_seeding_start:捕获自动播种操作的开始
  • hadr_automatic_seeding_state_transition: It occurs when an automatic seeding operation changes state hadr_automatic_seeding_state_transition:自动播种操作更改状态时发生
  • hadr_automatic_seeding_success: It occurs when an automatic seeding operation succeeds hadr_automatic_seeding_success:自动播种操作成功时发生
  • hadr_automatic_seeding_timeout: It occurs when an automatic seeding operation times out hadr_automatic_seeding_timeout:自动播种操作超时时发生
  • hard_physical_seeding_progress: It shows the physical Seeding Progress hard_physical_seeding_progress:显示物理播种进度

In the extended event session, you get useful information about the progress, transfer size, disk IO waits, network waits etc. You can also use SQL logs to monitor the progress of automatic seeding.

在扩展事件会话中,您可以获得有关进度,传输大小,磁盘IO等待,网络等待等的有用信息。您还可以使用SQL日志来监视自动播种的进度。

关于Always On可用性组中自动播种的要点 (Important Points about Automatic Seeding in Always On Availability Groups)

  • You can still use other initial data synchronization method in SQL Server Always On. You should decide which feature is most suitable for your environment 您仍然可以在SQL Server Always On中使用其他初始数据同步方法。 您应该确定最适合您的环境的功能
  • You cannot truncate the transaction log during the automatic seeding. It might result in significant transaction log growth during the progress of automatic seeding. You should consider this factor while planning for Always On Availability Groups synchronization using Automatic Seeding 您不能在自动播种期间截断事务日志。 在自动播种过程中,这可能会导致事务日志显着增长。 在计划使用“自动播种”的“始终在线”可用性组同步时,应考虑此因素
  • The database and log file path must be the same on primary and all secondary replicas 主副本和所有辅助副本上的数据库和日志文件路径必须相同
  • If the secondary replicas are at a remote site with limited network bandwidth, you should not use this feature 如果辅助副本位于网络带宽有限的远程站点,则不应使用此功能
  • You should also consider database size, load and transaction log growth on Primary replica to consider this method of initial synchronization 您还应该考虑主副本上的数据库大小,负载和事务日志增长,以考虑这种初始同步方法

结论 (Conclusion)

Automatic Seeding in Initial Data Synchronization is a useful feature. It might save a lot of DBA time by handling database backup, copy and restore automatically. You should explore this feature in your Always On Availability Groups environment.

初始数据同步中的自动播种是一项有用的功能。 通过自动处理数据库备份,复制和还原,可以节省大量DBA时间。 您应该在始终在线可用性组环境中探索此功能。

翻译自: https://www.sqlshack.com/automatic-seeding-in-always-on-availability-groups/

always on

always on_Always On可用性组中的自动播种相关推荐

  1. sql always on_Always On可用性组中具有发布者数据库SQL复制

    sql always on In this article, we will review how to setup SQL replication with publisher database i ...

  2. linux中mysql群集_阅读无群集可用性组中的Scale可用性组

    linux中mysql群集 In this article, we will explore configuring Read Scale Availability Group that does n ...

  3. Always On可用性组中SQL Server统计信息

    SQL Server统计信息简介 (Introduction to SQL Server Statistics) SQL Server Statistics are an essential part ...

  4. SQL Server Always On可用性组中的数据同步

    This article describes the data synchronization process on SQL Server Always On Availability Groups ...

  5. sql server父节点_将新节点添加到现有SQL Server Always On可用性组中

    sql server父节点 This is the 5th article in the series of a comprehensive guide to SQL Server Always On ...

  6. SQL Server Always On可用性组中的Windows故障转移群集仲裁模式

    This article gives an overview of Windows Failover Cluster Quorum modes that is necessary for SQL Se ...

  7. sql server高可用_SQL Server始终在线可用性组采访问题与解答

    sql server高可用 In this article, we will discuss a number of interview questions that you could be ask ...

  8. sql server只读_如何在SQL Server 2016中为可用性组配置只读路由

    sql server只读 The SQL Server Always On Availability Groups concept was introduced the first time in S ...

  9. Windows Server 2016上SQL Server Always On可用性组的全面指南

    In this article, we will configure a SQL Server Always On Availability Group on the Windows Server 2 ...

最新文章

  1. 推荐5款实用的jQuery时间轴插件
  2. OpenvSwitch代码分析之bridge和port
  3. HDU1506 Largest Rectangle in a Histogram(算竞进阶习题)
  4. datatables php数据,html5 - datatables 加载不出来数据。
  5. 任意输入一个整数反转输出
  6. 前端学习(2979):vue-element-admin结构always:true始终显示
  7. mysql rpm 启动_MySQL安装(rpm)和启动配置
  8. kafka集群为什么需要三个节点_大白话带你认识 Kafka
  9. elasticsearch亿级数据量全量索引导入优化方案
  10. JsonData工具类
  11. android网络动态获取权限,基于JetPack实现的权限动态获取
  12. SQL——联接分类和本质
  13. 面试问php学得怎么样,php面试常问的问题及回答
  14. js转义html,反转义
  15. WIN7系统下Mapgis6.7常见的两个问题及解决办法
  16. 雷达图分析法(转载)
  17. 最全面的Microsoft Office下载
  18. linux和windows下分别如何查看电脑是32位的还是64位?
  19. 全国计算机软考中级哪个科目最简单,软考中级哪个科目比较容易考?
  20. Layui动态渲染下拉框

热门文章

  1. output怎么用_这个功能QQ音乐,网易云音乐都有——用python实现一个音乐检索器...
  2. oracle ignore_Oracle 数据库常用操作语句,速速收藏
  3. c#养老院老人信息管理系统源码 论文_我市“老年人关爱服务体系建设”专题研究论文荣获第五届青年学者老龄论坛特等奖_社会民生_新闻频道...
  4. c语言关键字中文意思,C语言的32个关键字是什么意思啊
  5. deepin efi 启动u盘_如何安装Deepin国产操作系统?只需一个U盘就够了,超简单
  6. 10个 NPM 使用技巧
  7. Linux Ctrl+c与ctrl+z的区别
  8. UVa 1605 (构造) Building for UN
  9. Asp.Net递归遍历页面控件实例
  10. 【零基础学Java】—throw关键字(四十六)