module 2: creating efficient replication solutions

35
Module 2: Creating Efficient Replication Solutions

Upload: shannon-woods

Post on 12-Jan-2016

233 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Module 2: Creating Efficient Replication Solutions

Module 2:Creating Efficient

Replication Solutions

Page 2: Module 2: Creating Efficient Replication Solutions

Overview

Understanding the SQL Server Platform for Replication

Replicating Data and Objects

Replicating Data and Executing Objects

Designing a Replication Topology

Troubleshooting a Replication Implementation

Page 3: Module 2: Creating Efficient Replication Solutions

Lesson: Understanding the SQL Server Platform for Replication

Understanding Operating SystemImplications for Replication

Understanding SQL Server Installation Implications for Replication

Page 4: Module 2: Creating Efficient Replication Solutions

Understanding Operating System Implications for Replication

Operating systems that CANOperating systems that CANbe used for transactional be used for transactional

replication Publisherreplication Publisher

Operating systems that CANOperating systems that CANbe used for transactional be used for transactional

replication Publisherreplication Publisher

Operating systems that CANNOTOperating systems that CANNOTbe used for transactionalbe used for transactional

replication Publisherreplication Publisher

Operating systems that CANNOTOperating systems that CANNOTbe used for transactionalbe used for transactional

replication Publisherreplication Publisher

Windows NTWindows NT Windows 95Windows 95

Windows 2000Windows 2000 Windows 98Windows 98

Windows XPWindows XP Windows Me, Windows CEWindows Me, Windows CE

Page 5: Module 2: Creating Efficient Replication Solutions

Understanding SQL Server Installation Implications for Replication

Licensing

Licensing requirements detailed on www.microsoft.com Character Sets

All servers should use the same character set Collation

Use the same collation at Publisher and Subscriber Sort order

You may use different sort orders at Publisher and Subscriber

Page 6: Module 2: Creating Efficient Replication Solutions

Lesson: Replicating Data and Objects

Replicating Table Schema

Planning to Publish Table Schema Objects

Replicating Filtered Data

Replicating Schema Objects – Views, UDFs, and Stored Procedures

Page 7: Module 2: Creating Efficient Replication Solutions

Replicating Table Schema

Schema changes required by replication Adding tables to track and manage replication Adding columns to identify records

You can change the name of the destination table or its columns

Changing columns sp_repladdcolumn sp_repldropcolumn On-demand script execution SQL Distributed Management Objects The publication property page

Restrictions on dropping columns

Page 8: Module 2: Creating Efficient Replication Solutions

Planning to Publish Table Schema Objects

Primary key constraints

Reference constraints

Unique constraints

Clustered and nonclustered indexes

User triggers

Extended properties

Collation

Page 9: Module 2: Creating Efficient Replication Solutions

Replicating Filtered Data

Vertical FilteringVertical FilteringVertical FilteringVertical Filtering

234567

1A B C D E F

234567

1A B E

Table A

Horizontal FilteringHorizontal FilteringHorizontal FilteringHorizontal Filtering

234567

1A B C D E F

36

2A B C D E F

Table B Subscriber Publisher

Page 10: Module 2: Creating Efficient Replication Solutions

These Objects

Rely on TheseTables

Replicating Schema Objects – Views, UDFs, and Stored Procedures

CREATE VIEW vw_EmployeeDept AS ...CREATE VIEW vw_EmployeeDept AS ...

CREATE FUNCTION fn_PayPeriod AS ...CREATE FUNCTION fn_PayPeriod AS ...

CREATE VIEW vw_EmployeeDept AS ...CREATE VIEW vw_EmployeeDept AS ...

CREATE FUNCTION fn_PayPeriod AS ...CREATE FUNCTION fn_PayPeriod AS ...

CREATE PROCEDURE pr_ValidateVac AS ...CREATE PROCEDURE pr_ValidateVac AS ...

CREATE PROCEDURE pr_ValidateVac AS ...CREATE PROCEDURE pr_ValidateVac AS ...

Replicate View, UDF, Stored Replicate View, UDF, Stored ProceduresProcedures

REPLICATED SEPARATELYREPLICATED SEPARATELY

Replicate View, UDF, Stored Replicate View, UDF, Stored ProceduresProcedures

