0% found this document useful (0 votes)
32 views

Fdocuments - in Pro SQL Server 2005 Replication

Fdocuments.in Pro SQL Server 2005 Replication
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Fdocuments - in Pro SQL Server 2005 Replication

Fdocuments.in Pro SQL Server 2005 Replication
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

THE EXPERT’S VOICE ® IN SQL Pro

7/30/2019 SERVER
SQL Server 2005 Replication

Pro
SQL Server 2005
Replication
A comprehensive guide to developing, administering, and
mastering the complexities of replication with SQL Server 2005

Sujoy P. Paul

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 1/21
7/30/2019 Pro SQL Server 2005 Replication

Pro SQL Server 2005


Replication

Sujoy P. Paul

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 2/21
7/30/2019 Pro SQL Server 2005 Replication

Pro SQL Server 2005 Replication


Copyright © 2006 by Sujoy Paul
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.

ISBN-13: 978-1-59059-650-0
ISBN-10: 1-59059-650-1
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark
owner, with no intention of infringement of the trademark.
Lead Editor: Jim Sumser
Technical Reviewer: Judith Myerson
Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Gennick,
Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Dominic Shakeshaft,
Jim Sumser, Keir Thomas, Matt Wade
Project Manager: Sofia Marchant
Copy Edit Manager: Nicole Flores
Copy Editor: Andy Carroll
Assistant Production Director: Kari Brooks-Copony
Production Editor: Ellie Fountain
Compositor: Dina Quan
Proofreader: Linda Seifert
Indexer: Carol Burbo
Artist: Kinetic Publishing Services, LLC
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor,
New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail [email protected], or
visit http://www.springeronline.com.
For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley,
CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail [email protected], or visit http://www.apress.com.
The information in this book is distributed on an “as is” basis, without warranty. Although every precaution
has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability
to any person or entity with respect to any loss or damage caused or alleged to be caused directly or
indirectly by the information contained in this work.
The source code for this book is available to readers at http://www.apress.com in the Source Code section.
You will need to answer questions pertaining to this book in order to successfully download the code.

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 3/21
7/30/2019 Pro SQL Server 2005 Replication

Dedicated to my parents, Subhendu and Kavita Paul

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 4/21
7/30/2019 Pro SQL Server 2005 Replication

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 5/21
7/30/2019 Pro SQL Server 2005 Replication

Contents at a Glance

About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv


About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix

sCHAPTER 1 Introduction: Distributed Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1


sCHAPTER 2 Replication Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
sCHAPTER 3 Types of Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

sCHAPTER 4 Configuring Snapshot Replication Using the GUI . . . . . . . . . . . . . . . . 89


sCHAPTER 5 Configuring Snapshot Replication Using T-SQL . . . . . . . . . . . . . . . . 133
sCHAPTER 6 Snapshot Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
sCHAPTER 7 Internals of Snapshot Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
sCHAPTER 8 Configuring Transactional Replication Using the GUI . . . . . . . . . . . 251
sCHAPTER 9 Configuring Transactional Replication Using T-SQL . . . . . . . . . . . . 301
sCHAPTER 10 Internals of Transactional Replication . . . . . . . . . . . . . . . . . . . . . . . . . 357
sCHAPTER 11 Configuring Merge Replication Using the GUI . . . . . . . . . . . . . . . . . . 445
sCHAPTER 12 Web Synchronization with Merge Replication . . . . . . . . . . . . . . . . . . 491
sCHAPTER 13 Configuring Merge Replication Using T-SQL . . . . . . . . . . . . . . . . . . . 525
sCHAPTER 14 The Internals of Merge Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583
sCHAPTER 15 Backup and Recovery of Snapshot and Transactional
Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651
sCHAPTER 16 Backup and Recovery of Merge Replication. . . . . . . . . . . . . . . . . . . . 715
sCHAPTER 17 Optimizing Snapshot Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 759

sCHAPTER 18 Optimizing Transactional Replication . . . . . . . . . . . . . . . . . . . . . . . . . . 803


