In this guide, we’ll discuss more about migrating a SQL Server database to Azure SQL Database using SQL Server Transactional Replication.

在本指南中,我们将讨论有关使用SQL Server事务复制将SQL Server数据库迁移到Azure SQL数据库的更多信息。

With Azure SQL database, it is possible to replicate your on-premise database(s) with database(s) on the cloud in order to ensure application availability. In this article, we will see how we set up SQL Server transactional replication between an on-premise database and a database on Azure. We will deal with setting up SQL Server transactional replication—only supported feature of Azure SQL database.

使用Azure SQL数据库,可以将内部部署数据库与云上的数据库复制,以确保应用程序可用性。 在本文中,我们将了解如何在本地数据库和Azure上的数据库之间设置SQL Server事务复制。 我们将处理设置SQL Server事务复制-Azure SQL数据库仅受支持的功能。

数据库迁移 (Database Migration)

In this case, we are performing a database migration with a very short downtime using SQL Server transactional replication. I’ll discuss more in detail to setup and configure replication.

在这种情况下,我们将使用SQL Server事务复制在非常短的停机时间内执行数据库迁移。 我将详细讨论设置和配置复制。

  1. Note:注意:
  2. Only transactional replication is supported on Azure SQL Database. Other types such as Peer-to-peer or Merge Replication topology aren’t supported
  3. Azure SQL数据库仅支持事务复制。 不支持其他类型,例如点对点或合并复制拓扑
  4. Azure SQL database can only be used as a subscriber. Setting up publications is not allowed on Azure
  5. Azure SQL数据库只能用作订阅服务器。 在Azure上不允许设置发布

先决条件 (Prerequisites )

To be able to set up SQL Server transactional replication on Azure, you need to have some familiarity with Microsoft SQL Server Transactional Replication as well as the Azure SQL database cloud services.

为了能够在Azure上设置SQL Server事务复制,您需要熟悉Microsoft SQL Server事务复制以及Azure SQL数据库云服务。

版本号 (Versions)

It is mandatory that you meet the following requirements in order to set up SQL Server transactional replication on Microsoft Azure SQL Database.

为了在Microsoft Azure SQL数据库上设置SQL Server事务复制,必须满足以下要求。

    • SQL Server 2017 SQL Server 2017
    • SQL Server 2016 SQL Server 2016
    • SQL Server 2014 SP1 CU3 SQL Server 2014 SP1 CU3
    • SQL Server 2014 RTM CU10 SQL Server 2014 RTM CU10
    • SQL Server 2012 SP2 CU8 or SP3 SQL Server 2012 SP2 CU8或SP3
  • Use the latest versions of SQL Server Management Studio as well as SQL Server Data Tools in order to be able to use all the features of Azure SQL Database 使用最新版本SQL Server Management Studio以及SQL Server数据工具,以便能够使用Azure SQL数据库的所有功能
  • You can use SQL Server Management Studio to configure replication, or execute T-SQL statements on the publisher. Azure Portal cannot be used to configure replication
  • 您可以使用SQL Server Management Studio配置复制,或在发布服务器上执行T-SQL语句。 Azure门户不能用于配置复制
  • The only way you can authenticate on Azure for replication is use SQL Server authentication logins 您可以在Azure上进行复制身份验证的唯一方法是使用SQL Server身份验证登录名
  • Tables that are being replicated must have a primary key 要复制的表必须具有主键
  • Of course, you should already have an Azure subscription 当然,您应该已经有一个Azure订阅
  • The Azure SQL database subscriber is region-agnostic Azure SQL数据库订阅者与区域无关
  • You can use a single publication on SQL Server, to support both, Azure as well as SQL Server (on-premises and SQL Server in an Azure virtual machine) subscriptions 您可以在SQL Server上使用单个发布来支持Azure和SQL Server(本地和Azure虚拟机中SQL Server)订阅
  • The on-premise SQL Server must be used to manage, monitor and troubleshoot replication 本地SQL Server必须用于管理,监视复制并对其进行故障排除
  • Only push subscriptions to Azure are supported 仅支持对Azure的推送订阅
  • sp_addsubscription sp_addsubscription中仅支持@subscriber_type = 0
  • Bi-directional, immediate, updatable, or peer to peer replication are not supported by Azure SQL Database Azure SQL数据库不支持双向,即时,可更新或对等复制

