Вы находитесь на странице: 1из 8

CHAP1fR l7 5l3

C HAP T k l7
RepIcaton
1
he primary purpose o replicaLion is Lo disLribuLe daLa rom a masLer daLabase Lo one
or more secondary daLabases. 8ecause replicaLion mainLains a duplicaLe copy o daLa in
synchronizaLion wiLh Lhe masLer copy, Lhe Lechnology can be used Lo provide availabiliLy or
applicaLions.
1his chapLer provides a basic overview o Lhe replicaLion engine, along wiLh Lhe varieLy
o opLions LhaL you can use Lo disLribuLe daLa. lL also explains how you can use Lhe daLa
disLribuLion mechanisms Lo provide an exLremely low-laLency availabiliLy soluLion LhaL also
has Lhe capabiliLy Lo minimize downLime in Lhe evenL a ailback is necessary.
fxam objectve n ths chapter:
lmplemenL replicaLion
Lessons n ths chapter:
Lesson . Overview o ReplicaLion 5l4
Lesson 2. 1ransacLional ReplicaLion 526
Lesson 8. Merge ReplicaLion 538
Before You Begin
1o compleLe Lhe lessons in Lhis chapLer, you musL have.
One insLance o MicrosoL SL Server 2008 insLalled, eiLher LnLerprise, SLandard, or
Developer ediLion
1he AJventureWcrls daLabase insLalled
1wo daLabases named AW1rcnsccticncl and AWMere LhaL are copies o Lhe
AJventureWcrls daLabase
!& SkVlC ACCOUNTS
1he repIcaton engne uses named accounts for securty. 1herefore, the servce account
that SQL Server and SQL Server Agent are runnng under must be ether IocaI or doman
accounts. You cannot use locclsystem for the servce account.
!& SkVlC ACCOUNTS
1he repIcaton engne uses named accounts for securty. 1herefore, the servce account
that SQL Server and SQL Server Agent are runnng under must be ether IocaI or doman
accounts. You cannot use locclsystem for the servce account.
Lesson . Overview o ReplicaLion CHAP1fR l7 523
8ULK lNSLR1
8CP
SLLLC1. . .lN1O
RepIcaton s concerned wth onIy three of these operatons-TRUNCATL TA8LL, 8ULK
lNSLRT, and 8CP-because each affects data wthn a tabIe. If the database s pIaced nto
the SmpIe or uIk-Iogged recovery modeI and any of these operatons s executed, the
repIcaton engne cannot pck up the changes because transactonaI repIcaton reIes on
transactons n the transacton Iog, and merge repIcaton reIes on trggers.
Quick Check
I. What are the three methods of repIcaton?
2. What are the ve agents used n repIcaton?
3. What are the three types of data concts?
4. What are the two roIes that a database can have wthn a repIcaton archtecture?
5. What are the core components of repIcaton?
Quick Check Answers
I. Snapshot, transactonaI, and merge.
2. Snapshot Agent (snapshot.exe), Log Reader Agent (Iogread.exe), Dstrbuton
Agent (dstrb.exe), Merge Agent (repImerg.exe), and Queue Reader Agent
(qrdrsvc.exe).
3. Insert of a dupIcate prmary key, update conct, and update of a nonexstent row.
4. PubIsher or subscrber.
5. One or more artcIes are combned nto a pubIcaton that forms the bass of a
repIcaton sesson. 1he artcIes can optonaIIy have Iters appIed to them.
ln Lhis pracLice, you conIgure publishing on your insLance o SL Server.
!& LAkNlNG kPLlCATlON
1he practces n ths chapter congure a repIcaton envronment usng the settngs that I aIways
recommend when Iearnng repIcaton. You congure the pubIsher, subscrber, and dstrbutor
aII wthn the same nstance, whch has the effect of repIcatng between two databases on the
same nstance. 1hs s the most straghtforward way to Iearn repIcaton because t eImnates
the two most common causes of conguraton ssues n repIcaton: securty and connectvty.
8ULK lNSLR1
8CP
SLLLC1. . .lN1O
RepIcaton s concerned wth onIy three of these operatons-TRUNCATL TA8LL, 8ULK
lNSLRT, and 8CP-because each affects data wthn a tabIe. If the database s pIaced nto
the SmpIe or uIk-Iogged recovery modeI and any of these operatons s executed, the
repIcaton engne cannot pck up the changes because transactonaI repIcaton reIes on
transactons n the transacton Iog, and merge repIcaton reIes on trggers.
Quick Check
I. What are the three methods of repIcaton?
2. What are the ve agents used n repIcaton?
3. What are the three types of data concts?
4. What are the two roIes that a database can have wthn a repIcaton archtecture?
5. What are the core components of repIcaton?
Quick Check Answers
I. Snapshot, transactonaI, and merge.
2. Snapshot Agent (snapshot.exe), Log Reader Agent (Iogread.exe), Dstrbuton
Agent (dstrb.exe), Merge Agent (repImerg.exe), and Queue Reader Agent
(qrdrsvc.exe).
3. Insert of a dupIcate prmary key, update conct, and update of a nonexstent row.
4. PubIsher or subscrber.
5. One or more artcIes are combned nto a pubIcaton that forms the bass of a
repIcaton sesson. 1he artcIes can optonaIIy have Iters appIed to them.
Q
!& LAkNlNG kPLlCATlON
1he practces n ths chapter congure a repIcaton envronment usng the settngs that I aIways
recommend when Iearnng repIcaton. You congure the pubIsher, subscrber, and dstrbutor
aII wthn the same nstance, whch has the effect of repIcatng between two databases on the
same nstance. 1hs s the most straghtforward way to Iearn repIcaton because t eImnates
the two most common causes of conguraton ssues n repIcaton: securty and connectvty.
524 CHAP1fR l7 ReplicaLion
I. Open SL Server ManagemenL SLudio SSMS) and connecL Lo your insLance in Lhe
ObjecL 8rowser.
2. RighL-click Lhe ReplicaLion node and choose ConIgure DisLribuLion. Click NexL.
3. SelecL Lhe IrsL opLion or your insLance Lo acL as iLs own disLribuLor and Lhen click NexL.
4. Leave Lhe snapshoL older seL Lo Lhe deaulL value, and Lhen click NexL.
5. Leave Lhe name and locaLion o Lhe disLribuLion daLabase seL Lo Lhe deaulL values and
Lhen click NexL, as shown in Figure 7-4.
llGUk l7-4 DisLribuLion daLabase seLLings
6. Lnsure LhaL your insLance is selecLed or Lhe publisher and click NexL.
7. Veriy LhaL Lhe ConIgure DisLribuLion check box is selecLed and click NexL.
8. Click Finish Lo enable publishing and Lhen click Close.
9. Veriy LhaL you now have a daLabase named DisLribuLion creaLed on your insLance.
Lesson Summary
One or more arLicles can be combined inLo a publicaLion Lo orm Lhe deIniLion o Lhe
daLa seL LhaL will be moved by Lhe replicaLion engine.
A daLabase can be in Lhe role o publisher, subscriber, or boLh.
1here are Lhree meLhods o replicaLion. snapshoL, LransacLional, and merge.
Five agenLs perorm all Lhe work o Lhe replicaLion engine. Lhe SnapshoL AgenL, Lhe Log
Reader AgenL, Lhe DisLribuLion AgenL, Lhe Merge AgenL, and Lhe ueue Reader AgenL.
ln siLuaLions in which changes can be made aL boLh Lhe publisher and Lhe subscriber,
daLa conIicLs can resulL.
534 CHAP1fR l7 ReplicaLion
3. 1racer tokens.
4. sp_publicction_vclidction and sp_crticle_vclidction.
ln Lhis pracLice, you conIgure LransacLional replicaLion using Lhe AW1rcnsccticncl daLabase.
XRCI5 I Creatng the PubIcaton
ln Lhis exercise, you creaLe a publicaLion.
I. Open SSMS and connecL Lo Lhe insLance LhaL you are using or replicaLion.
2. CreaLe a daLabase named AW1rcnSubscriber on Lhe same insLance as Lhe
AW1rcnsccticncl daLabase.
3. l necessary, expand ReplicaLion. RighL-click Local PublicaLions and choose New
PublicaLion. Click NexL.
4. SelecL Lhe AW1rcnsccticncl daLabase and click NexL.
5. SelecL 1ransacLional PublicaLion and click NexL.
6. SelecL all Lables and all user-deIned uncLions UDFs), as shown in Figure 7-8, and
click NexL.
llGUk l7-8 SelecLing arLicles
3. 1racer tokens.
4. sp_publicction_vclidction and sp_crticle_vclidction.
Lesson 2. 1ransacLional ReplicaLion CHAP1fR l7 535
!& UDlS
You ncIude the UDfs wthn the pubIcaton because there are tabIes wthn the
AdventureWorks database that have constrants dened wth a UDf. If they are not
ether created aIready on the scrber or added to the pubIcaton, a faIure occurs when
the snapshot s appIed.
7. ou do noL wanL Lo apply any IlLers, so click NexL.
8. SelecL Lhe CreaLe A SnapshoL lmmediaLely And Keep 1he SnapshoL Available 1o lniLialize
SubscripLions check box and click NexL.
9. Click SecuriLy SeLLings.
I0. SelecL Run Under 1he SL Server AgenL Service AccounL, selecL 8y lmpersonaLing
1he Process AccounL, and click OK.
'&! AGNT SCUklTY STTlNGS
It s not recommended to run the repIcaton agents under the SQL Server Agent
servce account. 1he repIcaton agent accounts shouId have mnmaI permssons
n your envronment, and the SQL Server Agent servce account eIevates those
permssons. SL Server 8ooks Online has severaI very good artcIes about settng
repIcaton securty. You are expIctIy voIatng the securty best practces n the
very specc exampIes n ths chapter, and you're dong ths for a very good reason.
1hs chapter s about Iearnng the bascs of repIcaton and how t can t nto your
envronment. 1he purpose of ths chapter s to become famIar wth the repIcaton
engne before you take the step of depIoyng t across muItpIe nstances wth varyng
securty requrements and Iockng down aII the access. If you do not understand the
basc operaton of the engne before appIyng aII the securty to the agents, you wII
have a hard tme understandng whether any errors you encounter are because of a
stuaton that you ntroduced, a msconguraton, or securty bIockng access. You
shouId not run repIcaton agents wth ths conguraton n a producton envronment.
II. Click NexL. Veriy LhaL Lhe CreaLe 1he PublicaLion check box is selecLed. Click NexL.
I2. Cive Lhe publicaLion a name and Lhen click Finish.
I3. When Lhe New PublicaLion Wizard Inishes creaLing Lhe publicaLion, click Close.
XRCI5 2 Creatng the Subscrpton
ln Lhis exercise, you creaLe a subscripLion Lo Lhe publicaLion LhaL you creaLed in Lxercise .
I. Lxpand Local PublicaLions, righL-click Lhe publicaLion you jusL creaLed, and choose New
SubscripLions. ln Lhe New SubscripLion Wizard, click NexL.
2. Veriy LhaL your publicaLion is selecLed and click NexL.
3. Veriy LhaL Run All AgenLs AL 1he DisLribuLor is selecLed and click NexL.
4. SelecL Lhe check box nexL Lo your insLance and selecL Lhe AW1rcnSubscriber daLabase
rom Lhe SubscripLion DaLabase drop-down lisL. Click NexL.
!& UDl S
You ncIude the UDfs wthn the pubIcaton because there are tabIes wthn the
AdventureWorks database that have constrants dened wth a UDf. If they are not
ether created aIready on the scrber or added to the pubIcaton, a faIure occurs when
the snapshot s appIed.
'&! AGNT SCUklTY STTlNGS
It s not recommended to run the repIcaton agents under the SQL Server Agent
servce account. 1he repIcaton agent accounts shouId have mnmaI permssons
n your envronment, and the SQL Server Agent servce account eIevates those
permssons. SL Server 8ooks Online has severaI very good artcIes about settng
repIcaton securty. You are expIctIy voIatng the securty best practces n the
very specc exampIes n ths chapter, and you're dong ths for a very good reason.
1hs chapter s about Iearnng the bascs of repIcaton and how t can t nto your
envronment. 1he purpose of ths chapter s to become famIar wth the repIcaton
engne before you take the step of depIoyng t across muItpIe nstances wth varyng
securty requrements and Iockng down aII the access. If you do not understand the
basc operaton of the engne before appIyng aII the securty to the agents, you wII
have a hard tme understandng whether any errors you encounter are because of a
stuaton that you ntroduced, a msconguraton, or securty bIockng access. You
shouId not run repIcaton agents wth ths conguraton n a producton envronment.
536 CHAP1fR l7 ReplicaLion
5. On Lhe DisLribuLion AgenL SecuriLy page, click Lhe ellipsis buLLon nexL Lo your
subscriber in Lhe SubscripLion ProperLies window.
6. SelecL Run Under 1he SL Server AgenL Service AccounL, along wiLh boLh 8y
lmpersonaLing 1he Process AccounL opLions below ConnecL 1o 1he DisLribuLor and
ConnecL 1o 1he Subscriber. Click OK and Lhen click NexL.
7. On Lhe SynchronizaLion Schedule page, make sure Lhe AgenL Schedule seLLing is Run
ConLinuously which is Lhe deaulL) and click NexL.
8. Make sure Lhe SubscripLion ProperLies seLLing is lniLialize lmmediaLely and click NexL.
9. Veriy LhaL Lhe CreaLe SubscripLions) check box is selecLed. Click NexL and Lhen click
Finish.
I0. When Lhe subscripLion is creaLed, click Close.
XRCI5 3 Usng RepIcaton Montor
ln Lhis exercise, you use ReplicaLion MoniLor Lo view inormaLion abouL your publicaLion and
subscripLion and pracLice using Lracer Lokens.
I. ln ObjecL Lxplorer, righL-click Lhe ReplicaLion node and choose Launch ReplicaLion
MoniLor.
2. ln ReplicaLion MoniLor, inspecL Lhe various selecLions and Labs Lo view Lhe inormaLion
LhaL is now available on Lhe publicaLion and subscripLion LhaL you creaLed. RighL-clicking
an enLry enables you Lo view eiLher Lhe properLies o Lhe objecL or urLher deLails.
3. PracLice posLing Lracer Lokens and observe Lhe resulLs.
Lesson Summary
1ransacLional replicaLion uses Lhe Log Reader AgenL Lo move LransacLions rom Lhe
LransacLion log on Lhe publisher Lo Lhe disLribuLion daLabase. 1he DisLribuLion AgenL
Lhen moves LransacLions rom Lhe disLribuLion daLabase Lo each subscriber.
1ransacLional replicaLion disLribuLes daLa in one direcLion-rom publisher Lo subscriber.
1wo opLions, called immediaLe updaLing subscribers and queued updaLing subscribers,
can be conIgured. 1hese opLions enable LransacLions Lo be execuLed on a subscriber
and propagaLed back Lo Lhe publisher.
1ransacLional replicaLion can be conIgured in Lhree dierenL archiLecLures. 1he deaulL
archiLecLure is Lo have a single publisher wiLh one or more subscribers. AlLernaLively,
LransacLional replicaLion can be conIgured by using eiLher a bidirecLional or peer-Lo-peer
archiLecLure.
1racer Lokens enable an adminisLraLor Lo gaLher Liming sLaLisLics wiLhin Lhe replicaLion
rom publisher Lo disLribuLor, and also rom disLribuLor Lo subscriber, Lo moniLor Lhe
poinL-Lo-poinL laLency.
Lesson 8. Merge ReplicaLion CHAP1fR l7 54l
VaIdaton
ValidaLing a merge publicaLion is very similar Lo validaLion in LransacLional replicaLion. ValidaLion
can be execuLed in Lwo dierenL modes. row counL only, and row counL plus a checksum. 1he
operaLion and overhead are Lhe same as previously described or LransacLional replicaLion.
ou can execuLe s_vcliJctemereubliccticn Lo validaLe an enLire publicaLion or
s_vcliJctemeresubscriticn Lo validaLe a single subscriber, or you can add Lhe -vcliJcte
opLion Lo Lhe merge agenL.
Quick Check
I. Whch two tabIes aIIow merge repIcaton to determne the changes that need to
be synchronzed between pubIsher and subscrber?
2. What feature makes merge repIcaton more resIent to outages?
Quick Check Answers
I. MSmerge_contents and MSmerge_genhistory.
2. 1he merge engne uses the metadata to determne the changes that need to
be appIed. ecause both pubIsher and subscrber mantan a fuII hstory of aII
changes and the metadata s stored wthn the same database partcpatng n
repIcaton, backup/restore processes keep the metadata synchronzed wth the
data beng repIcated. 1hs ensures that the merge engne can recover, even from
a restore operaton, and ncrementaIIy resynchronze tseIf.
ln Lhese pracLices, you conIgure merge replicaLion using Lhe AWMere daLabase.
PRACTIC I Creatng a Merge PubIcaton
ln Lhis pracLice, you creaLe a merge publicaLion.
I. CreaLe a daLabase named AWMereSubscriber on Lhe same insLance as Lhe AWMere
daLabase.
2. ln ObjecL Lxplorer, righL-click Lhe ReplicaLion node and choose New, PublicaLion.
Click NexL.
3. SelecL Lhe AWMere daLabase and click NexL.
4. SelecL Merge PublicaLion and click NexL.
5. Veriy LhaL Lhe SL Server 2008 check box is selecLed and click NexL.
6. SelecL all Lhe Lables and UDFs, jusL as you did when creaLing Lhe LransacLional publicaLion
in Lhe Lesson 2 exercises, and click NexL.
Quick Check
I. Whch two tabIes aIIow merge repIcaton to determne the changes that need to
be synchronzed between pubIsher and subscrber?
2. What feature makes merge repIcaton more resIent to outages?
Quick Check Answers
I. MSmerge_contents and MSmerge_genhistory.
2. 1he merge engne uses the metadata to determne the changes that need to
be appIed. ecause both pubIsher and subscrber mantan a fuII hstory of aII
changes and the metadata s stored wthn the same database partcpatng n
repIcaton, backup/restore processes keep the metadata synchronzed wth the
data beng repIcated. 1hs ensures that the merge engne can recover, even from
a restore operaton, and ncrementaIIy resynchronze tseIf.
Q
542 CHAP1fR l7 ReplicaLion
7. Click NexL again. ou will noL be IlLering any rows, so click NexL a Lhird Lime.
8. Veriy LhaL Lhe CreaLe A SnapshoL lmmediaLely check box is selecLed and clear Lhe
Schedule 1he SnapshoL AgenL 1o Run AL 1he Following 1imes check box. Click NexL.
9. Speciy securiLy seLLings as you did when creaLing a LransacLional publicaLion and
click NexL.
I0. Veriy LhaL Lhe CreaLe 1he PublicaLion check box is selecLed and click NexL.
II. Speciy a name or your publicaLion and click Finish. When Lhe publicaLion Inishes
being creaLed, click Close.
I2. lnspecL Lhe AWMere daLabase Lo view all Lhe changes LhaL have been made Lo
Lriggers, sLored procedures, Lable sLrucLures, indexes, and views Lo supporL Lhe change
Lracking in merge replicaLion.
PRACTIC 2 Creatng a Merge Subscrpton
ln Lhis pracLice, you creaLe a subscripLion Lo Lhe merge publicaLion.
I. Lxpand Local PublicaLions, righL-click Lhe publicaLion you jusL creaLed in Lhe previous
exercise, and choose New SubscripLions.
2. SelecL your merge publicaLion and click NexL.
3. Veriy LhaL Lhe opLion or Run All AgenLs AL 1he DisLribuLor is selecLed and click NexL.
4. SelecL Lhe check box nexL Lo your insLance and selecL Lhe AWMereSubscriber daLabase
rom Lhe SubscripLion DaLabase drop-down lisL. Click NexL.
5. Click Lhe ellipsis buLLon nexL Lo your subscriber in Lhe SubscripLion ProperLies window.
6. SelecL Lhe opLion or Run Under 1he SL Server AgenL Service AccounL, along wiLh
boLh opLions or 8y lmpersonaLing 1he Process AccounL. Click OK, and Lhen click NexL.
7. On Lhe SynchronizaLion Schedule page, selecL Run ConLinuously rom Lhe AgenL
Schedule drop-down lisL and click NexL.
8. Make sure LhaL Lhe SubscripLion ProperLies seLLing is aL lniLialize lmmediaLely and
click NexL.
9. Make sure LhaL Lhe SubscripLion 1ype O Server seLLing is aL a prioriLy o 75.00
Lhe deaulL). Click NexL.
I0. Veriy LhaL Lhe CreaLe SubscripLions) check box is selecLed. Click NexL, and Lhen click
Finish.
II. When Lhe subscripLion is creaLed, click Close.
I2. Use ReplicaLion MoniLor Lo inspecL Lhe agenLs, hisLory, and any error messages.
I3. lnspecL Lhe AWMereSubscriber daLabase Lo view Lhe objecLs creaLed when Lhe
snapshoL was applied.
I4. Make changes Lo boLh Lhe publisher and subscriber and observe how Lhe daLa moves
Lhrough Lhe engine.
I5. lnLroduce daLa conIicLs and observe how Lhey are deLecLed and resolved.

Вам также может понравиться