sCHAPTER 19 Optimizing Merge Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 867
sCHAPTER 20 Heterogeneous Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 903
sAPPENDIX A E-R Diagram of the mysales Database . . . . . . . . . . . . . . . . . . . . . . . . . 943
sAPPENDIX B SQL Code for the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 947
sREFERENCES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 959

sINDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 961
v

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 6/21
7/30/2019 Pro SQL Server 2005 Replication

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 7/21
7/30/2019 Pro SQL Server 2005 Replication

Contents

About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv


About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix

sCHAPTER 1 Introduction: Distributed Data ..............................1

Distributed Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Methods of Distributing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Distributed Data Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
SQL Server 2005 Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

sCHAPTER 2 Replication Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19


Publisher-Subscriber Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Components of Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Distributor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Publisher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Subscriber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Publication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Article . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Subscriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Agents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Physical Replication Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Publisher/Distributor–Subscriber Model . . . . . . . . . . . . . . . . . . . . . . . 27
Central Publisher–Multiple Subscribers Model . . . . . . . . . . . . . . . . . . 27
Central Subscriber–Multiple Publishers Model . . . . . . . . . . . . . . . . . . 29
Multiple Publishers–Multiple Subscribers Model . . . . . . . . . . . . . . . . 30
Installing and Configuring Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Installing SQL Server Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Configuring with the GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Configuring Database Properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Configuring with T-SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
vii

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 8/21
7/30/2019 Pro SQL Server 2005 Replication

viii sCO NTE NTS

Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

sCHAPTER 3 Types of Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63


Snapshot Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
The Snapshot Agent Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
How Snapshot Replication Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Transactional Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
How Transactional Replication Works . . . . . . . . . . . . . . . . . . . . . . . . . 69
Immediate Updating and Queued Updating Subscriptions . . . . . . . . 70
The Log and Queue Reader Agent Profiles . . . . . . . . . . . . . . . . . . . . . 74
Peer-to-Peer Transactional Replication . . . . . . . . . . . . . . . . . . . . . . . . 77
Merge Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
The Merge Agent Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

sCHAPTER 4 Configuring Snapshot Replication Using the GUI . . . . . . . . . 89


Configuring Publication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Configuring a Subscription. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Configuring Push Subscriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Configuring Pull Subscriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Adding and Deleting an Article . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131

sCHAPTER 5 Configuring Snapshot Replication Using T-SQL. . . . . . . . . . 133


Dropping Subscriptions and Publications . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Dropping a Pull Subscription . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Dropping a Push Subscription . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Dropping a Publication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Configuring a Publication Using T-SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Creating a Publication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Creating a Snapshot Agent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Granting Publication Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Creating Articles for Publication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Starting the Snapshot Agent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 9/21
7/30/2019 Pro SQL Server 2005 Replication

sCO NTE NTS ix

Configuring a Subscription Using T-SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . 150


Configuring Push Subscriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Configuring Pull Subscriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Configuring Anonymous Subscriptions . . . . . . . . . . . . . . . . . . . . . . . 157
. . . . . . . . . . . . . . . . . . . . . . . . . . 158
Snapshot
Summary.Replication
. . . . . . . . . . Stored
. . . . . . .Procedures
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160

sCHAPTER 6 Snapshot Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161

Locating the Snapshot Folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161


Securing Snapshot Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Transmitting and Storing Snapshots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Transferring Compressed Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Transferring a Snapshot with Other Methods . . . . . . . . . . . . . . . . . . 169
Locating the Snapshot Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Determining the Types and Size of Snapshot Files . . . . . . . . . . . . . 171
Transmitting Snapshots Using FTP . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183

sCHAPTER 7 Internals of Snapshot Replication . . . . . . . . . . . . . . . . . . . . . . . . 185

On the Publisher Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185


The Publication Access List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
The Publication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
The Snapshot Agent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
The Distribution Agent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
The Miscellaneous Clean Up Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
On the Distributor Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
The Distribution Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
The MSDB Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
On the Subscriber Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249

sCHAPTER 8 Configuring Transactional Replication Using the GUI . . . 251


Configuring Publications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Configuring Standard Transactional Publications. . . . . . . . . . . . . . . 253
Configuring Transactional Publications with Updatable
Subscriptions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 10/21
7/30/2019 Pro SQL Server 2005 Replication