数据库迁移方案 (Database Migration Scenario)

  1. Use SQL Server transactional replication to replicate data from your on-premise SQL Server database to Azure 使用SQL Server事务复制将数据从本地SQL Server数据库复制到Azure
  2. Redirect the client applications to update the Azure SQL database copy 重定向客户端应用程序以更新Azure SQL数据库副本
  3. Stop updating the SQL Server version of the table after the redirection by removing the publication 通过删除发布,重定向后停止更新表SQL Server版本

设置SQL Server事务复制 (Setting up SQL Server Transactional Replication)

Let’s set up SQL Server transactional replication to Azure. In this guide, I will use the Adventure Works database for setting up the replication from SQL Server to Azure SQL Database. You can download the adventureworks2016 sample database.

让我们设置SQL Server到Azure的事务复制。 在本指南中,我将使用Adventure Works数据库来设置从SQL Server到Azure SQL数据库的复制。 您可以下载Adventureworks2016示例数据库 。

In this article, I am going set up a SQL Server transactional replication by selecting a SQL Server 2016 as the publisher and distributor, and an Azure SQL Database as the subscriber. You can refer to the Prerequisites section for more details.

在本文中,我将通过选择SQL Server 2016作为发布者和分发者,并选择Azure SQL数据库作为订阅者来设置SQL Server事务复制。 您可以参考先决条件部分以了解更多详细信息。

First, let’s configure publisher and distributor on the SQL Server 2016 server. In the next section, you’ll see the steps to configure distributor.

首先,让我们在SQL Server 2016服务器上配置发布者和分发者。 在下一节中,您将看到配置分发服务器的步骤。

设定分布 (Setup Distribution)

The steps are no different than setting up a normal replication. You can refer to a previous article of mine to see the details about the distributor configuration.

这些步骤与设置普通复制没有什么不同。 您可以参考我的上一篇文章,以了解有关分发服务器配置的详细信息 。

Note: The default values are used in all pages. This way, it will be very easy and straight-forward to understand how to configure distribution database. You can then make changes according to your requirements, based on the understanding you gather this way.

注意:所有页面均使用默认值。 这样,将非常容易直接地了解如何配置分发数据库。 然后,您可以基于对这种方式的了解,根据需求进行更改。

  1. Browse Object Explorer and locate the Replication folder. Right-click and select Configure Distribution

    浏览对象资源管理器并找到复制文件夹。 右键单击并选择配置分发

  2. Next to proceed to the next window 下一步进入下一个窗口
  3. Next, as the setup is configured with local distributor, choose the default setting “AmbikaPrashanth will act as its own Distributor; SQL Server will create a distribution database and log” and Click Next

    接下来,由于使用本地分发服务器配置了该设置,因此选择默认设置“ AmbikaPrashanth将充当其自己的分发服务器; SQL Server将创建一个分发数据库并记录”,然后单击“ 下一步”。

  4. Configure the Snapshot Folder. As this is a demo setup, I’ll go with the default values and click Next

    配置快照文件夹 。 因为这是一个演示设置,所以我将使用默认值,然后单击“ 下一步”。

  5. In the Configure distribution database page, select the defaults and proceed by clicking Finish button

    在“配置分发数据库”页面中,选择默认值,然后单击“ 完成”按钮继续。

  6. In the Complete the wizard page, review the summary and then click Finish to complete the configuration of the distribution database

    在“完成向导”页面中,查看摘要,然后单击“ 完成”以完成分发数据库的配置。

  7. Next, in the confirmation page, you would see the progress of the entire distributor setup

    接下来,在确认页面中,您将看到整个分销商设置的进度

配置发布者 (Configure Publisher)

In this section, we discuss setting up a publisher. As we know that during the setup, we can see a different type of replication that we can enable through the wizard.