REPLICATED SEPARATELYREPLICATED SEPARATELY

Replicate TablesReplicate TablesReplicate TablesReplicate Tables

11 3322

Page 11: Module 2: Creating Efficient Replication Solutions

Lesson: Replicating and Executing Objects

Reducing Replication Volume with Stored Procedures

Replicating Indexed Views as Tables

Replicating with On-Demand Script Execution

Preventing Data Inconsistencies from the Execution of Stored Procedures

Page 12: Module 2: Creating Efficient Replication Solutions

Reducing Replication Volume with Stored Procedures

UPDATE200,000Rows

The execution of stored proceduresThe execution of stored proceduresThe execution of stored proceduresThe execution of stored procedures

UPDATE200,000Rows

Create stored procedure to update affected rowsCreate stored procedure to update affected rows1111

Publish the stored procedure; replication creates copies on each Subscriber Publish the stored procedure; replication creates copies on each Subscriber 2222

Execute the stored procedure on the PublisherExecute the stored procedure on the Publisher3333

EXEC command is replicatedEXEC command is replicated4444

Update runs locally on SubscribersUpdate runs locally on Subscribers5555

11 3322

Page 13: Module 2: Creating Efficient Replication Solutions

Replicating Indexed Views as Tables

Preserve the image of the view data on disk

Allow you to replicate view content instead of schema

Reduce the amount of data to be replicated

Page 14: Module 2: Creating Efficient Replication Solutions

Replicating with On-Demand Script Execution

Script execution uses osql.exeScript execution uses osql.exe

Script is replicated Script is replicated 1111

Script executes locallyScript executes locally2222

Script executes locallyScript executes locally2222

Script executes locallyScript executes locally2222

11 3322

TruncateTable

TruncateTable

TruncateTable

TruncateTable

TruncateTable

TruncateTable

TruncateTable

TruncateTable

Page 15: Module 2: Creating Efficient Replication Solutions

Subscriber

PublisherEXEC pr_UpdateEXEC pr_Update

Preventing Data Inconsistencies from the Execution of Stored Procedures

UPDATE Table 1

UPDATE Table 2

Table 1Table 1

Table 2Table 2

EXEC pr_UpdateEXEC pr_Update

UPDATE Table 1

Table 1Table 1

UPDATE Table 2Table 2Table 2

Publisher and Subscriber Publisher and Subscriber do not matchdo not match

Publisher and Subscriber Publisher and Subscriber do not matchdo not match

ConstraintViolation

11 3322

Table 2Table 2

ConstraintViolation

Page 16: Module 2: Creating Efficient Replication Solutions

Lesson: Designing a Replication Topology

Central Publisher and Distributor

Republisher for a Slow Link

Republisher for Scale Out

Central Subscriber with Partitioned Data

Bidirectional Partitioned Topology

Bidirectional Non-Partitioned Topology

Page 17: Module 2: Creating Efficient Replication Solutions

Central Publisher and Distributor

Moscow

Rome

Paris

Athens

London

Berlinheadquarters

Central Publisher Central Publisher and Distributorand Distributor

Central Publisher Central Publisher and Distributorand Distributor

Remote Remote DistributionDistribution

Remote Remote DistributionDistribution

11 3322

Central Publisher Central Publisher and Distributorand Distributor

Central Publisher Central Publisher and Distributorand Distributor

Page 18: Module 2: Creating Efficient Replication Solutions

Republisher for a Slow Link

Seattle

San Francisco

Dallas

Sydney

Hong Kong

Beijing

Tokyo

San Francisco publishes to Seattle,

Dallas, and Tokyo

Slow link

Tokyo republishesto Beijing, Hong Kong,

and Sydney

11 3322

Page 19: Module 2: Creating Efficient Replication Solutions

Republisher for Scale Out

London

DakarWorldwide

Headquarters

RomeEuropeanHeadquarters

New York

AtlantaNorth American

Headquarters

Caracas

Madrid

Page 20: Module 2: Creating Efficient Replication Solutions

Central Subscriber with Partitioned Data

Seattle

New YorkSan Francisco

Dallas headquarters

Mexico City

Page 21: Module 2: Creating Efficient Replication Solutions