x sCO NTE NTS

Configuring Subscriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274


Configuring Updatable Subscriptions for Transactional
Publication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Switching Update Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
. . . . . . . . . . . . . . . . . 286
Configuring
SettingPeer-to-Peer
Up the Publication Transactional
. . . . . . . Replication
. . . . . . . . . . . . . . . . . . . . . . . . . . . 286
Enabling the Publication for Peer-to-Peer Replication . . . . . . . . . . 288
Initializing the Database Schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Configuring Peer-to-Peer Topology . . . . . . . . . . . . . . . . . . . . . . . . . . 292
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300

sCHAPTER 9 Configuring Transactional Replication Using T-SQL . . . . . 301


Configuring Publication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
Configuring Standard Transactional Publication. . . . . . . . . . . . . . . . 303
Configuring a Push Subscription for Standard Publication . . . . . . . 313
Configuring a Pull Subscription for Standard Publication . . . . . . . . 315
Configuring Transactional Publication with Updatable
Subscriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
Configuring a Pull Subscription for Immediate Updating . . . . . . . . 322
Configuring a Push Subscription for Immediate Updating . . . . . . . 327
Configuring a Push Subscription for Queued Updating . . . . . . . . . . 329
Configuring a Pull Subscription for Queued Updating . . . . . . . . . . . 330
Switching Between Immediate and Queued Updating
Subscriptions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
Configuring Peer-to-Peer Transactional Replication . . . . . . . . . . . . . . . . . 335
Adding the Publication on Node A . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
Adding the Articles to the Publication on Node A . . . . . . . . . . . . . . . 336
Adding the Subscription on Node A . . . . . . . . . . . . . . . . . . . . . . . . . . 337
Adding the Push Subscription Agent on Node A . . . . . . . . . . . . . . . . 337
Adding the Publication on Node B. . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
Adding the Articles to the Publication on Node B . . . . . . . . . . . . . . . 339
Adding the Subscription on Node B . . . . . . . . . . . . . . . . . . . . . . . . . . 340
Adding the Push Subscription Agent on Node B. . . . . . . . . . . . . . . . 340
Checking the Configuration for Peer-to-Peer Replication . . . . . . . . 341
Configuring Bidirectional Transactional Replication . . . . . . . . . . . . . . . . . 343
Transactional Replication Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . 351
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 11/21
7/30/2019 Pro SQL Server 2005 Replication

sCO NTE NTS xi

sCHAPTER 10 Internals of Transactional Replication . . . . . . . . . . . . . . . . . . . 357

Concurrent Snapshot Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357


The Transaction Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
The Log Reader Agent. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
The Queue Reader Agent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
Transactional Replication with Queued Updating . . . . . . . . . . . . . . . . . . . 383
The Publication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
The Subscriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
Conflict Detection and Resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
Transactional Replication with Immediate Updating . . . . . . . . . . . . . . . . . 399
The Publication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
The Subscriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
Peer-to-Peer Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
Standard Transactional Publication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
The Publication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
The Distribution Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443

sCHAPTER 11 Configuring Merge Replication Using the GUI . . . . . . . . . . . . 445


Configuring Publication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446

Configuring a Publication for Download-Only Articles . . . . . . . . . . . 446


Configuring a Publication for Standard Articles . . . . . . . . . . . . . . . . 454
Adding Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458
Configuring Subscriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
Configuring Pull Subscriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
Configuring Push Subscriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490

sCHAPTER 12 Web Synchronization with Merge Replication . . . . . . . . . . . 491


Web Synchronization Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
Configuring a Publication for Web Synchronization . . . . . . . . . . . . . . . . . . 492
Configuring IIS for Web Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . 494
Configuring SSL for Web Synchronization . . . . . . . . . . . . . . . . . . . . . 495
Configuring the IIS Server for Web Synchronization . . . . . . . . . . . . 504
Setting Permissions for the SQL Server Replication Listener . . . . . 512
Running IIS in Diagnostic Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 12/21
7/30/2019 Pro SQL Server 2005 Replication

xii sCO NTE NTS