在本节中,我们讨论设置发布者。 众所周知,在安装过程中,我们可以看到可以通过向导启用的另一种复制类型。

  1. Browse Object Explorer, locate the Replication folder, right-click Local Publication, and then click New Publication

    浏览对象资源管理器 ,找到“ 复制”文件夹,右键单击“ 本地 发布” ,然后单击“ 新建发布”。

  2. In the Publication Wizard, click Next

    发布向导中 ,单击“下一步”。

  3. On the publication database page, select the Adventureworks2016 database and click Next

    在发布数据库页面上,选择Adventureworks2016数据库,然后单击“ 下一步”。

  4. Next, select Transactional publication as the Publication Type, and click Next

    接下来,选择“ 事务性发布”作为“发布类型”,然后单击“ 下一步”。

  5. In the Articles page, choose all the objects that are part of the publication. In the case of this tutorial, it’s a full database migration hence, I select all the objects

    在“ 文章”页面中,选择出版物中所有的对象。 在本教程中,这是一次完整的数据库迁移,因此,我选择所有对象

    Note: Since we are doing a full database migration, we are not going to set up any type of table row filtering.

    注意:由于我们正在进行完整的数据库迁移,因此我们将不会设置任何类型的表行过滤。

  6. In the Snapshot Agent page select Create a snapshot immediately. We need to specify when we are going to run the snapshot agent that will create that first snapshot, which will then be applied to Azure SQL Database. In this case, we set it to create the snapshot immediately because we are going to initialize replication right away

    在“ 快照代理”页面中,选择“ 立即创建快照” 。 我们需要指定何时要运行将创建第一个快照的快照代理,然后将其应用于Azure SQL数据库。 在这种情况下,我们将其设置为立即创建快照,因为我们将立即初始化复制。

  7. On the Agent Security page, configure the Snapshot Agent using Security settings

    在“ 代理安全性”页面上,使用“ 安全性”设置配置快照代理

  8. In this case, we use the SQL Server Agent service. In this step, the recommended setting is to use a domain account. But for demo purposes, I am just going to use the SQL Server agent service account

    在这种情况下,我们使用SQL Server代理服务。 在此步骤中,建议的设置是使用域帐户。 但出于演示目的,我将使用SQL Server代理服务帐户

  9. Finish 完成”。
  10. In the next page, type in the publication name and click Finish

    在下一页中,键入出版物名称,然后单击“ 完成”。

  11. The publication setup progress appears. It summarizes the progress of the publication setup and configuration. In case of this tutorial, you would see that the Adventureworks_Pub is successfully created. The wizard will take care of creating the publication, adding the articles, and then starting the snapshot agent to take that initial snapshot of the AdventureWorks2016 database

    显示出版物设置进度。 它总结了发布设置和配置的进度。 如果是本教程,您会看到成功创建了Adventureworks_Pub。 该向导将负责创建发布,添加文章,然后启动快照代理以获取AdventureWorks2016数据库的初始快照。

  12. Browse the Publication folder to view the newly-created publication 浏览出版物文件夹以查看新创建的出版物

配置订户 (Configure Subscriber)

Creating the subscription is the last step in setting up transaction replication.

