This article will review on how to configure SQL Server Replication along with mirroring on a database.

本文将回顾如何配置SQL Server复制以及数据库镜像。

复制概述 (Replication Overview)

SQL Server Replication is used to transfer data and objects from one database to another database. There are three main types of replication SQL server supports.

SQL Server复制用于将数据和对象从一个数据库传输到另一个数据库。 SQL Server支持三种主要的复制类型。

  • Snapshot Replication 快照复制
  • Merge Replication 合并复制
  • Transactional Replication 事务复制

快照复制 (Snapshot Replication)

Snapshot replication distributes data exactly as it appears at a specific moment in time and does not monitor for updates to the data. When synchronization occurs, the entire snapshot is generated and sent to Subscribers. The snapshot agent generates the snapshot and place snapshot files in snapshot folder. The distribution agent applies the snapshot in subscriber.

快照复制完全按照特定时间出现的数据来分发数据,并且不监视数据更新。 发生同步时,将生成整个快照并将其发送给订阅服务器。 快照代理会生成快照并将快照文件放置在快照文件夹中。 分发代理将快照应用到订阅服务器中。

事务复制 (Transactional Replication)

In SQL Server Replication (transactional), the initial snapshot is generated by snapshot agent and stores the snapshot files in snapshot folder and the distribution agent applies the snapshot on subscribers. The log reader agent monitors the transaction log for all incremental changes and copies the transactions to distribution database and these transactions applied on subscribers by distribution agent.

在SQL Server复制(事务性)中,初始快照由快照代理生成,并将快照文件存储在快照文件夹中,而分发代理将快照应用于订阅服务器。 日志读取器代理监视事务日志中的所有增量更改,并将事务复制到分发数据库,​​然后由分发代理将这些事务应用于订阅服务器。

合并复制 (Merge Replication)

In merge replication the snapshot agent generates the snapshot and places snapshot files in snapshot folder. These files include the schema of the objects, bulk copy files, triggers, constraints and stored procedures and the initial snapshot is applied on subscribers by merge agent. The incremental changes on both publisher and subscriber were tracked by merge triggers created on each table added to merge replication and these changes are downloaded/uploaded by merge agent.

在合并复制中,快照代理会生成快照并将快照文件放置在快照文件夹中。 这些文件包括对象的架构,大容量复制文件,触发器,约束和存储过程,并且初始快照由合并代理应用于订阅服务器。 通过在添加到合并复制的每个表上创建的合并触发器跟踪发布者和订阅者上的增量更改,并且这些更改由合并代理下载/上载。

Below are servers I used while configuring replication on mirroring.

以下是我在配置镜像复制时使用的服务器。

  • Principal Server: SQL01V 主体服务器:SQL01V
  • Mirror Server: SQL02V 镜像服务器:SQL02V
  • Distributor: SQLDIST01V 发行人:SQLDIST01V
  • Subscriber: SQLSUB01V 订阅者:SQLSUB01V

步骤摘要 (Steps Summary)

Below are the steps for configuring replication along with mirroring on a database. In this setup we are configuring mirroring on publisher database.

以下是在数据库上配置复制和镜像的步骤。 在此设置中,我们将在发布者数据库上配置镜像。

  1. Setup a remote distributor 设置一个远程分配器
  2. Enable principal server and mirror server to publish using same remote distributor 启用主体服务器和镜像服务器使用同一远程分发服务器进行发布
  3. Configure publication and add subscriber 配置发布并添加订阅者
  4. Configure mirroring 配置镜像
  5. Change SQL Server Replication agent parameters 更改SQL Server复制代理参数

发行设置 (Distribution Setup)

The distribution database should be configured on a remote SQL server instance and should be available for both principal server and mirror server.

分发数据库应在远程SQL Server实例上配置,并且对于主体服务器和镜像服务器均应可用。

On the distributor “SQLDIST01V”, Login to SQL Server instance using SQL Server management studio.

在分发服务器“ SQLDIST01V”上,使用SQL Server Management Studio登录到SQL Server实例。

Navigate to the replication folder, right click and click on Configure Distribution. The configure distribution wizard opens. Click Next -> select the first option “SQLDIST01V” will act as its own distributor; SQL Server will create a distribution database and log (Here the server name changes as per your distribution server) and click Next -> Input the snapshot folder (give a shared path which will be available for both principal server and mirror server) -> Click Next -> Input the distribution database name (default is distribution) and the locations to save the data file and the log file ->