Bidirectional Partitioned Topology

New York

The New York Office updates customers in the East Region

No conflicts existNo conflicts existNo conflicts existNo conflicts exist

The San Francisco Office updates

customers in the West Region

San Francisco

1

2

3

4

5

6

7

A B C D E F

Page 22: Module 2: Creating Efficient Replication Solutions

Bidirectional Non-Partitioned Topology

New York

Both offices update the Both offices update the same datasame data

Both offices update the Both offices update the same datasame data

San Francisco

1

2

3

4

5

6

7

A B C D E F

11 3322

Page 23: Module 2: Creating Efficient Replication Solutions

Lesson: Troubleshooting a Replication Implementation

Keep a Performance Baseline

Check Replication Alerts

Look for Errors by Using Replication Monitor

Confirm Mutual Recognition of Servers

Validate Data

Check Subscription Status

Restore the Subscriber to the Current State

Removing Replication

Page 24: Module 2: Creating Efficient Replication Solutions

Step 1: Keep a Performance Baseline

Page 25: Module 2: Creating Efficient Replication Solutions

Step 2: Check Replication Alerts

Default AlertsDefault AlertsDefault AlertsDefault Alerts

Agent successAgent success

Agent failureAgent failure

Agent retryAgent retry

Subscriber has passed data validationSubscriber has passed data validation

Subscription cleaned upSubscription cleaned up

Subscriber has failed data validationSubscriber has failed data validation

Subscription reinitialized after data validationSubscription reinitialized after data validation

Page 26: Module 2: Creating Efficient Replication Solutions

Step 3: Look for Errors by Using Replication Monitor

Page 27: Module 2: Creating Efficient Replication Solutions

Step 4: Confirm Mutual Recognition of Servers

Page 28: Module 2: Creating Efficient Replication Solutions

Step 5: Validate Data

Validation Options

Compute a fast row count Compute an actual row count Compute a checksum

Use stored procedures to validate a subscription

sp_article_validation

sp_publication_validation

sp_table_validation

Handling validation failures

Page 29: Module 2: Creating Efficient Replication Solutions

Practice: Validate Data

Subscribe to a publication

Create an invalid row

Validate data and receive error message

Page 30: Module 2: Creating Efficient Replication Solutions

Step 6: Check Subscription Status

sp_helppublication

Information about all publications

sp_helparticle

Information about all articles

sp_helpsubscription

Information about all subscriptions

Page 31: Module 2: Creating Efficient Replication Solutions

Step 7: Restore the Subscriber to the Current State

SynchronizeSynchronizeSynchronizeSynchronize

Yes

No

Yes

No

Fixed?Fixed?Fixed?Fixed?

Force Force replicationreplication

Force Force replicationreplication

Fixed?Fixed?

ReinitializeReinitializeReinitializeReinitialize

CompleteCompleteCompleteComplete

Page 32: Module 2: Creating Efficient Replication Solutions

Removing Replication

Removal SequenceRemoval SequenceRemoval SequenceRemoval Sequence

Stop the SQL Server Agent Stop the SQL Server Agent

Remove replication with wizardRemove replication with wizard

Delete the distribution databaseDelete the distribution database

Delete the Subscriber tablesDelete the Subscriber tables

PreparationPreparationPreparationPreparation

CreateScriptsCreateScripts

Page 33: Module 2: Creating Efficient Replication Solutions

Review

Understanding the SQL Server Platform for Replication

Replicating Data and Objects

Replicating Data and Executing Objects

Designing a Replication Topology

Troubleshooting a Replication Implementation

Page 34: Module 2: Creating Efficient Replication Solutions

Lab 2: Implementing Replication

Exercise 1: Determining the Replication Type

Exercise 2: Implementing Snapshot Replication

Exercise 3: Implementing Transactional Replication

Exercise 4: Implementing Merge Replication

Exercise 5: Removing Subscriptions and Publications

Page 35: Module 2: Creating Efficient Replication Solutions

Regional OfficeMexico City Local Offices

Regional Offices

Regional OfficeBoston

Regional OfficeLos Angeles

HeadquartersSt. Louis

Regional OfficeAtlanta

Regional OfficeChicago

Lab 2, exercise 1 – Determine the Topology Type