Beruflich Dokumente
Kultur Dokumente
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.
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.
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.
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.
?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.
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.
(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
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 ())*.