MAGENTA
YELLOW
BLACK
PANTONE 123 CV
RELATED TITLES
Companion eBook
ISBN 1-59059-650-1
Pro
When I started getting my feet wet in database replication more than a decade
ago, I was overwhelmed by the complexity of the different kinds of replication
and the jargon surrounding them. The rapid advancement of replication technology and the evolution of SQL Server 2005 havent made the learning process
any easier. Mastering the terminology, processes, and internal workings of
replication requires time, patience, and, if you are fortunate, access to the right
resources. However, once I overcame the initial hurdle of learning how to configure the different replication types, I soon realized that the internals of replication are not that esoteric. In fact, I marveled at how the different components
worked in harmony to make replication work.
In this book, I discuss the whole gamut of snapshot, transactional, peer-topeer, and merge replication in SQL Server 2005, along with replication across
heterogeneous databases, using real-life scenarios. Knowing the internals of
the different replication types will give you a better understanding of replication. I also describe the use of different tools, like the SSMS, SQLCMD, tablediff,
DTA, and Replication Monitor, introduced in SQL Server 2005 for backing up,
recovering, and optimizing replication. This book will make your learning
process easier and help you acquire the knowledge youll need to solve your
real-life replication problems. I hope after reading this book you will find replication as stimulating and exciting as I do.
This book is the fruit of the knowledge and experience I have acquired over
the years. If you have any questions, please do not hesitate to send me an email.
I can be reached at sujoyp@hotmail.com.
90000
Pro
Sujoy P. Paul
Paul
www.apress.com
Shelve in
SQL Server
89253 59650
9 781590 596500
User level:
IntermediateAdvanced
6501FM.qxd
11/13/06
10:16 AM
Page i
Sujoy P. Paul
6501FM.qxd
11/13/06
10:16 AM
Page ii
6501FM.qxd
11/13/06
10:16 AM
Page iii
6501FM.qxd
11/13/06
10:16 AM
Page iv
6501FM.qxd
11/13/06
10:16 AM
Page v
Contents at a Glance
About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
CHAPTER
CHAPTER
CHAPTER
CHAPTER
CHAPTER
CHAPTER
CHAPTER
CHAPTER
CHAPTER
CHAPTER
CHAPTER
CHAPTER
CHAPTER
CHAPTER
CHAPTER
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
CHAPTER 16
CHAPTER 17
CHAPTER 18
CHAPTER 19
CHAPTER 20
APPENDIX A
APPENDIX B
REFERENCES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 959
INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 961
6501FM.qxd
11/13/06
10:16 AM
Page vi
6501FM.qxd
11/13/06
10:16 AM
Page vii
Contents
About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
CHAPTER 1
CHAPTER 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/DistributorSubscriber Model . . . . . . . . . . . . . . . . . . . . . . . 27
Central PublisherMultiple Subscribers Model . . . . . . . . . . . . . . . . . . 27
Central SubscriberMultiple Publishers Model . . . . . . . . . . . . . . . . . . 29
Multiple PublishersMultiple 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
6501FM.qxd
viii
11/13/06
10:16 AM
Page viii
CONTENTS
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Quick Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
CHAPTER 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
CHAPTER 4
CHAPTER 5
6501FM.qxd
11/13/06
10:16 AM
Page ix
CONTENTS
CHAPTER 6
Snapshot Generation
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
CHAPTER 7
CHAPTER 8
ix
6501FM.qxd
11/13/06
10:16 AM
Page x
CONTENTS
CHAPTER 9
6501FM.qxd
11/13/06
10:16 AM
Page xi
CONTENTS
xi
6501FM.qxd
xii
11/13/06
10:16 AM
Page xii
CONTENTS
Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651
Snapshot Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651
Backing Up the Publication Database . . . . . . . . . . . . . . . . . . . . . . . . 653
Restoring the Publication Database . . . . . . . . . . . . . . . . . . . . . . . . . . 663
Considerations for Other Databases . . . . . . . . . . . . . . . . . . . . . . . . . . 668
6501FM.qxd
11/13/06
10:16 AM
Page xiii
CONTENTS
xiii
6501FM.qxd
xiv
11/13/06
10:16 AM
Page xiv
CONTENTS
APPENDIX A
APPENDIX B
REFERENCES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 959
INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 961
6501FM.qxd
11/13/06
10:16 AM
Page xv
xv
6501FM.qxd
11/13/06
10:16 AM
Page xvi
6501FM.qxd
11/13/06
10:16 AM
Page xvii
xvii
6501FM.qxd
11/13/06
10:16 AM
Page xviii
6501FM.qxd
11/13/06
10:16 AM
Page xix
Acknowledgments
F
irst 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
6501FM.qxd
11/13/06
10:16 AM
Page xx