Configuring Subscriptions for Web Synchronization . . . . . . . . . . . . . . . . . 516


Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524

sCHAPTER 13 Configuring Merge Replication Using T-SQL . . . . . . . . . . . . . 525


Configuring Publications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525
Configuring Publication with Download-Only Articles . . . . . . . . . . . 527
Configuring Publication with Standard Articles . . . . . . . . . . . . . . . . 533
Configuring Subscriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 565
Configuring Client-Type Push Subscriptions for Download-Only
Articles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 565
Configuring Pull Subscriptions for Standard Articles . . . . . . . . . . . . 569
Identity Range Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 572
Configuring Automatic Range Management . . . . . . . . . . . . . . . . . . . 573
Merge Replication Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582

sCHAPTER 14 The Internals of Merge Replication . . . . . . . . . . . . . . . . . . . . . . . 583


The Merge Agent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583
Subsystems and Proxies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592
Using SQLCMD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592
The Roles of Subsystems and Proxies . . . . . . . . . . . . . . . . . . . . . . . . 597
Publication and Subscriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610
Publication with Download-Only Articles . . . . . . . . . . . . . . . . . . . . . . 611
Publication with Standard Articles and Parameterized Filters . . . . 627
Conflict Detection and Resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 650

sCHAPTER 15 Backup and Recovery of Snapshot and Transactional


Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651
Snapshot Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651
Backing Up the Publication Database . . . . . . . . . . . . . . . . . . . . . . . . 653
Restoring the Publication Database . . . . . . . . . . . . . . . . . . . . . . . . . . 663
Considerations for Other Databases . . . . . . . . . . . . . . . . . . . . . . . . . . 668

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 13/21
7/30/2019 Pro SQL Server 2005 Replication

sCO NTE NTS xiii

Transactional Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669


Validating Subscriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669
Standard Read-Only Transactional Replication . . . . . . . . . . . . . . . . 678
Transactional Publication with Updatable Subscriptions . . . . . . . . 688
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 696
Peer-to-Peer
Log Shipping Replication
with Transactional Replication . . . . . . . . . . . . . . . . . . 700
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 711
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 713

sCHAPTER 16 Backup and Recovery of Merge Replication . . . . . . . . . . . . . 715


Publication with Download-Only Articles . . . . . . . . . . . . . . . . . . . . . . . . . . . 715
Backing Up the Publication Database . . . . . . . . . . . . . . . . . . . . . . . . 716
Restoring the Publication Database for Push Subscription. . . . . . . 716
Restoring the Publication Database for Pull Subscription . . . . . . . . 722
Synchronizing Subscriptions with No-Sync Initialization
Using T-SQL and SQLCMD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 740
Backing Up and Restoring Subscription Databases . . . . . . . . . . . . . . . . . . 742
Validating Subscriptions for Merge Replication . . . . . . . . . . . . . . . . . . . . . 745
Log Shipping with Download-Only Articles . . . . . . . . . . . . . . . . . . . . . . . . . 750
Configuring Log Shipping on the Primary Server . . . . . . . . . . . . . . . 751
Configuring Log Shipping on the Secondary Server . . . . . . . . . . . . 753
Adding the Secondary Server Information to the Primary
Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 756
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 757
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 758

sCHAPTER 17 Optimizing Snapshot Replication . . . . . . . . . . . . . . . . . . . . . . . . . 759


Optimizing Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 759
Using the System Monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 761
Using SQL Server Profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784
Best Practices for Snapshot Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . 798
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 800
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 802

sCHAPTER 18 Optimizing Transactional Replication . . . . . . . . . . . . . . . . . . . . 803


Performance Considerations for the Transaction Log . . . . . . . . . . . . . . . . 803
Using Tracer Tokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 806
Using the System Monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 812
Using SQL Trace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 818

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 14/21
7/30/2019 Pro SQL Server 2005 Replication

xiv sCO NTE NTS

Using the Database Engine Tuning Advisor . . . . . . . . . . . . . . . . . . . . . . . . 841


Best Practices for Transactional Replication . . . . . . . . . . . . . . . . . . . . . . . 860
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 865
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 866

