Introduction

Oracle GoldenGate (OGG) supports DDL capture and apply for the Oracle and Teradata databases only. Because of this, maintenance tasks for other databases require a lot of coordination and typically an e tended OGG outa!e. "n this article #e shall discuss one option for automatin! the capture, deli$ery, and e ecution of DDL operations usin! OGG for %icrosoft &'L &er$er ())*. The techniques discussed may also be used for other databases supported by OGG. +,-T"O./ The scripts and information pro$ided in this article are for educational purposes only. They are not supported by Oracle De$elopment or &upport, and come #ith no !uarantee or #arrant for functionality in any en$ironment other than the test system used to prepare this article.

Main Article
Oracle GoldenGate (OGG) pro$ides data capture from transaction lo!s and deli$ery for homo!eneous and hetero!eneous databases and messa!in! systems. Built0in functionality allo#s OGG capture and apply processes to perform non0database actions based upon database transactional data. -sin! this kno#led!e, #e can use OGG as the intermediary mechanism to e ecute DDL statements on the source and tar!et databases. The hi!h le$el o$er$ie# for accomplishin! this is/ 1. +reate an OGG2343.T table on the source and tar!et to hold DDL statements. (. +reate a &tored 5rocedure on the source and tar!et that reads the OGG2343.T table and e ecutes the DDL statements #hen an e$ent is processed by the OGG 3 tract and 6eplicat. 7. &et the OGG 3 tract and 6eplicat to e ecute a 8indo#s Batch script #hen the e$ent tri!!er is processed.

