Sie sind auf Seite 1von 11

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))

GO ALTER TABLE [dbo].[OGG_EVENT] C1EC/ CON+TRAINT [C/_OGG_EVENT_EVENT_I"&] GO ALTER TABLE [dbo].[OGG_EVENT] ADD DE3A LT (N4N4) 3OR [EVENT_I"&] GO

3ach ro# must ha$e a unique item number (343.T2"T%) and e$ent id (343.T2"D). 343.T2"%5 and 343.T2"%52D,T3 are used as an 9audit trail9. These columns are updated by the stored procedure upon successful e ecution of the DDL statement in 343.T2T:T. The 343.T2T:T column #ill contain the D%L statement to be e ecuted by the stored procedure. DDL statements that #ould e ceed ;))) bytes must be broken up into multiple statements.

The execOGGDDL Stored Procedure


The e ecOGGDDL 5rocedure is the heart of this process.
CREATE &ROCED RE dbo.'5'cOGGDDL 6'v%Id nvarchar(10) A+ BEGIN BEGIN TR. +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 ,roc'88 I3 (+ELECT CO NT (;) 3RO" dbo.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.4 77 +%ar% =oo,#n$ %hro>$h %h' r'cord8 01ILE (+ELECT CO NT (;) 3RO" 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.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.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 ,da%' %h' r'cord %o 8'% %h' EVENT_I"& %o 4.4 &DATE dbo.OGG_EVENT +ET EVENT_I"& 2 N4.4! EVENT_I"&_DATE 2 GETDATE() 01ERE EVENT_ID 2 6'v%Id and EVENT_IT" 2 6'v%I%( END END TR. BEGIN CATC1 +ELECT ERROR_N "BER() A+ ErrorN>(b'r !ERROR_"E++AGE() A+ Error"'88a$'A END CATC1

END

GO

8hen the OGG 3 tract or 6eplicat processes the e$ent tri!!er record, this 5rocedure is called and supplied the 343.T2"D column data from the tri!!er record. The 5rocedure queries the 343.T2T:T records from the OGG2343.T table that match the supplied 343.T2"D. 3ach ro# is then read, e ecuted, and updated #ith an 343.T2"%5 code of <=> and current e ecution time for the 343.T2"%52D,T3 in order. Because of the o$erhead associated #ith ha$in! the OGG 3 tract and 6eplicat e ecute the 5rocedure, they instead e ecute a 8indo#s Batch file that calls the 5rocedure $ia the 8indo#s &'L+%D utility.

The ddlevt.bat Scri t


The 8indo#s Batch script, ddle$t.bat, is e ecuted $ia an 343.T,+T"O. defined in the OGG 3 tract and 6eplicat parameter files.
6'cho o99 8'%=oca= 'nab='d'=a:'d'5,an8#on RE" G'% %h' 'v'n% #d 9or %h#8 r>n 8'% EVTID2B1 RE" +'% an o>%,>% =oca%#on 8'% O TLOC2BCd,0 RE" +%r#, 8,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 BEVTIDB.o>% 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.'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. The stored procedure is e ecuted $ia the 8indo#s &'L+%D utility, and pro$ided the unique 343.T2"D from the captured tri!!er record. The 0&, 0-, 05, and 0d options must be set correctly to pro$ide the database ser$er for the connection (0 &), the database userid (0-) and pass#ord (05) for a user #ith create and alter table authority, and the database #here the DDL statements #ill be e ecuted (0d).

Setu
To setup the database and 8indo#s components/ 1. +reate the dbo.OGG2343.T table in the source and tar!et database. (. ,DD T6,.D,T, to the dbo.OGG2343.T table on the source database. 7. +reate the dbo.e ecOGGDDL 5rocedure in the source and tar!et database. ;. +reate the ddle$t.bat script in the OGG 9dirsql9 directory on the source and tar!et ser$er. (a) Be sure to set the correct options for &'L+%D to access each database.

OGG Extract !han"e#


, sample +han!e Data +apture 3 tract parameter file is sho#n belo#.
'5%rac% '%'8% '5%%ra#= .Dd#rda%D'% 8o>rc'db (88_'a8%! >8'r#d $$>8'r! ,a88Lord Orac='1 %ran=o$o,%#on8 (ana$'8'condar:%r>nca%#on,o#n% r',or%co>n% 'v'r: M0 8'cond8! ra%' nod:na(#cr'8o=>%#on #$nor'>,da%'8 #$nor'd'='%'8 %ab=' dbo.OGG_EVENT! 9#=%'r (68%rc(,(EVENT_T)T! EEnd Ev'n%E) N? 0) A %ab=' dbo.OGG_EVENT! 9#=%'r (68%rc(,(EVENT_T)T! EEnd Ev'n%E) 2 0)! 'v'n%ac%#on8(+1ELL (EcGO$o=d'n$a%'Od#r8H=Odd=Ca,%>r'A,,=:Odd='v%.ba% dd=PobE! VAR dd=Pob 2 EVENT_ID)! +TO&) A d:na(#cr'8o=>%#on $'%>,da%'8 $'%d'='%'8 %ab=''5c=>d' dbo.OGG_EVENT %ab=' dbo.;A

?ey parameters that must be set/ 1. "f usin! #ildcards, you must set .OD=.,%"+63&OL-T"O. before the first OGG2343.T table statement. (a) This #ill force 3 tract to resol$e the ob@ect record for the OGG2343.T table at startup. (. &et "G.O63-5D,T3& and "G.O63D3L3T3& before the first OGG2343.T table statement. (a) 8e only #ant to process inserts for this table. 7. ,dd t#o table statements for the OGG2343.T table.

(a) The first #ill capture all records #here the 343.T2T:T is not 93nd 3$ent9. (b) The second #ill only capture the record #here the 343.T2T:T is 93nd 3$ent9. i. This is the tri!!er e$ent record. ii. 8hen this record is processed, the 8indo#s Batch script ddle$t.bat is e ecuted and supplied the 343.T2"D of the tri!!er record. ,. This in turn e ecutes the e ecOGGDDL 5rocedure #hich e ecutes the DDL chan!es. (c) ,s part of the 343.T,+T"O.& option, the 3 tract #ill be !racefully stopped. ;. ,fter the second OGG2343.T table statement/ (a) &et D=.,%"+63&OL-T"O. to reacti$ate default table resolution for #ildcards. (b) &et G3T-5D,T3& and G3TD3L3T3& to reacti$ate default capture of update and delete operations. (c) &et T,BL33:+L-D3 dbo.OGG2343.T to pre$ent the OGG2343.T records from bein! captured as part of the #ildcard table statement.

OGG Extract Data Pu$ !han"e#


"f the 3 tract Data 5ump is confi!ured #ith 5,&&TA6- and #ild card T,BL3 statements, no chan!es are required. "f not, the ne# tables must be added.

OGG %e licat !han"e#


, sample 6eplicat parameter file is presented belo#.
r',=#ca% r%'8% 8o>rc'db "++_0'8%! >8'r#d $$>8'r! ,a88Lord Orac='1 a88>('%ar$'%d'98 r',or%co>n% 'v'r: M0 8'cond8! ra%' d#8card9#=' .Dd#rr,%Dr%'8%.d8c! ,>r$' ba%ch8H= a==oLd>,%ar$'%(a, nod:na(#cr'8o=>%#on (a, dbo.OGG_EVENT! %ar$'% dbo.OGG_EVENT! 9#=%'r (68%rc(,(EVENT_T)T! EEnd Ev'n%E) N? 0) A (a, dbo.OGG_EVENT! %ar$'% dbo.OGG_EVENT! 9#=%'r (68%rc(,(EVENT_T)T! EEnd Ev'n%E) 2 0)! 'v'n%ac%#on8(+1ELL (EcGO$o=d'n$a%'Od#r8H=Odd=Ca,%>r'A,,=:OTar$'%Odd='v%.ba% dd=PobE! VAR dd=Pob 2 EVENT_ID)! ch'c-,o#n% b'9or'! #$nor'! 8%o,) A d:na(#cr'8o=>%#on (a,'5c=>d' dbo.OGG_EVENT (a, dbo.;! %ar$'% dbo.;A

These chan!es must be made to one 6eplicat only. ?ey parameters to set are/ 1. ,LLO8D-5T,6G3T%,5 to enable multiple map statements for the OGG2343.T table. (. "f usin! #ildcards in the 6eplicat, set .OD=.,%"+63&OL-T"O. to ha$e 6eplicat resol$e the ob@ect record for the OGG2343.T table at startup. 7. T#o map statements for the OGG2343.T table. (a) The first #ill apply all records #here the 343.T2T:T column does not contain 93nd 3$ent9. (b) The second #ill only apply the 93nd 3$ent9 record. i. Like in 3 tract, this is the tri!!er record for 6eplicat. ii. 8hen this record is read from the trail, 6eplicat does the follo#in!/ ,. The ddle$t.bat script is e ecuted and pro$ided the 343.T2"D data of the tri!!er record. This in turn e ecutes the e ecOGGDDL 5rocedure #hich e ecutes the DDL chan!es.

B. The 6eplicat #ill checkpoint. +. The tri!!er record #ill be i!noredB meanin! it #ill not be applied to the tar!et table. D. The 6eplicat #ill perform a !raceful stop. ,ll other 6eplicats applyin! data to the same database must be modified as sho#n in the follo#in! e ample.
r',=#ca% r%'8%a 8o>rc'db "++_0'8%! >8'r#d $$>8'r! ,a88Lord Orac='1 a88>('%ar$'%d'98 r',or%co>n% 'v'r: M0 8'cond8! ra%' d#8card9#=' .Dd#rr,%Dr%'8%a.d8c! ,>r$' ba%ch8H= nod:na(#cr'8o=>%#on (a, dbo.OGG_EVENT! %ar$'% dbo.OGG_EVENT! 9#=%'r (68%rc(,(EVENT_T)T! EEnd Ev'n%E) 2 0)! 'v'n%ac%#on8(ch'c-,o#n% b'9or'! #$nor'! 8%o,) A d:na(#cr'8o=>%#on (a,'5c=>d' dbo.OGG_EVENT (a, dbo.;! %ar$'% dbo.;A

"n these 6eplicats, #e only check for the tri!!er record. 8hen the tri!!er record is read each 6eplicat #ill checkpoint and !racefully stop. "t should be noted that in the 6eplicats #e are bein! some#hat conser$ati$e. "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. This is not true if e plicit mappin! is usedB in that case each 6eplicat must be stopped, ne# map statements added, and the 6eplicat restarted before data #ill be applied to the ne# tables.

Exa$ le Databa#e Maintenance %un


To test this procedure, #e #ill simulate a production database maintenance #indo#. To prepare for the maintenance #indo#, assi!ned maintenance e$ent D%)))1, " create three sta!in! files/ 1. dm))12ddl.in (a)This file contains the ddl statements that #ill be loaded into the OGG2343.T table. These statements are/
#n8'r% #n%o dbo.OGG_EVENT (EVENT_ID! EVENT_IT"! EVENT_T)T) va=>'8 (N4D"00014!1! N4cr'a%' %ab=' dbo.dd=%'8% (co=1 b#$#n%! co=J varchar(100)! co=Q da%'%#('J! CON+TRAINT ,-_%8% &RI"AR. /E. (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.dd=%'8%J (co=1 b#$#n%! co=J varchar(100)! co=Q da%'%#('J! CON+TRAINT ,-_%8%1 &RI"AR. /E. (co=1))4) #n8'r% #n%o dbo.OGG_EVENT (EVENT_ID! EVENT_IT"! EVENT_T)T) va=>'8 (N4D"00014!Q! N4a=%'r %ab=' dbo.dd=%'8% add co=* char(M)4) #n8'r% #n%o dbo.OGG_EVENT (EVENT_ID! EVENT_IT"! EVENT_T)T) va=>'8 (N4D"00014!*! N4cr'a%' %ab=' dbo.dd=%'8%Q (co=1 b#$#n%! co=J varchar(100)! co=Q da%'%#('J! CON+TRAINT ,-_%8%Q &RI"AR. /E. (co=1))4) #n8'r% #n%o dbo.OGG_EVENT (EVENT_ID! EVENT_IT"! EVENT_T)T) va=>'8 (N4D"00014!R! N4cr'a%' %ab=' dbo.dd=%'8%* (co=1 b#$#n%! co=J varchar(100)! co=Q da%'%#('J! CON+TRAINT ,-_%8%* &RI"AR. /E. (co=1))4) $o #n8'r% #n%o dbo.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. (. dbm))12trandata.in (a)This file contains all of the GG&+" ,DD T6,.D,T, commands required to ensure the OGG 3 tract captures all database operations for the ne# files.
add add add add %randa%a %randa%a %randa%a %randa%a dbo.dd=%'8% dbo.dd=%'8%J dbo.dd=%'8%Q dbo.dd=%'8%*

7. dbm))12dml.in (a)This file contains all of the D%L statements required to load data into the ne# tables. D%L statements cannot be e ecuted until after the GG&+" ,DD T6,.D,T, commands are e ecuted. Data inconsistencies may occur if data is loaded into the ne# tables before Trandata is enabled.
>8' 'a8% $o #n8'r% #n%o dbo.dd=%'8% va=>'8 (1! 4Th#8 #8 roL 14! C RRENT_TI"E+TA"&! 4LS&4) $o #n8'r% #n%o dbo.dd=%'8% va=>'8 (J! 4Th#8 #8 roL J4! C RRENT_TI"E+TA"&!

4LS&4) $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%J va=>'8 (1! 4Th#8 #8 roL 14! C RRENT_TI"E+TA"&) $o #n8'r% #n%o 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 (Q! 4Th#8 #8 roL Q4! C RRENT_TI"E+TA"&) $o >,da%' 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. %ake sure all OGG 3 tract and 6eplicat Groups report 9,t 3OC9.

&'L &er$er %ana!ement &tudio sho#s the current source and tar!et tables.

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

V d#8card8G 3ro( Tab=' dbo.OGG_EVENTG V #n8'r%8G V >,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.

3 ecute the GG&+" ,DD T6,.D,T, commands and restart the 3 tract. =ou may no# load the ne# tables and be!in application D%L a!ainst the source database.

On the tar!et, the tri!!er record #ill cause the 343.T,+T"O. to e ecute in each 6eplicat. The DDL statements #ill be retrie$ed and e ecuted by the stored procedure, and the ne# tables #ill be $isible from #ithin %icrosoft &'L &er$er %ana!ement &tudio.

,dd the necessary %,5 statements to each 6eplicat and restart them. Data captured on the source is bein! queued in the OGG Trails. Once the 6eplicats are runnin!, all captured data #ill be applied to the tar!et tables.

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. This article presented one e ample of this functionality for %icrosoft &'L &er$er ())*.

Das könnte Ihnen auch gefallen