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
Lesson: Understanding the SQL Server Platform for Replication Understanding Operating System Implications for Replication Understanding SQL Server Installation Implications for Replication
Understanding Operating System Implications for Replication Operating systems that CAN be used for transactional replication Publisher Operating systems that CANNOT be used for transactional replication Publisher Windows NT Windows 95 Windows 2000 Windows 98 Windows XP Windows Me, Windows CE
Understanding SQL Server Installation Implications for Replication Licensing Licensing requirements detailed on 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
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
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
Planning to Publish Table Schema Objects Primary key constraints Reference constraints Unique constraints Clustered and nonclustered indexes User triggers Extended properties Collation
Replicating Filtered Data Vertical Filtering ABCDEF ABE Table A Horizontal Filtering ABCDEF ABCDEF Table B Subscriber Publisher
These Objects Rely on These Tables Replicating Schema Objects – Views, UDFs, and Stored Procedures CREATE VIEW vw_EmployeeDept AS... CREATE FUNCTION fn_PayPeriod AS... CREATE VIEW vw_EmployeeDept AS... CREATE FUNCTION fn_PayPeriod AS... CREATE PROCEDURE pr_ValidateVac AS... Replicate View, UDF, Stored Procedures REPLICATED SEPARATELY Replicate View, UDF, Stored Procedures REPLICATED SEPARATELY Replicate Tables
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
Reducing Replication Volume with Stored Procedures UPDATE 200,000 Rows The execution of stored procedures UPDATE 200,000 Rows Create stored procedure to update affected rows 11 Publish the stored procedure; replication creates copies on each Subscriber 22 Execute the stored procedure on the Publisher 33 EXEC command is replicated 44 Update runs locally on Subscribers
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
Replicating with On-Demand Script Execution Script execution uses osql.exe Script is replicated 11 Script executes locally Truncate Table Truncate Table Truncate Table Truncate Table Truncate Table Truncate Table Truncate Table Truncate Table
Subscriber Publisher EXEC pr_Update Preventing Data Inconsistencies from the Execution of Stored Procedures UPDATE Table 1 UPDATE Table 2 Table 1 Table 2 EXEC pr_Update UPDATE Table 1 Table 1 UPDATE Table 2 Table 2 Publisher and Subscriber do not match Constraint Violation Table 2 Constraint Violation
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
Central Publisher and Distributor Moscow Rome Paris Athens London Berlin headquarters Central Publisher and Distributor Remote Distribution Central Publisher and Distributor
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 republishes to Beijing, Hong Kong, and Sydney
Republisher for Scale Out London Dakar Worldwide Headquarters Rome European Headquarters New York Atlanta North American Headquarters Caracas Madrid
Central Subscriber with Partitioned Data Seattle New York San Francisco Dallas headquarters Mexico City
Bidirectional Partitioned Topology New York The New York Office updates customers in the East Region No conflicts exist The San Francisco Office updates customers in the West Region San Francisco ABCDEF
Bidirectional Non-Partitioned Topology New York Both offices update the same data San Francisco ABCDEF
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
Step 1: Keep a Performance Baseline
Step 2: Check Replication Alerts Default Alerts Agent success Agent failure Agent retry Subscriber has passed data validation Subscription cleaned up Subscriber has failed data validation Subscription reinitialized after data validation
Step 3: Look for Errors by Using Replication Monitor
Step 4: Confirm Mutual Recognition of Servers
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
Practice: Validate Data Subscribe to a publication Create an invalid row Validate data and receive error message
Step 6: Check Subscription Status sp_helppublication Information about all publications sp_helparticle Information about all articles sp_helpsubscription Information about all subscriptions
Step 7: Restore the Subscriber to the Current StateSynchronizeSynchronize Yes No Yes No Fixed?Fixed? Force replication Fixed? ReinitializeReinitialize CompleteComplete
Removing Replication Removal Sequence Stop the SQL Server Agent Remove replication with wizard Delete the distribution database Delete the Subscriber tables PreparationPreparation Create Scripts Create Scripts
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
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
Lab 2, exercise 1 – Determine the Topology Type Regional Office Mexico City Local Offices Regional Offices Regional Office Boston Regional Office Los Angeles Headquarters St. Louis Regional Office Atlanta Regional Office Chicago
Regional Office Mexico City Local Offices Regional Offices Regional Office Boston Regional Office Los Angeles Headquarters St. Louis Regional Office Atlanta Regional Office Chicago Lab 2, exercise 1 – Determine the Topology Type