The OGG_EVENT Table
The OGG2343.T table is defined as/
CREATE TABLE [dbo].[OGG_EVENT]( [EVENT_ID] [nvarchar](10) NOT N LL! [EVENT_IT"] [b#$#n%] NOT N LL! [EVENT_I"&] [nchar](1) NOT N LL! [EVENT_I"&_DATE] [da%'%#('] N LL! [EVENT_T)T] [nvarchar](*000) NOT N LL! CON+TRAINT [,-_O$$Ev'n%] &RI"AR. /E. CL +TERED ( [EVENT_IT"] A+C! [EVENT_ID] A+C ) 0IT1 (&AD_INDE) 2 O33! +TATI+TIC+_NORECO"& TE 2 O33! IGNORE_D &_/E. 2 O33! ALLO0_RO0_LOC/+ 2 ON! ALLO0_&AGE_LOC/+ 2 ON) ON [&RI"AR.] ) ON [&RI"AR.] GO ALTER TABLE [dbo].[OGG_EVENT] 0IT1 C1EC/ ADD CON+TRAINT [C/_OGG_EVENT_EVENT_I"&] C1EC/ (([EVENT_I"&]2N4.4 OR [EVENT_I"&]2N4N4))

[OGG_EVENT] C1EC/ CON+TRAINT [C/_OGG_EVENT_EVENT_I"&] GO ALTER TABLE [dbo].T2T:T column #ill contain the D%L statement to be e ecuted by the stored procedure.T2"D).T2"%5 and 343. BEGIN CATC1 +ELECT ERROR_N "BER() A+ ErrorN>(b'r !ERROR_"E++AGE() A+ Error"'88a$'A END CATC1 END .4 77 +%ar% =oo.OGG_EVENT +ET EVENT_I"& 2 N4.T3 are used as an 9audit trail9. 343.T2"%52D.4! EVENT_I"&_DATE 2 GETDATE() 01ERE EVENT_ID 2 6'v%Id and EVENT_IT" 2 6'v%I%( END END TR.4 &DATE dbo.da%' %h' r'cord %o 8'% %h' EVENT_I"& %o 4.T2"T%) and e$ent id (343.) 3RO" dbo.GO ALTER TABLE [dbo].OGG_EVENT 01ERE EVENT_ID 2 6'v%Id AND &&ER(EVENT_I"&) 2 N4N4) ? 0 BEGIN 77 Grab %h' 9#r8% r'cord o>% +ET 6'v%I%( 2 (+ELECT "IN(EVENT_IT") 3RO" dbo.roc'88 I3 (+ELECT CO NT (. The 343.[OGG_EVENT] ADD DE3A LT (N4N4) 3OR [EVENT_I"&] GO 3ach ro# must ha$e a unique item number (343. The execOGGDDL Stored Procedure The e ecOGGDDL 5rocedure is the heart of this process.))) bytes must be broken up into multiple statements. These columns are updated by the stored procedure upon successful e ecution of the DDL statement in 343. CREATE &ROCED RE dbo. +ET NOCO NT ON DECLARE 6'v%I%( b#$#n% DECLARE 6'v%T5% nvarchar(*000) 77 T'8% 9or an: Ev'n%8 %o .OGG_EVENT 01ERE EVENT_ID 2 6'v%Id AND &&ER(EVENT_I"&) 2 N4N4) +ELECT 6'v%T5% 2 EVENT_T)T 3RO" dbo. DDL statements that #ould e ceed .OGG_EVENT 01ERE EVENT_ID 2 6'v%Id AND EVENT_IT" 2 6'v%I%( AND &&ER(EVENT_I"&) 2 N4N4 77 '5'c>%' %h' 8%a%'('n%8 I3 6'v%T5% @2 N4End Ev'n%4 '5'c(6'v%T5%) 77 .'5'cOGGDDL 6'v%Id nvarchar(10) A+ BEGIN BEGIN TR.T2T:T.OGG_EVENT 01ERE EVENT_ID 2 6'v%Id AND &&ER(EVENT_I"&) 2 N4N4) 2 0 &RINT N4Th'r' ar' no Ev'n%8 %o .roc'88 9or Ev'n%_I%( 4 <6'v%Id <N4.) 3RO" dbo.#n$ %hro>$h %h' r'cord8 01ILE (+ELECT CO NT (.

The 0&. The 5rocedure queries the 343. ddle$t. 6'cho o99 8'%=oca= 'nab='d'=a:'d'5.0 RE" +%r#. 8. . and pro$ided the unique 343. The stored procedure is e ecuted $ia the 8indo#s &'L+%D utility. 05. they instead e ecute a 8indo#s Batch file that calls the 5rocedure $ia the 8indo#s &'L+%D utility.o>% 9or D9 E%o-'n82.T2"D.+T"O.ac'8 9ro( %h' d#r'c%or: na(' 9or D9 E%o-'n82. d'=#(82 E BBa #n (4'cho BO TLOCB4) do (8'% +2BBa F 8'% +2@+G 2@ F 'cho @+@) 8'% O TLOC2B+B RE" E5'c>%' %h' +%or'd &roc'd>r' 8H=c(d 7I E'5'c dbo.T2"%5 code of <=> and current e ecution time for the 343. 0-.an8#on RE" G'% %h' 'v'n% #d 9or %h#8 r>n 8'% EVTID2B1 RE" +'% an o>%. The ddlevt. is e ecuted $ia an 343.>% =oca%#on 8'% O TLOC2BCd. Because of the o$erhead associated #ith ha$in! the OGG 3 tract and 6eplicat e ecute the 5rocedure.GO 8hen the OGG 3 tract or 6eplicat processes the e$ent tri!!er record. this 5rocedure is called and supplied the 343.'5'cOGGDDL 6'v%Id24BEVTIDB4E 7+ V""++J00K 7 7d 'a8% 7o BO TLOCB $$>8'r 7& Orac='1 This script creates an output file that #ill contain error information should the stored procedure fail. and the database #here the DDL statements #ill be e ecuted (0d). 3ach ro# is then read.bat Scri t The 8indo#s Batch script.T2"D from the captured tri!!er record. and updated #ith an 343.T2"%52D.T3 in order.T2T:T records from the OGG2343.T. e ecuted.T table that match the supplied 343. defined in the OGG 3 tract and 6eplicat parameter files. the database userid (0-) and pass#ord (05) for a user #ith create and alter table authority. d'=#(82 E BBa #n (4'cho BO TLOCB4) do (8'% +2BBa F 8'% +2@+G 2@ F 'cho @+@) 8'% O TLOC2B+B BEVTIDB. and 0d options must be set correctly to pro$ide the database ser$er for the connection (0 &).bat.T2"D column data from the tri!!er record.

(.T table at startup..OGG_EVENT! 9#=%'r (68%rc(. (a) 8e only #ant to process inserts for this table. +reate the dbo. &et "G.OGG2343.or%co>n% 'v'r: M0 8'cond8! ra%' nod:na(#cr'8o=>%#on #$nor'>. 7.T3& and "G.da%'8 $'%d'='%'8 %ab=''5c=>d' dbo. (.T table in the source and tar!et database.T table on the source database. OGG Extract !han"e# .T table statement.T table. (a) Be sure to set the correct options for &'L+%D to access each database.e ecOGGDDL 5rocedure in the source and tar!et database.dd t#o table statements for the OGG2343.ba% dd=PobE! VAR dd=Pob 2 EVENT_ID)! +TO&) A d:na(#cr'8o=>%#on $'%>. sample +han!e Data +apture 3 tract parameter file is sho#n belo#.. +reate the ddle$t. 7. +reate the dbo. .OGG_EVENT %ab=' dbo.(EVENT_T)T! EEnd Ev'n%E) 2 0)! 'v'n%ac%#on8(+1ELL (EcGO$o=d'n$a%'Od#r8H=Odd=Ca. ..%"+63&OL-T"O.DD T6.Setu To setup the database and 8indo#s components/ 1.OGG2343.T table statement. before the first OGG2343. (a) This #ill force 3 tract to resol$e the ob@ect record for the OGG2343.T.O63D3L3T3& before the first OGG2343.a88Lord Orac='1 %ran=o$o.o#n% r'.(EVENT_T)T! EEnd Ev'n%E) N? 0) A %ab=' dbo. '5%rac% '%'8% '5%%ra#= . you must set .A ?ey parameters that must be set/ 1.Dd#rda%D'% 8o>rc'db (88_'a8%! >8'r#d $$>8'r! . to the dbo.bat script in the OGG 9dirsql9 directory on the source and tar!et ser$er.%#on8 (ana$'8'condar:%r>nca%#on.OGG_EVENT! 9#=%'r (68%rc(.D.OD=. . "f usin! #ildcards.%>r'A. .=:Odd='v%...da%'8 #$nor'd'='%'8 %ab=' dbo.O63-5D.

T to pre$ent the OGG2343.T.%ar$'%(a..&&TA6. . to reacti$ate default table resolution for #ildcards. 8hen this record is processed.OGG_EVENT (a. (c) .s part of the 343. This is the tri!!er e$ent record.'5c=>d' dbo. the 3 tract #ill be !racefully stopped.ba% dd=PobE! VAR dd=Pob 2 EVENT_ID)! ch'c-.T2"D of the tri!!er record.. dbo.A .! %ar$'% dbo. i.BL33:+L-D3 dbo. ii.OGG2343.T3& and G3TD3L3T3& to reacti$ate default capture of update and delete operations. the ne# tables must be added. .%Dr%'8%.=#ca% r%'8% 8o>rc'db "++_0'8%! >8'r#d $$>8'r! . This in turn e ecutes the e ecOGGDDL 5rocedure #hich e ecutes the DDL chan!es.& option.. no chan!es are required.BL3 statements.bat is e ecuted and supplied the 343. (b) &et G3T-5D.OGG_EVENT! 9#=%'r (68%rc(.and #ild card T.d8c! .T2T:T is not 93nd 3$ent9.OGG_EVENT! %ar$'% dbo. (c) &et T. "f not. OGG Extract Data Pu$ !han"e# "f the 3 tract Data 5ump is confi!ured #ith 5. nod:na(#cr'8o=>%#on (a. r'.(EVENT_T)T! EEnd Ev'n%E) 2 0)! 'v'n%ac%#on8(+1ELL (EcGO$o=d'n$a%'Od#r8H=Odd=Ca.OGG_EVENT! %ar$'% dbo.T table statement/ (a) &et D=.+T"O.%"+63&OL-T"O.OGG_EVENT! 9#=%'r (68%rc(.) A d:na(#cr'8o=>%#on (a.o#n% b'9or'! #$nor'! 8%o.Dd#rr.a88Lord Orac='1 a88>('%ar$'%d'98 r'.. .=:OTar$'%Odd='v%. OGG %e licat !han"e# . (b) The second #ill only capture the record #here the 343.(EVENT_T)T! EEnd Ev'n%E) N? 0) A (a.T2T:T is 93nd 3$ent9.fter the second OGG2343.or%co>n% 'v'r: M0 8'cond8! ra%' d#8card9#=' .(a) The first #ill capture all records #here the 343. dbo. the 8indo#s Batch script ddle$t..%>r'A. sample 6eplicat parameter file is presented belo#..>r$' ba%ch8H= a==oLd>. dbo.T records from bein! captured as part of the #ildcard table statement.

(b) The second #ill only apply the 93nd 3$ent9 record. The tri!!er record #ill be i!noredB meanin! it #ill not be applied to the tar!et table. 8hen the tri!!er record is read each 6eplicat #ill checkpoint and !racefully stop.T table. ne# map statements added. This is not true if e plicit mappin! is usedB in that case each 6eplicat must be stopped.. to ha$e 6eplicat resol$e the ob@ect record for the OGG2343.) A d:na(#cr'8o=>%#on (a..>r$' ba%ch8H= nod:na(#cr'8o=>%#on (a.(EVENT_T)T! EEnd Ev'n%E) 2 0)! 'v'n%ac%#on8(ch'c-. The 6eplicat #ill checkpoint.OD=.T2"D data of the tri!!er record. ii.. . D. ?ey parameters to set are/ 1.%Dr%'8%a. and the 6eplicat restarted before data #ill be applied to the ne# tables. "t should be noted that in the 6eplicats #e are bein! some#hat conser$ati$e.bat script is e ecuted and pro$ided the 343. . r'. Like in 3 tract.T table.d8c! . The 6eplicat #ill perform a !raceful stop.OGG_EVENT! 9#=%'r (68%rc(. T#o map statements for the OGG2343. set .%"+63&OL-T"O. "f #ildcards are used there is no need to stop the 6eplicats because the ne# table ob@ects #ill be resol$ed #hen the first record for the each ne# table is encountered by 6eplicat. The ddle$t.5 to enable multiple map statements for the OGG2343. (a) The first #ill apply all records #here the 343.'5c=>d' dbo.T table at startup. dbo.ll other 6eplicats applyin! data to the same database must be modified as sho#n in the follo#in! e ample. • This in turn e ecutes the e ecOGGDDL 5rocedure #hich e ecutes the DDL chan!es.These chan!es must be made to one 6eplicat only.o#n% b'9or'! #$nor'! 8%o.LLO8D-5T.Dd#rr.or%co>n% 'v'r: M0 8'cond8! ra%' d#8card9#=' .A "n these 6eplicats.a88Lord Orac='1 a88>('%ar$'%d'98 r'.=#ca% r%'8%a 8o>rc'db "++_0'8%! >8'r#d $$>8'r! .OGG_EVENT! %ar$'% dbo. i. this is the tri!!er record for 6eplicat. dbo. #e only check for the tri!!er record. "f usin! #ildcards in the 6eplicat.! %ar$'% dbo. B.T2T:T column does not contain 93nd 3$ent9. . 7. 8hen this record is read from the trail.OGG_EVENT (a. +. (..6G3T%. 6eplicat does the follo#in!/ .

>8' 'a8% $o #n8'r% #n%o dbo. /E. /E.D.dd=%'8% add co=* char(M)4) #n8'r% #n%o dbo.-_%8% &RI"AR.dd=%'8%J (co=1 b#$#n%! co=J varchar(100)! co=Q da%'%#('J! CON+TRAINT .D.dd=%'8% (co=1 b#$#n%! co=J varchar(100)! co=Q da%'%#('J! CON+TRAINT . " create three sta!in! files/ 1. dbm))12dml.in (a)This file contains all of the GG&+" . commands are e ecuted. Data inconsistencies may occur if data is loaded into the ne# tables before Trandata is enabled.in (a)This file contains the ddl statements that #ill be loaded into the OGG2343.dd=%'8% va=>'8 (J! 4Th#8 #8 roL J4! C RRENT_TI"E+TA"&! . These statements are/ #n8'r% #n%o dbo. /E.dd=%'8%Q dbo.in (a)This file contains all of the D%L statements required to load data into the ne# tables.Exa$ le Databa#e Maintenance %un To test this procedure.-_%8%1 &RI"AR.dd=%'8%* 7.-_%8%* &RI"AR. (co=1))4) $o #n8'r% #n%o dbo. assi!ned maintenance e$ent D%)))1. (.dd=%'8% va=>'8 (1! 4Th#8 #8 roL 14! C RRENT_TI"E+TA"&! 4LS&4) $o #n8'r% #n%o dbo. dbm))12trandata.dd=%'8%J dbo.dd=%'8%* (co=1 b#$#n%! co=J varchar(100)! co=Q da%'%#('J! CON+TRAINT . #e #ill simulate a production database maintenance #indo#.T.dd=%'8% dbo.DD T6..T. (co=1))4) #n8'r% #n%o dbo. dm))12ddl. add add add add %randa%a %randa%a %randa%a %randa%a dbo.-_%8%Q &RI"AR.OGG_EVENT (EVENT_ID! EVENT_IT"! EVENT_T)T) va=>'8 (N4D"00014! M! N4End Ev'n%4) $o (b)The last record in the file must be the tri!!er record.OGG_EVENT (EVENT_ID! EVENT_IT"! EVENT_T)T) va=>'8 (N4D"00014!Q! N4a=%'r %ab=' dbo. (co=1))4) #n8'r% #n%o dbo.OGG_EVENT (EVENT_ID! EVENT_IT"! EVENT_T)T) va=>'8 (N4D"00014!1! N4cr'a%' %ab=' dbo..T table. To prepare for the maintenance #indo#.OGG_EVENT (EVENT_ID! EVENT_IT"! EVENT_T)T) va=>'8 (N4D"00014!*! N4cr'a%' %ab=' dbo. D%L statements cannot be e ecuted until after the GG&+" . (co=1))4) #n8'r% #n%o dbo.OGG_EVENT (EVENT_ID! EVENT_IT"! EVENT_T)T) va=>'8 (N4D"00014!J! N4cr'a%' %ab=' dbo. /E.dd=%'8%Q (co=1 b#$#n%! co=J varchar(100)! co=Q da%'%#('J! CON+TRAINT . commands required to ensure the OGG 3 tract captures all database operations for the ne# files.DD T6.OGG_EVENT (EVENT_ID! EVENT_IT"! EVENT_T)T) va=>'8 (N4D"00014!R! N4cr'a%' %ab=' dbo.

t 3OC9.dd=%'8%J va=>'8 (Q! 4Th#8 #8 roL Q4! C RRENT_TI"E+TA"&) $o >. %ake sure all OGG 3 tract and 6eplicat Groups report 9.da%' dbo. .dd=%'8%J va=>'8 (J! 4Th#8 #8 roL J4! C RRENT_TI"E+TA"&) $o #n8'r% #n%o dbo.dd=%'8%J va=>'8 (1! 4Th#8 #8 roL 14! C RRENT_TI"E+TA"&) $o #n8'r% #n%o dbo.dd=%'8% va=>'8 (Q! 4Th#8 #8 roL Q4! C RRENT_TI"E+TA"&! 4LS&4) $o #n8'r% #n%o dbo.dd=%'8% 8'% co=*24SL&4 Lh'r' co=12J $o 8hen the database maintenance #indo# be!ins. application processin! is suspended and allo# all outstandin! database operations to be captured and applied to the tar!et.4LS&4) $o #n8'r% #n%o dbo.

o>%4..T...... ....or% a% J01Q70T7JR 1*GRUG11 (ac%#v#%: 8#nc' J01Q70T7JR 1*GJMGQK) O>%. e ecute the dm)))12ddl.................ba% D"00014 d>' %o +1ELL 'v'n% 9or 8o>rc' %ab=' dbo.. and its report file #ill contain/ 01Q70T7JR 1*GRUG10 IN3O OGG701JKM E5'c>%#n$ 8h'== co((and 4cGO$o=d'n$a%'Od#r8H=Odd=Ca.bat scriptB #hich in turn e ecutes the stored procedure... .. R'...+T"O......in commands........OGG_EVENT #n L+NG 050000009JG00000cT'G000Q! TranG 0000G000J0aQM....... J01Q70T7JR 1*GRUG10 IN3O OGG70RQ01 +h'== co((and o>%............ The 3 tract #ill !racefully stop. J01Q70T7JR 1*GRUG10 IN3O OGG70RQ01 +h'== co((and o>%... 8hen the tri!!er record #ith 343.............%>r'A.......%>r'A.....=:OD"0001... ...roc'88 d>' %o +TO& 'v'n% 9or 8o>rc' %ab=' dbo...#n$ ....=:Odd='v%....>% %o ..%>r'A.OGG_EVENT #n L+NG 050000009JG00000cT'G000Q! TranG 0000G000J0aQM.&'L &er$er %ana!ement &tudio sho#s the current source and tar!et tables.da%'8G d'='%'8G R 0 0 .... J01Q70T7JR 1*GRUG11 IN3O OGG701JKU +>cc'889>==: '5'c>%'d 8h'== co((and 4cGO$o=d'n$a%'Od#r8H=Odd=Ca.......%>r'A...Dd#rda%D'%G 3ro( Tab=' dbo.OGG_EVENTG V V V #n8'r%8G >.. #ill e ecute the ddle$t.....ba% D"00014.... "n &'L &er$er %ana!ement &tudio.=:Odd='v%... J01Q70T7JR 1*GRUG11 0ARNING OGG701JKQ +%o...>%G 4cGOGo=d'nGa%'Od#r8H=Odd=Ca. .T2T:T of 93nd 3$ent9 is captured the 3 tract 343.............>%G 4cGOGo=d'nGa%'Od#r8H=Odd=Ca...... R>n T#(' +%a%#8%#c8 ........=:O4.... .

D. =ou may no# load the ne# tables and be!in application D%L a!ainst the source database.da%'8G V d'='%'8G V d#8card8G 0 1 0 0 0 %icrosoft &'L &er$er %ana!ement &tudio no# sho#s ne# tables in the source database.OGG_EVENTG V #n8'r%8G V >.T. 3 ecute the GG&+" . commands and restart the 3 tract.V d#8card8G 3ro( Tab=' dbo..DD T6. .

The DDL statements #ill be retrie$ed and e ecuted by the stored procedure.+T"O. to e ecute in each 6eplicat. Data captured on the source is bein! queued in the OGG Trails. the tri!!er record #ill cause the 343. Once the 6eplicats are runnin!. . Su$$ar& Oracle GoldenGate ad$anced functionality alon! #ith operatin! system scripts and a database stored procedure may be used to minimiDe the impact of database maintenance tasks. and the ne# tables #ill be $isible from #ithin %icrosoft &'L &er$er %ana!ement &tudio.5 statements to each 6eplicat and restart them.T. This article presented one e ample of this functionality for %icrosoft &'L &er$er ())*. all captured data #ill be applied to the tar!et tables.On the tar!et.dd the necessary %. .

Sign up to vote on this title
UsefulNot useful