37
Module 5: Implementing Merge Replication

Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Embed Size (px)

Citation preview

Page 1: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Module 5:Implementing Merge

Replication

Page 2: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Overview

Understanding Merge Replication Architecture

Implementing Conflict Resolution

Planning and Deploying Merge Replication

Troubleshooting Merge Replication

Tuning Merge Replication

Page 3: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Lesson: Understanding Merge Replication Architecture

How the Snapshot Agent Prepares a Publisher

How Merge Agent Creates and Synchronizes Subscriptions

How Generation Numbers Assist Synchronization

The Limited Role of the Distribution Database

Location of the Merge Agent

Page 4: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

How the Snapshot Agent Prepares a Publisher

MSmerge_contentsMSmerge_contentsrowguid

TableTableTableTable rowguidrowguidrowguidrowguid

TriggersStored Procedures

TriggersStored Procedures

TableTable rowguidrowguid

rowguid

UPDATEINSERT

rowguid

UPDATEDELETE

MSmerge_tombstoneMSmerge_tombstone

Saves the row content

MSmerge_contentsMSmerge_contentsrowguid

TableTableTableTable rowguidrowguidrowguidrowguid

TriggersStored Procedures

TriggersStored Procedures

TableTable rowguidrowguid

rowguid

UPDATEINSERT

rowguid

UPDATEDELETE

MSmerge_tombstoneMSmerge_tombstone

Saves the row content

11 3322

Page 5: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

How Merge Agent Creates and Synchronizes Subscriptions

Reads MSmerge_contents on Subscriber and PublisherReads MSmerge_contents on Subscriber and Publisher

Passes Subscriber changes to PublisherPasses Subscriber changes to Publisher

Passes Publisher changes to SubscriberPasses Publisher changes to Subscriber

If both changed same row identified by rowguid, initiates conflict resolverIf both changed same row identified by rowguid, initiates conflict resolver

Merge AgentMerge AgentMerge AgentMerge Agent

Page 6: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

How Generation Numbers Assist Synchronization

Generation numbers:

Help determine what rows need to be updated without reading the entire table.

Indicate the last change that has occurred.

Are kept independently by Publisher and Subscriber.

Page 7: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

The Limited Role of the Distribution Database

The distribution database stores:

The snapshot location.

The identity of the Publisher.

The identities of the Subscribers.

The time when each Subscriber last synchronized.

Locate the distribution database on the Publisher

Page 8: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Location of the Merge Agent

Subscriber for pull subscriptions

Distributor for push subscriptions

Page 9: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Lesson: Implementing Conflict Resolution

Conflict Detection

Conflict Resolution

Page 10: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Conflict Detection

Change by Manager

ALFKIALFKI HighHigh 3/4/013/4/01

Change by Sales

ALFKIALFKI HighHigh 4/7/014/7/01

Original Row

CustomerCustomerCustomerCustomer

ALFKIALFKI

PriorityPriorityPriorityPriority ContactContactContactContact

MedMed 3/4/013/4/01

Changes areMerged ALFKIALFKI HighHigh 4/7/014/7/01

Page 11: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Conflict Resolution

The Publisher has the highest priority so it wins all conflicts that it has with Subscribers.

All Subscribers gain the priority of the Publisher with which they synchronize, but only when they synchronize.

Whichever Subscriber synchronizes with the Publisher first gains the advantage of the Publisher’s priority first and will win subsequent conflicts with other Subscribers.

Page 12: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Practice: Implementing Conflict Resolution

Create table, merge publication, subscription

Make changes to table

Synchronize the tables and check for conflicts

Resolve conflicts

Page 13: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Lesson: Planning and Deploying Merge Replication

How to Manage Identity Values

Implementing Attachable Subscription Databases

Using Dynamic Horizontal Filters

Using Dynamic Snapshots

Using Join Filters

How SQL Server Implements Join Filters

Page 14: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

How to Manage Identity Values

Page 15: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Practice: How to Manage Identity Values

Create table, merge publication, subscription

Add rows

Synchronize subscription

Page 16: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Create and configure the publicationsCreate and configure the publications

Create database and pull subscriptionsCreate database and pull subscriptions

Copy the database and transfer the .msf fileCopy the database and transfer the .msf file

Attach the subscription databaseAttach the subscription database

Start the appropriate AgentStart the appropriate Agent

Implementing Attachable Subscription Databases

Page 17: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Practice: Implementing Attachable Subscription Databases

Create a new database

Create a merge publication

Configure the publication to allow attachable subscription databases

Create a pull subscription

Copy the subscription database

Copy the .msf file to your partner’s server and attach the database

Modify a row

Synchronize the subscription database

Page 18: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Using Dynamic Horizontal Filters

Benefit of dynamic filters

Provide different partitions of data to different Subscribers

SUSER_SNAME()

Returns the login name for the user’s connection

HOST_NAME()