创建预订是设置事务复制的最后一步。

  1. In Object Explorer, expand the Replication folder, right-click Local Subscriptions, and then select New Subscriptions

    在对象资源管理器中,展开“ 复制”文件夹,右键单击“ 本地订阅” ,然后选择“ 新建订阅”

  2. Select the publication database. In case of this tutorial, it will be AdventureWorks2016

    选择发布数据库。 如果是本教程,它将是AdventureWorks2016

  3. As we only have one publication (the one that I just created), we’ll select it and click Next

    由于我们只有一个出版物(我刚刚创建的一个出版物),因此将其选中,然后单击“ 下一步”。

  4. In a normal setup, we have the option of selecting where to run the distribution agent. But for Azure SQL Database, the first option will be it. Only push subscription works for Azure

    在常规设置中,我们可以选择在哪里运行分发代理。 但是对于Azure SQL数据库,第一个选择就是它。 仅推送订阅适用于Azure

    Note: Select pull subscription would not work. And for subscribers, I’m going to add a new subscriber, and this is going to be the Azure server.

    注意 :选择请求订阅将不起作用。 对于订阅者,我将添加一个新订阅者,这将是Azure服务器。

  5. In the wizard, I have to select a SQL Server subscriber to add the Azure SQL Server

    在向导中,我必须选择一个SQL Server订阅服务器以添加Azure SQL Server

  6. In the next step, we create an empty subscriber. Use SQL Server Management Studio or Azure Portal to create an empty database. The database creation is part of the configuration; we need to look at the available service tier offerings (S0, S1, S2, S3, S4 and S5). Once this is done, go back to the wizard, back to the drop down, and click on Refresh database list to get the name of the database you just created

    在下一步中,我们创建一个空订户。 使用SQL Server Management Studio或Azure门户创建一个空数据库。 创建数据库是配置的一部分。 我们需要查看可用的服务层产品(S0,S1,S2,S3,S4和S5)。 完成此操作后,返回向导,返回到下拉列表,然后单击“ 刷新数据库”列表以获取刚刚创建的数据库的名称。

  7. Next, to connect to the distributer, we’re just going to use the SQL Server Agent account, though normally you would use a separate domain account. Finally, to connect to the subscriber, we’re going to use a SQL login. In this case, I use a SQL account myadminuser and its password, to push the commands from the distributor

    接下来,要连接到分发服务器,我们将使用SQL Server代理帐户,尽管通常情况下,您将使用单独的域帐户。 最后,要连接到订户,我们将使用SQL登录名。 在这种情况下,我使用一个SQL帐户myadminuser及其密码来从分发器中推送命令

    Note: You can also try an alternative account that has the database owner permission set for the subscription database AdventureWorks2016

    注意 :您也可以尝试为订阅数据库AdventureWorks2016设置了数据库所有者权限的备用帐户

  8. Finish. 完成
  9. We can either run the replication continuously, run it only on demand when we actually execute the job, or we can also define a schedule for it. As it is part of the database migration, it is recommended to set it to run continuously, so both, the publisher and subscriber databases, will be in sync. Next, we’re going to initialize the subscription, immediately, as soon as we are done with the wizard. These are the default configurations that are used for the demo

    我们既可以连续运行复制,也可以仅在实际执行作业时按需运行复制,也可以为其定义时间表。 由于它是数据库迁移的一部分,因此建议将其设置为连续运行,这样发布者数据库和订阅者数据库都将保持同步。 接下来,一旦完成向导,我们将立即初始化订阅。 这些是用于演示的默认配置

  10. At this point, the Create subscription wizard will create the subscription to the Azure SQL Database

    此时,创建订阅向导将创建对Azure SQL数据库的订阅

  11. Next, let’s go back to the SQL Server Management Studio and verify that there is a new subscription that points to the Azure SQL Server. To verify this, launch Replication Monitor 接下来,让我们回到SQL Server Management Studio并验证是否存在指向Azure SQL Server的新订阅。 要验证这一点,请启动复制监视器
  12. In the Replication Monitor, we can expand the publisher and click on the publication and get the status of the subscription that’s happening over the cloud

    在Replication Monitor中,我们可以扩展发布者并单击发布,并获取通过云进行的订阅的状态

  13. In the case of this article, we can see the status as running, it has no errors, and the performance is excellent. We can double click on that particular subscription if we want to and we would get a detailed history of the data that has been uploaded to the cloud

    在本文的情况下,我们可以看到状态为“正在运行”,没有错误,并且性能非常好。 如果需要,我们可以双击该特定订阅,我们将获得已上传到云中的数据的详细历史记录

  14. We can check the Undistributed Commands tab to see the status; a value of 0 means that both databases are in sync. In case of the demo, it is 1785, which means that the database is synchronizing at the moment

    我们可以检查“未分发的命令”选项卡以查看状态; 值0表示两个数据库都处于同步状态。 在演示中,它是1785,这意味着数据库正在同步

  15. Connect to the Azure SQL database and verify the data

    连接到Azure SQL数据库并验证数据

摘要 (Summary)

In this article, we discussed how to perform a full database migration to Azure SQL Database using Transaction Replication. In this guide, I have selected all the objects in the database. In most cases it depends on the complexity of your schema. You might use SQL Server transactional replication along with other combination of data transfer methods for non-primary key tables. I hope this article gave you an idea how to perform database migrations. I hope you liked this article. Please leave your feedback in the comments section.

