Module 4: Implementing Transactional Replication.
-
Upload
philippa-hutchinson -
Category
Documents
-
view
224 -
download
0
Transcript of Module 4: Implementing Transactional Replication.
Module 4:Implementing Transactional Replication
Overview
Understanding Transactional Replication Architecture
Replicating with Transactional Replication
Implementing Updatable Transactional Replication
Facilitating Transactional Replication by Using Stored Procedures
Troubleshooting Transactional Replication
Tuning Transactional Replication
Lesson: Understanding Transactional Replication Architecture
How Transactional Replication Moves Data
The Role of the Log Reader Agent
How the Log Reader Agent Reads the Transaction Log
How the Log Reader Agent Changes Transaction Syntax
The Role of the Distribution Agent
Independent and Shared Agents
Concurrent Snapshot Generation
How Transactional Replication Moves Data
Snapshot ensures synchronized table schema and dataSnapshot ensures synchronized table schema and data
Log Reader Agent scans transaction logLog Reader Agent scans transaction log
Log Reader Agent copies transactions marked for replication to DistributorLog Reader Agent copies transactions marked for replication to Distributor
Distribution Agent moves transactions from Distributor to SubscribersDistribution Agent moves transactions from Distributor to Subscribers
The Role of the Log Reader Agent
1111 The Log Reader Agent is created when the first transactional publication is created on the Publisher
Log Reader Log Reader AgentAgent
Log Reader Log Reader AgentAgentCreatedCreatedCreatedCreated2222 The Log Reader Agent looks
in the distribution database for the last LSN read
Each time the Log Reader Agent runs:
3333 The Log Reader Agent reads the transaction log of the publishing database starting with the next LSN
distributiondistribution
LSN: 18
Transaction log
Transaction log
1111 The Log Reader Agent is created when the first transactional publication is created on the Publisher
Log Reader Log Reader AgentAgent
Log Reader Log Reader AgentAgent
2222 The Log Reader Agent looks in the distribution database for the last LSN read
Each time the Log Reader Agent runs:
3333 The Log Reader Agent reads the transaction log of the publication database starting with the next LSN
distributiondistribution
LSN: 18
Transaction log
Transaction log
11 3322
How the Log Reader Agent Reads the Transaction Log
1111 Finds the next LSN
2222 Starts reading transactions
3333 Ignores transactions related to nonpublished objects
4444 Copies the published transactions to the distribution database
5555 Marks the log as transactions read to here
LSN:************** 29: XXXXX
LSN:************** 17: UPDATELSN:************** 18: XXXXX LSN:************** 19: UPDATE LSN:************** 20: UPDATE LSN:************** 21: INSERTLSN:************** 22: DELETELSN:************** 23: UPDATELSN:************** 24: INSERTLSN:************** 25: INSERTLSN:************** 26: UPDATE LSN:************** 27: INSERT LSN:************** 28: INSERT
UPDATEUPDATEINSERTUPDATE …
6666 Anything prior to the mark can be truncated
11 3322
How the Log Reader Agent Changes Transaction Syntax
INSERT INTO Emp VALUES (57, 'Bremer', 'Ted') INSERT INTO Emp VALUES (57, 'Bremer', 'Ted')
CALL sp_MSins_Emp (57, 'Bremer', 'Ted') CALL sp_MSins_Emp (57, 'Bremer', 'Ted') May convert to astored procedureMay convert to astored procedure
UPDATE XYZ SET …UPDATE XYZ SET …
DELETE XYZ …INSERT XYZ …
DELETE XYZ …INSERT XYZ …
May convert to anDELETE/INSERT
May convert to anDELETE/INSERT
UPDATE Emp SET Phone = '5559521' WHERE LastName = 'Bremer' AND FirstName = 'Ted'
UPDATE Emp SET Phone = '5559521' WHERE LastName = 'Bremer' AND FirstName = 'Ted'
CALL sp_MSupd_Emp (57, '5559521') CALL sp_MSupd_Emp (57, '5559521') Uses primary keyUses primary key
11 3322
The Role of the Distribution Agent
distribution database
distribution database
subscribing database
subscribing database
subscribing database
subscribing database
Distribution Distribution AgentAgent
Distribution Distribution AgentAgent
DTSPackage
DTSDTSData PumpData Pump
DTSDTSData PumpData Pump
Transformable subscriptions only
Transformable subscriptions only
11 3322
subscribing database
subscribing database
subscribing database
subscribing database
Independent and Shared Agents
Shared Agent
Shared Agent
Independent Agent
Independent Agent
Independent Agent
Independent Agent
Concurrent Snapshot Generation
Marks the log
Copies the tables
Marks the log
Checks the log between the marks for transactions marked for replication
Applies the initial snapshot
Applies the transactions copied from the marked portion of the log
Publishing Database
Transaction log
Transaction log
INSERT…X
Subscribing Database
Tablesprocsviews
Tablesprocsviews
Distributor
SQLSQL
1111
2222
3333
4444
5555
6666
X
INSERT…
INSERT…
11 3322
Lesson: Replicating with Transactional Replication
Designing Tables for Transactional Replication
Replicating text, ntext, and image Data
Replicating Horizontally Filtered Data
Overhead of Filtering for Transactional Replication
Designing Tables for Transactional Replication
Y Related row
INSERT X, Y, Z
Insert on Publisher checks the relationship
Insert on Publisher checks the relationship
It is not necessary to check again on the Subscriber
It is not necessary to check again on the Subscriber
ReplicationReplicationReplicationReplication
ReplicationReplicationReplicationReplication
Use NOT FOR REPLICATION for relationshipsUse NOT FOR REPLICATION for relationshipsUse NOT FOR REPLICATION for relationshipsUse NOT FOR REPLICATION for relationships
11 3322
Y Related row
INSERT X, Y, Z
Practice: Designing Tables for Transactional Replication
Adding syntax
ALTER TABLE and CLUSTERED INDEX
ALTER TABLE and FOREIGN KEY
CREATE TRIGGER
Replicating text, ntext, and image Data
Reinitialize the publication if nonlogged operations have occurred
Use the WITH LOG option with text operations
Use max text repl size with ODBC subscribers
Replicating Horizontally Filtered Data
CREATE PROCEDURE CustFilter FOR REPLICATION ASIF EXISTS ( SELECT Country FROM Customers WHERE Country IN (SELECT Country FROM Promotion (NOLOCK)) RETURN 1ELSE RETURN 0
CREATE PROCEDURE CustFilter FOR REPLICATION ASIF EXISTS ( SELECT Country FROM Customers WHERE Country IN (SELECT Country FROM Promotion (NOLOCK)) RETURN 1ELSE RETURN 0
Overhead of Filtering in Transactional Replication
Number of filters
Every row tested against every filter
Each filter is evaluated independently
Complexity
Complexity determines overhead
Joins, functions, comparisons, and indexes contribute to overhead
Lesson: Implementing Updatable Transactional Replication
What Are Updating Subscriptions?
Limitations of Updating Subscriptions
How Subscribers Using Immediate Updating Subscriptions Update Tables
Schema Alterations for Subscribers Using Immediate Updating Subscriptions
Choosing a Queue Type
How Queued Updating Subscriptions Update Tables (SQL Server 2000 queue)
How Queued Updating Subscriptions Update Tables (MSMQ)
Managing Conflicts with Subscribers Using Queued Updating Subscriptions
Implementing Immediate Updating with Failover to Queued Updating
Managing Identity Values for Updating Subscriptions
Subscriber using immediate updating
subscription
Subscriber using queued
updating subscription
What Are Updating Subscriptions?
Publisher
Distributor
Queue Reader Agent
Reliable Connection
Reliable Connection
Queue
IntermittentConnectionIntermittentConnection
11 3322
Limitations of Updating Subscriptions
No merge replication
No republishing replicated data at the Subscriber
All text and image data should be treated as read-only
Cannot disable the updating subscription
Cannot use INSERT statements without a column list
Cannot combine with transformable subscriptions
Cannot use pre-existing data at Subscribers
How Subscribers Using Immediate Updating Subscriptions Update Tables
Publisher updates table and forwards transactionsPublisher updates table and forwards transactions
Subscriber starts transaction and connects with MS DTCSubscriber starts transaction and connects with MS DTC
MS DTC completes data modification with two-phase commit (2PC)MS DTC completes data modification with two-phase commit (2PC)
Publisher distributes update to other Subscribers according to schedulePublisher distributes update to other Subscribers according to schedule
Schema Alterations for Subscribers Using Immediate Updating Subscriptions
MSrepl_tran_version
Added by wizard if needed
Include vertical filter
Add to column list
System-defined triggers
Added automatically when subscribers enabled
Make calls to MS DTC
Avoiding a trigger-firing loop
Fire user-defined triggers after immediate updating triggers
Choosing a Queue Type
SQL Server 2000 queue
Works with all SQL Server platforms
Easy to set up
No additional components to install
Faster
Microsoft Message Queue (MSMQ)
Centralized queue administration and monitoring
Propagate changes when Subscriber is not running SQL Server
Does not require available Publisher when Subscriber reconnects
Publisher updates table and forwards transactions using typical transactional replicationPublisher updates table and forwards transactions using typical transactional replication
Subscriber trigger places copy of new transactions in MSreplication_queueSubscriber trigger places copy of new transactions in MSreplication_queue
SQL Server Queue Reader Agent checks for new rows to be moved to Distributor queueSQL Server Queue Reader Agent checks for new rows to be moved to Distributor queue
SQL Server Queue Reader Agent uses MS DTC to move rows to PublisherSQL Server Queue Reader Agent uses MS DTC to move rows to Publisher
Publisher distributes update to other SubscribersPublisher distributes update to other Subscribers
SQL Server 2000 Queue:SQL Server 2000 Queue:SQL Server 2000 Queue:SQL Server 2000 Queue:
How Queued Updating Subscriptions Update Tables (SQL Server 2000 Queue)
Publisher updates table and forwards transactions using typical transactional replicationPublisher updates table and forwards transactions using typical transactional replication
MSMQ places transaction in MSMQ-managed queueMSMQ places transaction in MSMQ-managed queue
MSMQ service on Subscriber moves row to MSMQ service on Distributor by using MS DTCMSMQ service on Subscriber moves row to MSMQ service on Distributor by using MS DTC
MSMQ service on Distributor connects to Publisher and updates Subscriber table by using MS DTCMSMQ service on Distributor connects to Publisher and updates Subscriber table by using MS DTC
Publisher distributes update to other SubscribersPublisher distributes update to other Subscribers
MSMQ:MSMQ:MSMQ:MSMQ:
How Queued Updating Subscriptions Update Tables (MSMQ)
Managing Conflicts with Subscribers Using Queued Updating Subscriptions
How SQL Server detects conflicts
Choosing a conflict resolver
Keep change made at Publisher
Keep change made at Subscriber
Reinitialize the subscription
Implementing Immediate Updating with Failover to Queued Updating
Immediate updatingImmediate updatingImmediate updatingImmediate updating
1111 Using immediate updating
2222 Connection is unavailable
3333 Switch to queuing
4444 When connection is available – empty the queue
5555 Resume immediate updating
11 3322
QueueQueue1.
2.
3.
4.
4. 3. 2. 1. 4. 3. 2. 1.
Managing Identity Values for Updating Subscriptions
Methods for managing identity values
Use SQL Server 2000 automatic management Use the NOT FOR REPLICATION option Use a primary key other than the identity column
Identity values and immediate updating
Publisher controls identity values You cannot assign identity ranges
Identity values and queued updating
Assigned by the Subscriber Identity values and queued updating failover
Assign identity ranges to Subscribers Inserted rows generate identity values from the range
Lesson: Facilitating Transactional Replication by Using Stored Procedures
Understanding Custom Stored Procedures for Replication
Creating Custom Stored Procedures
Implementing Custom Stored Procedures
Understanding Custom Stored Procedures for Replication
Benefits of custom stored procedures
Improved performance Less data passed over the network
Command types
CALL MCALL XCALL SQL NONE
Creating Custom Stored Procedures
sp_scriptinsproc
sp_scriptdelproc
sp_scriptupdproc
sp_scriptmappedupdproc
sp_scriptdynamicupdproc
sp_scriptpublicationcustomprocs
Implementing Custom Stored Procedures
Lesson: Troubleshooting Transactional Replication
Troubleshooting by Using the Distribution and Log Reader Agents
Troubleshooting by Using Stored Procedures
Skipping Errors to Prevent Replication Halts
Reinitializing Subscriptions
Troubleshooting Steps
Troubleshooting Guidelines
Troubleshooting by Using the Distribution and Log Reader Agents
"C:\Program Files\Microsoft SQL Server\80\COM\logread" -Publisher [VANCOUVER] -PublisherDB [Northwind] -DistributorSecurityMode 1
"C:\Program Files\Microsoft SQL Server\80\COM\logread" -Publisher [VANCOUVER] -PublisherDB [Northwind] -DistributorSecurityMode 1
"C:\Program Files\Microsoft SQL Server\80\COM\distrib" -Publisher [VANCOUVER] -PublisherDB [Northwind] -Publication [CustomersTransactional] -DistributorSecurityMode 1
"C:\Program Files\Microsoft SQL Server\80\COM\distrib" -Publisher [VANCOUVER] -PublisherDB [Northwind] -Publication [CustomersTransactional] -DistributorSecurityMode 1
Log Reader AgentLog Reader AgentLog Reader AgentLog Reader Agent
Distribution AgentDistribution AgentDistribution AgentDistribution Agent
Troubleshooting by Using Stored Procedures
sp_browsereplcmds – Commands waiting at Distributor
sp_replshowcmds – Commands waiting at Publisher
sp_repltrans – LSNs in transaction log
sp_replflush – Stop acting as the Log Reader Agent
sp_repldone – System use only
sp_replqueuemonitor – Lists queue messages
DBCC OPENTRAN – Returns oldest LSNs
sp_replcmds – System use only
Practice: Troubleshooting by Using Stored Procedures
Create a push subscription and subscribe
Identify commands at Distributor
Identify commands at Publisher
Skipping Errors to Prevent Replication Halts
Reinitializing Subscriptions
Troubleshooting Steps
Check Replication Monitor
Change -BatchCommitSize
Disable Cleanup
Rerun distribution
Check MSreplication_subscriptions
Identify the row
Narrow the query
Map the sequence number
Display commands
Troubleshooting Guidelines
Use SQL error logs
Run DBCC checks
Check for blocking issues
Analyze index and query performance on subscribing tables
View application and System Event Viewer logs
Check triggers
Lesson: Tuning Transactional Replication
Identifying Subscriber Factors That Degrade Performance
Improving Performance Through Design and Configuration
Improving Performance by Using Appropriate Subscription Types and Scheduling
Improving Performance by Using Agent Properties
Identifying Subscriber Factors That Degrade Performance
Subscriber computer factors
Subscription database or SQL Server setup factors
Network speed or connection factors
Additional factors
Improving Performance Through Design and Configuration
Design factors
Use custom stored procedures
Avoid individual row evaluation
Publish as indexed views instead of filtered tables
Avoid the update of unique constrained columns
Configuration factors
Set the distribution database to a fixed size
Configure the Distributor on a dedicated server
Improving Performance by Using Appropriate Subscription Types and Scheduling
Subscription factors
Use push and pull subscriptions appropriately
Use anonymous subscriptions appropriately
Scheduling factors
Run agents continuously
Reduce distribution frequency
Schedule snapshots during periods of low activity
Improving Performance by Using Agent Properties
Property of both the Log Reader Agent and Distribution Agent
Use -PollingInterval parameter to adjust latency Log Reader Agent Properties
Increase -ReadBatchSize parameter Retain -ReadBatchThreshold default Adjust the -MaxCmdsInTran setting
Distribution Agent Properties
Increase -CommitBatchSize and -CommitBatchThreshold defaults
Review
Understanding Transactional Replication Architecture
Replicating with Transactional Replication
Implementing Updatable Transactional Replication
Facilitating Transactional Replication by Using Stored Procedures
Troubleshooting Transactional Replication
Tuning Transactional Replication
Lab 4: Implementing Transactional Replication
Exercise 1: Designing a Transactional Replication Solution
Course Evaluation