Returns the host name for the user’s connection

User-defined functions

Page 19: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Using Dynamic Snapshots

Create snapshots in advance for later application to disconnected Subscribers

Create only the snapshots you need

Create snapshots at a convenient time

Page 20: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Practice: Dynamic Filtering with Dynamic Snapshots

Create table

Add rows

Create merge publication

Create pull subscription

Create dynamic snapshot

Create second subscription

Page 21: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Using Join Filters

Page 22: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Views based on views based on views

Second ViewSecond View

JoinedJoinedJoinedJoined

How SQL Server Implements Join Filters

First ViewFirst View

JoinedJoinedJoinedJoined FilteredFilteredTableTable

FilteredFilteredTableTable

11 3322

Page 23: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Practice: Join Filters

Create a merge publication with a join filter

Create a pull subscription

Verify and test the publication and subscription

Page 24: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Lesson: Troubleshooting Merge Replication

Troubleshooting by Using the Merge Agent

Troubleshooting Slow Merge Performance by Using SQL Profiler

Troubleshooting Slow Performance When Using Merge Filters

Troubleshooting Subscriptions Using Merge Replication Data Validation

Page 25: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Troubleshooting by Using the Merge Agent

Running the Merge Agent

Practice

"C:\Program Files\Microsoft SQL Server\80\COM\replmerg" -Publisher [VANCOUVER] -PublisherDB [Northwind] -Publication [MergeFilterCustOrdGermany] -Subscriber [DENVER] -SubscriberDB [NorthwindSubscriber] -SubscriptionType 1 -SubscriberSecurityMode 1 -Distributor [VANCOUVER]

"C:\Program Files\Microsoft SQL Server\80\COM\replmerg" -Publisher [VANCOUVER] -PublisherDB [Northwind] -Publication [MergeFilterCustOrdGermany] -Subscriber [DENVER] -SubscriberDB [NorthwindSubscriber] -SubscriptionType 1 -SubscriberSecurityMode 1 -Distributor [VANCOUVER]

Merge AgentMerge AgentMerge AgentMerge Agent

Page 26: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Select eventsSelect events

Select data columnsSelect data columns

Filter trace informationFilter trace information

Identify the operationsIdentify the operations

SQL ProfilerSQL ProfilerSQL ProfilerSQL Profiler

Troubleshooting Slow Merge Performance by Using SQL Profiler

Page 27: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Practice: Troubleshooting Slow Merge Performance By Using SQL Profiler

Create a trace file with SQL Profiler

Page 28: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Troubleshooting Slow Performance When Using Merge Filters

sp_MSsetupbelongs

Determines which set of rows in each table should be replicated to the Subscriber

sp_MSinitdynamicsubscriber

Used to query published tables by the merge process

Page 29: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Troubleshooting Subscriptions Using Merge Replication Data Validation

Scheduled data validation

Select type of validation with -Validate parameter

Select how often to validate with -ValidateInterval parameter

Special replication validation alert

Partial reinitialization

Returns the Subscriber to a previous state when data was synchronized

Page 30: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Lesson: Tuning Merge Replication

Planning for Efficient Merge Replication Tuning

Tuning the Merge Agent’s Performance

Tuning Publications

Tuning Filters, Indexes, and Filter Queries

Tuning the Merge Cleanup Process

Page 31: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Planning for Efficient Merge Replication Tuning

Reduce simultaneous merge requests

Use faster hardware

Optimize replication configuration

Stagger the timing of Subscribers’ merge processes

Create a hierarchy of Publishers

Use Republisher for scale-out

Page 32: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Tuning the Merge Agent’s Performance

Select the appropriate Merge Agent profile

Default profile

High Volume Server-to-Server profile

Slow Link Agent profile

Force the merge process to upload

ExchangeType 3—upload and download (default)

ExchangeType 1—download only

ExchangeType 2—upload only

Page 33: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Tuning Publications

Reconfigure tables that contain text or image columns

Use global subscriptions

Select the optimize synchronization option

Page 34: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Tuning Filters, Indexes, and Filter Queries

Use static filters

Partition data into small data sets

Use indexes on columns used in filters

Rebuild indexes

Optimize filtering expressions for indexes

Consider denormalization to simplify partitions

Page 35: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Tuning the Merge Cleanup Process

Metadata based on retention

MSmerge_contents

MSmerge_tombstone

MSmerge_genhistory

Cleanup process

Default retention period

Page 36: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Review

Understanding Merge Replication Architecture

Implementing Conflict Resolution

Planning and Deploying Merge Replication

Troubleshooting Merge Replication

Tuning Merge Replication

Page 37: Module 5: Implementing Merge Replication. Overview Understanding Merge Replication Architecture Implementing Conflict Resolution Planning and Deploying

Lab 5: Implementing Merge Replication

Exercise 0: Lab Setup

Exercise 1: Using Dynamic and Join Filters with Merge Replication