sCHAPTER 19 Optimizing Merge Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 867


Using the System Monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 867
Using the SQL Server Profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 869
Adjusting Publication Retention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 894
Changing Merge Agent Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 895
Snapshot Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 897
Best Practices for Merge Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 898
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 901
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 902

sCHAPTER 20 Heterogeneous Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 903


Snapshot Replication from an Oracle Publisher to a SQL Server
Subscriber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 903
Configuring an Oracle Publication for Snapshot Replication . . . . . 903
Configuring a SQL Server Subscription for Snapshot
Publication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 914
Monitoring Replication with Replication Monitor . . . . . . . . . . . . . . . 920
Transactional Replication from an Oracle Publisher to a SQL Server
Subscriber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 923
Configuring an Oracle Publication for Transactional
Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 924
Configuring a SQL Server Subscription for Transactional
Publication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 931
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 940
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 941

sAPPENDIX A E-R Diagram of the mysales Database . . . . . . . . . . . . . . . . . . . 943


sAPPENDIX B SQL Code for the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 947
sREFERENCES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 959

sINDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 961

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 15/21
7/30/2019 Pro SQL Server 2005 Replication

About the Author

sSUJOY PAUL has a bachelor’s degree in chemical engineering from


the University of Toronto, Canada, and a postgraduate degree in the
same discipline from the University of Strathclyde, Glasgow, UK. Since
then, he has moved on to the software industry and has gained exten-
sive experience in database management systems, such as Microsoft
SQL Server 2000, Sybase ASA, and Sybase ASE; data modeling; and
case-based tools like PowerDesigner and ERWIN. His background
includes expertise in database replication, with a special interest in
two-way replication, backup and recovery, performance and tuning,
and troubleshooting. He is a Microsoft Certified Professional on SQL Server 2000. His other
professional interests include knowledge management, semantic web, and bioinformatics,
in which he also has a postgraduate diploma. Currently, he is working for a major consulting
company in Toronto, Canada.
He is an avid fan of soccer and tennis. In his spare time he plays squash and enjoys reading
literature, and he has also published poetry. He can be reached at [email protected].

xv

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 16/21
7/30/2019 Pro SQL Server 2005 Replication

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 17/21
7/30/2019 Pro SQL Server 2005 Replication

About the Technical Reviewer

sJUDITH M. MYERSON is a systems architect and engineer. Her areas of interest include middle-
ware technologies, application development, web development, software engineering,
network management, servers, security management, information assurance, standards,
RFID technologies, and project management. Judith holds a Master of Science degree in
engineering, and is a member of the IEEE organization. She has reviewed/edited a number
of books, including Hardening Linux, Creating Client Extranets with SharePoint 2003, and
Microsoft SharePoint: Building Office 2003 Solutions.

xvii

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 18/21
7/30/2019 Pro SQL Server 2005 Replication

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 19/21
7/30/2019 Pro SQL Server 2005 Replication

Acknowledgments

First of all, I would like to thank Mr. Jim Sumser, without whose constant encouragement and
support this book would not have been possible. I would also like to thank Mr. Andy Carroll, Ms.
Ellie Fountain, Ms. Kylie Johnson, Ms. Sofia Marchant, Ms. Judith Myerson, and the rest of the
Apress team for their unending patience and superb professionalism in constantly striving for
excellence. They also gave me sufficient time even when the deadlines had elapsed. I sincerely
appreciate that.
I would like to thank my parents for helping me in pursuing my dreams, and my sister,
Manashi, who taught me how to dream and helped develop the savoir faire in me. I would also
like to thank Didi, Ajoyda, Mohor, Gogol, Ma, Anjanda, Shweta, and my dear friend Bob for
being there for me. Finally, I would like to thank my wife, Aditi, who suffered the most during
this venture. Her tireless support in proofreading my writing, editing the figures every day and
night, and bearing all of this with a smile on her face made it all the more worthwhile.

xix

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 20/21
7/30/2019 Pro SQL Server 2005 Replication

http://slidepdf.com/reader/full/pro-sql-server-2005-replication 21/21

You might also like