always on_Always On可用性组中的自动播种

SQL Server 2016引入了一种新的数据库同步方法——自动播种,用于Always On Availability Groups。此功能在主副本上执行完整数据库备份并通过网络流式传输到辅助副本,从而简化大型数据库的添加过程。通过启用跟踪标志9657,可以启用压缩以优化大型数据库的同步。在添加数据库时,应确保所有副本上都有相同的目录和足够的磁盘空间。通过动态管理视图、Windows Performance Monitor和扩展事件,可以监视自动播种的进度和性能。
摘要由CSDN通过智能技术生成

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 跳过初始数据同步:如果我们要手动执行所有数据库备份,在每个辅助副本上还原它们,然后在辅助副本上手动加入它们,则可以选择此选项

Initial Data Synchronization wizard in SSMS

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版本。

Automatic Seeding in Initial Data Synchronization wizard

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.

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

Introuction Wizard

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.

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

Select Automatic Seeding Option

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)

Validation error

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.

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

Successful validation

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.

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

Message after adding database into Always on Availaibilty Group

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备份时,您需要在主副本上运行以下命令以检查备份状态

SELECT
 r.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 s
 ON 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命令正在执行备份,并且可以跟踪备份完成百分比。

VDI backup in Automatic seeding for  Always On Availability Groups

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操作的状态。

SELECT
 r.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 s
 ON 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已启用压缩。

Dynamic Management View output

使用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

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

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

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

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:显示物理播种进度

Extended event session

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日志来监视自动播种的进度。

Monitor Extended event session output

关于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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值