导航到复制文件夹,右键单击并单击配置分发 。 将打开配置分发向导。 单击下一步 ->选择第一个选项“ SQLDIST01V”将充当其自己的分发服务器; SQL Server将创建一个分发数据库并进行日志记录(此处服务器名称随分发服务器而变化 ,然后单击下一步 ->输入快照文件夹(给出一个共享路径,该路径将同时用于主体服务器和镜像服务器)->单击下一步 ->输入分发数据库名称(默认为分发)以及保存数据文件和日志文件的位置->

Click Next and add publishers. Here we need to add both principal server and mirror server so that both can publish using the same distribution. At the end enable configure distribution, click Next and then Finish.

单击下一步,然后添加发布者。 在这里,我们需要添加主体服务器和镜像服务器,以便它们都可以使用相同的发行版进行发布。 最后,启用配置分发,单击下一步 ,然后单击完成

The remote distribution setup is completed, and we added both principal server and mirror server as publishers at distributor.

远程分发设置已完成,我们在分发服务器上同时添加了主体服务器和镜像服务器作为发布者。

使主体和镜像能够使用相同的远程分发服务器进行发布 (Enable Principal and Mirror to Publish Using Same Remote Distributor)

Login to principal server “SQL01V” and navigate to replication folder. Right click and select Configure Distribution.

登录到主体服务器“ SQL01V”并导航到复制文件夹。 右键单击并选择配置分发

The configure distribution wizard opens. Click Next -> select second option Use the following server a Distributor -> Click on Add -> connect to the remote distributor

将打开配置分发向导。 单击下一步 ->选择第二个选项使用以下服务器作为分发服务器 ->单击添加 ->连接到远程分发服务器

Click Next -> enter the administrative link password of distributor.

单击下一步 ->输入分发服务器的管理链接密码。

Click Next -> check configure distribution and click Next and then Finish

单击下一步 ->检查配置分发,然后单击下一步 ,然后单击完成

Login to the mirror server “SQL02V” and follow the same steps to add the remote distributor “SQLDIST01V”.

登录到镜像服务器“ SQL02V”,并按照相同的步骤添加远程分发服务器“ SQLDIST01V”。

配置发布和添加订户 (Configuring Publication and Add Subscriber)

Login to principal server “SQL01V”, configure publication add articles to publication and generate the snapshot. Add the subscriber “SQLSUB01V” and apply the snapshot.

登录到主体服务器“ SQL01V”,配置发布将文章添加到发布并生成快照。 添加订阅服务器“ SQLSUB01V”并应用快照。

  • Note:注意: For step by step to configure SQL Server Replication (merge) and adding subscribers please refer to any of the below articles.有关逐步配置SQL Server复制(合并)和添加订阅服务器的信息,请参阅以下任何文章。

    SQL Server Replication (Merge) – What gets replicated and what doesn’tSQL Server复制(合并)–复制什么,什么不复制

    Foreign key issues while applying a snapshot in SQL Server merge replication在SQL Server合并复制中应用快照时出现外键问题

    For step by step to configure transactional replication please refer to the below article.
    SQL Server replication: Configuring Snapshot and Transactional Replication

    有关逐步配置事务复制的信息,请参阅以下文章。
    SQL Server复制:配置快照和事务复制

配置镜像 (Configuring Mirroring)

Login to principal server and configure mirroring on publisher database between principal server “SQL01V” and mirror server “SQL02V”.

登录到主体服务器,并在主体服务器“ SQL01V”和镜像服务器“ SQL02V”之间的发布者数据库上配置镜像。

  • Note: Please refer to the below article for configuring mirroring.
    How to create a Database Mirroring
  • 注意:请参考以下文章以配置镜像。
    如何创建数据库镜像

更改SQL Server复制代理参数 (Change the SQL Server Replication Agent Parameters)

Login to your principal database instance. Navigate to the Replication folder and the publication we created. Right click on the publication and click on Launch Replication Monitor.

登录到您的主体数据库实例。 导航到“ 复制”文件夹和我们创建的发布。 右键单击发布,然后单击启动复制监视器。

In case of merge replication. Launch replication monitor, navigate to the publication and click on All Subscribers tab. if you have multiple subscribers select any one of the merge agents of the subscriber -> right click and click on Agent Profile. If the existing agent profile is default Click on New and clone new profile from default profile. Give the profile name and description of your choice and uncheck show only parameters used in this profile. Enter your mirror server name in the parameter called “-PublisherFailoverPartner” and click Ok.

如果是合并复制。 启动复制监视器,导航到发布,然后单击“ 所有订户”选项卡。 如果您有多个订阅者,请选择该订阅者的任一合并代理程序->右键单击并单击代理配置文件 。 如果现有代理配置文件是默认配置文件,请单击“ 新建”,然后从默认配置文件克隆新配置文件。 提供配置文件名称和您选择的描述,然后取消选中仅显示此配置文件中使用的参数 。 在名为“ -PublisherFailoverPartner ”的参数中输入镜像服务器名称,然后单击“确定”。

Now use the profile you created for the agent. The agent uses parameters in the newly selected profile from next run. Stop and start your agents.

现在使用您为代理创建的配置文件。 代理将从下次运行中使用新选择的配置文件中的参数。 停止并启动您的代理。

In case of transactional replication, launch replication monitor, navigate to the publication and click on Agents tab. select the log reader agent, right click and click on Agent Profile. If the existing agent profile is default Click on New and clone new profile from default profile. Give the profile name and description of your choice and uncheck show only parameters used in this profile. Enter your mirror server name in the parameter called “-PublisherFailoverPartner” and click Ok.

如果是事务复制,请启动复制监视器,导航到发布,然后单击“ 代理”选项卡。 选择日志阅读器代理,右键单击并单击代理配置文件 。 如果现有代理配置文件是默认配置文件,请单击“ 新建”,然后从默认配置文件克隆新配置文件。 提供配置文件名称和您选择的描述,然后取消选中仅显示此配置文件中使用的参数 。 在名为“ -PublisherFailoverPartner ”的参数中输入镜像服务器名称,然后单击“确定”。

We can also create new agent profile from distributor. Login to the distribution server Navigate to Replication -> Local Publications -> Right click and click on Distributor properties -> Click on Profile Defaults -> select the type of agent and click New -> Clone from default profile, give the name and description of agent, change the agent parameters and click ok.

我们还可以从分销商创建新的代理商资料。 登录到分发服务器导航到复制 -> 本地发布 ->右键单击,然后单击分发服务器属性 ->单击配置文件默认值 ->选择代理的类型,然后单击新建 ->从默认配置文件克隆,提供名称和描述。代理,更改代理参数,然后单击确定。

We need to take care while creating the agent profiles with publisher failover partner parameter when we have multiple publisher databases being mirrored.

当我们有多个发布者数据库被镜像时,在使用发布者故障转移伙伴参数创建代理配置文件时,我们需要注意。

For example, if we have two different publications and both the publisher databases are mirrored to different mirror servers. Create two different agent profiles with two different server names in “-PublisherFailoverPartner” and use the appropriate profile for each agent.

例如,如果我们有两个不同的发布,并且两个发布者数据库都镜像到不同的镜像服务器。 在“ -PublisherFailoverPartner”中使用两个不同的服务器名称创建两个不同的代理配置文件,并对每个代理使用适当的配置文件。

Now login to the principal server perform a failover. Do some transactions on current principal server. Check if the SQL Server Replication jobs were running with out any failure and query your subscriber database to see if the new transactions got replicated or not.

现在登录到主体服务器执行故障转移。 在当前主体服务器上执行一些事务。 检查SQL Server复制作业是否在正常运行,并查询您的订户数据库以查看是否复制了新事务。

监控方式 (Monitoring)

After failover from principal server to mirror server, all the publications configured will be shown in local publication folder of active server. Replication monitor can be launched from the active server in mirroring.

从主体服务器故障转移到镜像服务器后,所有配置的发布将显示在活动服务器的本地发布文件夹中。 可以从活动服务器中以镜像方式启动复制监视器。

In case if you are using the stored procedures to administer replication at mirror database, use the actual publisher name where you configured replication i.e. the principal server. The replication meta data stored in principal server and mirror server is same. The publisher name stored in systems tables at mirror server is original publisher name.

如果要使用存储过程在镜像数据库上管理复制,请使用配置复制的实际发布者名称,即主体服务器。 主体服务器和镜像服务器中存储的复制元数据相同。 镜像服务器的系统表中存储的发布者名称是原始发布者名称。

Example: If you are adding a pull subscription to the publication after failover using stored procedures, use the actual publisher name i.e. principal server while passing the publisher name as a parameter to replication stored procedures.

示例:如果要使用存储过程在故障转移后向发布添加请求订阅,请使用实际的发布者名称(即主体服务器),同时将发布者名称作为参数传递给复制存储过程。

目录 (Table of contents)

SQL Server Replication with a table with more than 246 columns
Foreign key issues while applying a snapshot in SQL Server merge replication
SQL Server Replication (Merge) – What gets replicated and what doesn’t
SQL Server Replication (Merge) – Performance Issues in replicating schema changes
Merge SQL Server replication parameterized row filter issues
SQL Server Replication on a mirrored database
Log shipping on a mirrored database
具有超过246列的表SQL Server复制
在SQL Server合并复制中应用快照时出现外键问题
SQL Server复制(合并)–复制什么,什么不复制
SQL Server复制(合并)–复制架构更改中的性能问题
合并SQL Server复制参数化的行筛选器问题
镜像数据库上SQL Server复制
镜像数据库上的日志传送

翻译自: https://www.sqlshack.com/sql-server-replication-on-a-mirrored-database/

镜像数据库上SQL Server复制相关推荐

  1. sql server 复制_SQL Server复制(合并)–复制架构更改中的性能问题

    sql server 复制 This article will review performance issues in replicating schema changes on tables in ...

  2. 数据库镜像怎么还原数据库_镜像数据库上的日志传送

    数据库镜像怎么还原数据库 Both log shipping and mirroring are high availability and disaster recovery options ava ...

  3. Linux上SQL Server合并复制

    Replication is a process to manage multiple copies of the same data at a different node. Microsoft S ...

  4. Linux上SQL Server事务复制

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

  5. sql数据库备份默认路径_在Linux上SQL Server中更改默认数据库文件和备份路径

    sql数据库备份默认路径 In a previous article, we explored the process to change default SQL dump file location ...

  6. sql server合并行_合并SQL Server复制参数化的行筛选器问题

    sql server合并行 In this article we will discuss about SQL Server Merge Replication Parameterized row f ...

  7. sql server复制表_具有超过246列的表SQL Server复制

    sql server复制表 问题 (Problem) In our environment we use SQL Server merge replication to replicate data ...

  8. 驰网云数据库MySQL SQL Server

    驰网云数据库MySQL &SQL Server 在最近几年,云数据库逐渐成为焦点中的焦点.根据IDC数据显示,到2025年,全球超过50%的数据库将部署在公有云上:在中国市场,这个数据将达70 ...

  9. 通往SQL Server复制的阶梯:一级- SQL服务器复制介绍

    链接:http://www.sqlservercentral.com/articles/Stairway+Series/72274/ 文章:Stairway to SQL Server Replica ...

最新文章

  1. I/O异步之I/O完成端口
  2. python【力扣LeetCode算法题库】28-实现 strStr()
  3. OpenCV探索之路(八):重映射与仿射变换
  4. win10 下安装、配置、启动mysql
  5. Java学习笔记10-1——MyBatis
  6. 数字图像处理-1.图像获取
  7. 【Elasticsearch】 es 集群发现机制
  8. Mysql数据库及帐号的权限查询
  9. python获取url的json数据_通过url获取json数据并在python中使用(simplejson)
  10. 【每日算法Day 62】LeetCode 815. 公交路线
  11. IntentService简介
  12. Python 爬虫学习笔记(七(2))JsonPath解析+实战
  13. 工程师思维(简化版)——聪明人的10个工程思维
  14. 面试姊妹篇4:常见的Java多线程面试题
  15. 《那些年啊,那些事——一个程序员的奋斗史》——25
  16. 华为机试 放苹果
  17. [画风突变] 藤原千花专属相册,C语言制作书记专属电子相册!
  18. 香港计算机翻译博士,香港城市大学博士offer一枚-指南者留学
  19. 使用网卡rtk8812au以及omnipeek抓取空中包
  20. 厦门有哪些靠谱的互联网公司

热门文章

  1. python 方向键控制代码_Python控制鼠标键盘代码实例
  2. C# Excel导入与导出
  3. 用Keras搭建神经网络 简单模版(三)—— CNN 卷积神经网络(手写数字图片识别)...
  4. FPGA--(verilog)一个完整工程的设计(包含设计块和激励块)及仿真
  5. 洛谷 P1272 重建道路(树形DP)
  6. NHibernate入门实例
  7. Apache HTTP Server Version 安装简要记录
  8. Google Chrome 最新市场份额
  9. Xcode启动RN报错“`fsevents` unavailable“
  10. react native 组件汇总整理,点击链接至GitHub