在本文中,我们讨论了如何使用事务复制将数据库完全迁移到Azure SQL数据库。 在本指南中,我选择了数据库中的所有对象。 在大多数情况下,这取决于架构的复杂性。 您可以将SQL Server事务复制与其他数据传输方法组合一起用于非主键表。 希望本文为您提供了如何执行数据库迁移的想法。 希望您喜欢这篇文章。 请在评论部分留下您的反馈。

翻译自: https://www.sqlshack.com/sql-server-database-migration-to-azure-sql-database-using-sql-server-transactional-replication/

使用SQL Server事务复制将SQL Server数据库迁移到Azure SQL数据库相关推荐

  1. 将本地SQL Server数据库迁移到Azure SQL数据库

    In this article, we will discuss and understand a method to migrate an on-premises SQL Server databa ...

  2. 如何处理SQL Server事务复制中的大事务操作

    如何处理SQL Server事务复制中的大事务操作 事务复制的工作机制 事务复制是由 SQL Server 快照代理.日志读取器代理和分发代理实现的.快照代理准备快照文件(其中包含了已发布表和数据库对 ...

  3. sql数据库 订阅发布_如何使用中央发布者和多个订阅者数据库设置自定义SQL Server事务复制

    sql数据库 订阅发布 In this article, you'll learn how to setup a simple, custom distributed database replica ...

  4. Linux上SQL Server事务复制

    In this article, we will talk about how to send the SQL Server Transactional Replication on Linux En ...

  5. sql azure 语法_如何将内部SQL Server数据库迁移到Azure

    sql azure 语法 Lately, database administrators often hear the question "have you tried Azure?&quo ...

  6. azure云数据库_在Azure SQL数据库中配置多重身份验证

    azure云数据库 介绍 (Introduction) The new SSMS 17.2 allows users to authenticate using Active Directory wi ...

  7. azure云数据库_保护Azure SQL数据库免于意外删除

    azure云数据库 In this article, we will review options called LOCKS in Azure SQL database and Azure SQL S ...

  8. azure云数据库_使用Azure SQL数据库构建ASP.NET应用

    azure云数据库 In this article, you will learn about Azure SQL Database and its uses. Then the article sp ...

  9. azure云数据库_在Azure SQL数据库中配置电子邮件通知

    azure云数据库 In this article, we will review how to configure email notifications in the Azure SQL sing ...

最新文章

  1. ArcGIS10.2 网络分析之路径分析(二)---构建网络数据集
  2. CentOS7安装xfce桌面环境
  3. 【ACM】最长公共子序列 - 动态规划
  4. .NET手记-JS获取Url参数
  5. 面试小能手速成,接口测试脚本如何编写?其实很简单
  6. matplotlib基本使用
  7. 在ubuntu中自定义安装nginx
  8. 写代码质量改善java计划151建议——导航开始
  9. SQL常用语句(普通查询+条件查询)
  10. 微型计算机应用领域思维导图,思维导图作用和应用领域有哪些
  11. 线性代数学习之对称矩阵与矩阵的SVD分解
  12. Cloudera Manager集群报警,堆转储目录/tmp 或日志目录/var/log 可用空间小于 5.0 吉字节
  13. (一)基于Multisim的超外差接收系统:本地振荡器的设计
  14. python如何实现电子邮件的发送
  15. 局部动态地图(LDM)的介绍
  16. phonegap 微信登录总结
  17. [导入]以IT民工的名义,我经济条件改善了很多很多,却发现越发穷苦的趋势出来了...月光的雏形已经显现,怨念。。...
  18. dnf如何查询服务器角色信息,DNF助手如何查询他人角色 查看陌生人详情方法
  19. Docker仓库harbor
  20. PAT日志 1086

热门文章

  1. 无法使用带括号的初始值设定项初始化数组_leetcode32. 最长有效括号
  2. 鸿蒙系统空城计,鸿蒙系统到底什么时候用在手机上?
  3. wordpress表单数据验证_实战:Drupal迁移到WordPress
  4. Java中的序列问题-2
  5. Jenkins 自动化集成之路 Linux 安装 maven
  6. ReactJS实用技巧(1):JSX与HTML的那些不同
  7. asp.net中XmlDocument解析出现出错,处理特殊字符
  8. React实现类似淘宝tab居中切换效果
  9. 计算机网络学习笔记(28. Email消息格式与POP协议)
  10. 移动端开发—流式布局