ORACLE GOLDENGATE



1)  GoldenGate Setup & Configuration


On Source & Target Hosts Perform the Following
On Source: Unzip the GG Software and Perform the installation & Configuration

[oracle@targethost]/data # unzip ogg112101_fbo_ggs_Linux_x64_ora11g_64bit.zip

[oracle@targethost]/data # tar -xvf ogg112101_fbo_ggs_Linux_x64_ora11g_64bit.zip

[oracle@sourcehost]/data/ggate # ./ggsci


GGSCI (targethost) 1> create subdirs

1. Ensure The database is in archive log mode

2. Create Necessary tablespace and goldengate user in database
SQL> create tablespace ggs_data datafile '/data/GGS/Base/ggs_data01.dbf' size 200m;
SQL> create user ggs_owner identified by ggs_owner default tablespace ggs_data temporary tablespace temp;
SQL> grant connect,resource to ggs_owner;
SQL> grant select any dictionary, select any table to ggs_owner;
SQL> grant create table to ggs_owner;
SQL> grant flashback any table to ggs_owner;
SQL> grant execute on dbms_flashback to ggs_owner;
SQL> grant execute on utl_file to ggs_owner;
SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS;
SQL> alter session set recyclebin=OFF;
SQL> exec dbms_goldengate_auth.grant_admin_privilege('GGS_OWNER');
SQL> grant select any dictionary to GGS_OWNER;
SQL> grant insert any table to GGS_OWNER;
SQL> grant update any table to GGS_OWNER;
SQL> grant delete any table to GGS_OWNER;

Also Configure DDL Replication, Run the following scripts from goldengate software directory

@marker_setup
@ddl_setup
@role_setup
grant ggs_ggsuser_role to ggs_owner;
@ddl_enable
@ddl_pin GGS_OWNER



2)  Configuring Manager Process

On Source: Configure Manager Process
############################################################

cd /data/ggate
./ggsci
info all
EDIT PARAMS MGR
### Copy the below to param file
PORT 7809
USERID ggs_owner, PASSWORD ggs_owner
PURGEOLDEXTRACTS /data/ggate/dirdat/ex, USECHECKPOINTS
######start the manager process ########
start manager
info all

############################################################
On Target: Configure Manager Process
############################################################
cd /data/ggate
./ggsci
info all
EDIT PARAMS MGR
### Copy the below to param file
PORT 7809
USERID ggs_owner, PASSWORD ggs_owner
PURGEOLDEXTRACTS /u01/ggt_target/dirdat/rt, USECHECKPOINTS
######start the manager process ########
start manager

info all

3 : Configure the Extract / Replicat for Initial Load




4: Configuring Online Change Synchronization after initial load



In this example , we will configure a continuous synchronisation for the same myobj table.
  • Create a GoldenGate Checkpoint table
  • Create an Extract group
  • Create a parameter file for the online Extract group
  • Create a Trail
  • Create a Replicat group
  • Create a parameter file for the online Replicat group


 5: Configuring Secondary Extract on Source (datapump Extract)



In the previous example, we have configured the extract process which extracts the changes from source and write the trail files to target.
However, in large system this can lead to lag for extract process and may have chance of loosing data.
Hence configuring local extract apart from remote trail is also possible using datapump process (differs from database expdp/impdp datapump).
Datapump process create local trail files and send them to remote as required.


6: Configuring DDL Synchronization


In Previous examples we see Extract and Replicat process and dml synchronisation.
Where in if you want DDL also synchronised across databases then extract parameter file must be changed accordingly.
In addition to extract options, we must execute scripts (refer to Example 1) to configure the ddl setup.
Also, the object that need to be DDL synchronised option trandata should be enabled.



 7: Filtering the Data


In this example we see how to filter the data changes to target side. i.e we can exclude some changes to thetarget side and skip them applying.



 8: Using Defgen Utility



It may be possible that some changes happen to table structure on target side, but this affects the replicat process.
For example, if a column name is changed in the replicat side itself and the primary column name is different then the replicat process will abended with error "invalid identifier"
In those cases, defgen utility will help to handle the column name changes.
Not only the above case, when you have structural changes between tables defgen utility can be used to create a COLMAP information.
First lets create a DDL information using defgen utility on source side.
## Create a Defgen Parameter file
EDIT PARAMS defgen
DEFSFILE I:\ggs_source\dirsql\def.sql
USERID ggs_owner, PASSWORD ggs_owner
TABLE test.myobj;
## Using Defgen utitlty create the sql file
./defgen paramfile I:\ggs_source\dirprm\defgen.prm
## Copy the generated SQL file to target location
scp I:\ggs_source\dirsql\def.sql 192.168.56.109:/u01/ggt_target/dirsql/def.sql
On target side, Edit the Replicat parameter file to colmap the differences in column names
./ggsci
EDIT params rep2
##Edit and Add the Bold part of following lines to parameter file
REPLICAT rep2
SOURCEDEFS /u01/ggt_target/dirsql/def.sql
USERID ggs_owner, PASSWORD ggs_owner
MAP test.myobj, TARGET test.myobj, COLMAP (usedefaults,object_name=objname);
## Start the replicat
start replicat rep2
## Replication will proceed with out error


9: Conflict Resolution & Skipping Transaction


In replication, one of the most important issue is conflict data and whenever the conflicts happen the replication stops and it will not proceed. Common cases of conflicts can be,
  • No data found (ora-1403)
  • Unique constraint errors
  • primary key violations
We need to either fix the data (not the dba job should checked by business analysts), or skip the transactions.
In order to skip the transactions in goldengate in such scenario, the following methods can be used. Usually and generally replicat process will be in abended state when conflict arises.
  • Using logdump
  • Skiptranaction
  • Handle collisions
  • Exceptional handling


 10: Reporting Commands in Goldengate



It is required to evaluate the extract status, and details and replicat status, lag details. Further also any long running transactions etc.







11: Missing Trail File


Sometimes there is likely hood that extract trail files are deleted by manually or by discard process.
In those cases, replicat process will abend since it does not have a trail file. Not only the replicat, the extract process itself will abend if its the current extract file.
The following is the sample errors in those cases, if an extract file is deleted.

2015-04-16 08:52:08  ERROR   OGG-01496  Oracle GoldenGate Capture for Oracle, myload2.prm:  Failed to open target trail file /data/ggate/dirdat/bb000007, at RBA 12678462.
In case of missing trail file or files, you can create a extract for specific period and run the extract, in this case you must have archives present in the location



12: Missing Archive Log File



Sometimes , due to RMAN Deletion Policy archives may be deleted and if goldengate extract process needs it, then as such no archive is present , the extract process will be abended.
In those cases, the following error will be shown in GG Error log
2011-05-10 15:13:23  ERROR   OGG-00446  Could not find archived log for sequence 92 thread 1 under default destinations SQL <SELECT  name    FROM v$archived_log   WHERE sequence# = :ora_seq_no AND  thread# = :ora_thread AND         resetlogs_id = :ora_resetlog_id AND         archived = 'YES' AND         deleted = 'NO>, error retrieving redo file name for sequence 92, archived = 1, use_alternate = 0 Not able to establish

initial position for begin time 2011-05-10 14:38:39.
If you have an archive log in backup. Just restore it from rman and start the extract process.
If you do not have archive log at all, then you must skip the archive log to do that.
Reading the error saying , the archive log sequence 92 is missing, so if you want to read next archive then issue following command
./ggsci
alter extract ext3, extseqno 93
Monitor the error log or check extract status
info extract ext3, detail
Note: By Doing so, the target may miss the data that changed and recorded in that missing archive log file.


13: Purging Trail Files



As like archive log clean up, one should also think about purging golden gate trail files to purge them.
By default, Goldengate manager does not purge them unless the purgeoldextracts parameter is not specified in the mgr param file.
Syntax for purging trail files
PURGEOLDEXTRACTS trail [, USECHECKPOINTS | NOUSECHECKPOINT ] [, MINKEEP_rule MINKEEPHOURS|MINKEEPDAYS|MINKEEPFILES] 
So now question is how often the manager purges the trail records, by default it is 10 MINS as per CHECKMINUTES default value. Even you do not specify this 10 mins is applicable.
For example, in the following the manager process purge the old extracts. The USECHECKPOINTS parameter tells manager process to check trail file is already applied or not in Checkpoint table. Do NOT use NOUSECHECKPOINT, since it will delete all the trail files without considering the trail file
.ggsci
./ggsci
info all
EDIT PARAMS MGR
### Add the bold line to your manager Param file ###
PORT 7809
USERID ggs_owner, PASSWORD ggs_owner
PURGEOLDEXTRACTS /data/ggate/dirdat/ex, USECHECKPOINTS

For example, you want to retain trails for 10 Hours and rest to be deleted use MINKEEP_RULE
.ggsci
./ggsci
info all
EDIT PARAMS MGR
### Add the bold line to your manager Param file ###
PORT 7809
USERID ggs_owner, PASSWORD ggs_owner
PURGEOLDEXTRACTS /data/ggate/dirdat/ex, USECHECKPOINTS , MINKEEPHOURS 10

For example, if you want to delete the DDL History also, you can use PURGEDDLHISTORY Marker in the parameter file
.ggsci
./ggsci
info all
EDIT PARAMS MGR
### Add the bold line to your manager Param file ###
PORT 7809
USERID ggs_owner, PASSWORD ggs_owner
PURGEOLDEXTRACTS /data/ggate/dirdat/ex, USECHECKPOINTS , MINKEEPHOURS 10
PURGEDDLHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5, FREQUENCYMINUTES 30
So this is all about configuration, what about when you hit a filesystem issue and you want to purge the trails and change the MINKEEPHOURS 10 reasonable number.
Lets check it. Check the extract or replicat trail file location by using
ggsci> info extract ext3 detail
cd /data/ggate/
[oracle@sourcehost]/data/ggatedu -sch *
4.3M    rt
15G     ex
15G     total
My extract folder showing 15G extracts are there. Now to purge this I will need to edit the manager parameter file, and you see below it keeps 10 Hours of trail files. By which using checkpoints , so its safe to delete those trail files even keeping for 5 hours. Lets do that.
.ggsci
./ggsci
info all
EDIT PARAMS MGR
PORT 7809
USERID ggs_owner, PASSWORD ggs_owner
PURGEOLDEXTRACTS /data/ggate/dirdat/ex, USECHECKPOINTS , MINKEEPHOURS 10
Change the Hours to 5, Ensure you have USECHECKPOINTS in parameterfile, this will make sure the trails files need for GG will not be deleted.
EDIT PARAMS MGR
PORT 7809
USERID ggs_owner, PASSWORD ggs_owner
PURGEOLDEXTRACTS /data/ggate/dirdat/ex, USECHECKPOINTS , MINKEEPHOURS 5
Once you changed , *** IMP *** Do not stop the manager, just refresh it. After 10 mins (maintainence activity default) it will start purging. If you stop/start the manager it will stop the extract and replicat process running on host.
GGSCI (source) 3> refresh mgr
Sending REFRESH request to MANAGER ...
Mgr Params Updated
After 10 mins you can see in error log file. The old purge files start purging.
If you want to purge the trail files immediately, you can use,
GGSCI(source) > send manager getpurgeoldextracts
GGSCI (source) > send manager purgeoldextracts
This command will immediately remove the trails from the location.
Also note, you must add each individual location for trails file to purge each extract trail files.




14: Auto Starting Extract & Replicat, More Manager Parameters




Manager parameter also can be used to define many other functions to manage.
For example if you want to start the Extract and Replicat Process automatically when a manager process start , keep the following line
AUTOSTART ER *
There are other options also available , retries and wait before retry and reset the minutes along with your restart.
AUTORESTART ER *, RETRIES 3, WAITMINUTES 10, RESETMINUTES 60
There are other certain options which can help you to manage goldengate effectively and important are,
BOOTDELAYMINUTESWhen ever a database host restarts , the goldengate manager wait until this many minutes to ensure OS completes start up and start GG then, Applicable only for windows.
DOWNREPORTMINUTESDisplays the Status of Extract/Replicat process in Error Log, the frequency of showing such status can be regulated with this option. If you have very large error log file it can be difficult to read every and then so you can specify how frequent you want to see such status.
DOWNCRITICALIn the report , it shows the process status abended/normal shutdown
LAGCRITICALSECONDSHow many seconds of LAG threshold before it publish to error log.
LAGCRITICALSpecifies a lag threshold that is considered critical and generates a warning to the error log.
Sample parameter file
.ggsci
edit params MGR
AUTOSTART ER *
AUTORESTART ER *, RETRIES 3, WAITMINUTES 10, RESETMINUTES 60
DOWNREPORTMINUTES 15
DOWNCRITICAL
LAGCRITICALSECONDS 10
LAGINFOMINUTES 0
LAGREPORTMINUTES 15



15: Security in Goldengate


As you aware, the parameter files for Extract and replicat contains database username and password which can be security concern.
Hence goldengate provide a keygen utility to create a encryption key and can be used to generate a encrypted password and use that encrypted password in parameter file.
Let's look at, first create a encryption keys using keygen utility in goldengate software location
oracle@sourcehost:/data/ggate  $ ./keygen  128 4 >> ENCKEYS
0x022A972B7CF6EF537DBCF35792BEH321
0x03CC8167B516426D9CA3A70B5B1FDW12
0x066E6C23EF369406BA8A5B3F2580DF54
0x0A10575F2857E61FD8710F73EFE08H11
### Copy the Enckeys file to target goldengate home
scp ENCKEYS target:/data/ggate
### Create a Encryption password using Encryption of above
[oracle@sourcehost]/data/ggate # ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Apr 23 2012 08:32:14
Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
GGSCI (source) 2> encrypt password gguser123 ENCRYPTKEY key1
Encrypted password:  AADAAAAAAAAAAAKAVHWAGJIGWBGHDBRAGJMIPEQEXBYEMDYIRBICFHSCTDHHEJHANCKAUDDGQJPBHRDT
Algorithm used:  AES128
GGSCI (source) 3> dblogin USERID gguser@MYDB, PASSWORD AADAAAAAAAAAAAKAVHWAGJIGWBGHDBRAGJMIPEQEXBYEMDYIRBICFHSCTDHHEJHANCKAUDDGQJPBHRDT, encryptkey key1
Successfully logged into database.
GGSCI (source) 4> dblogin USERID gguser@MYDB, PASSWORD gguser123
Successfully logged into database.
So you can use this encrypted password in your extract param file
GGSCI> edit params ext3
### Look at below bold part and remove old password and keep the encrypted password.
EXTRACT ext1
USERID ggs_owner, PASSWORD AADAAAAAAAAAAAKAVHWAGJIGWBGHDBRAGJMIPEQEXBYEMDYIRBICFHSCTDHHEJHANCKAUDDGQJPBHRDT, encryptkey  key1
RMTHOST 192.168.56.109, MGRPORT 7809
RMTTASK replicat, GROUP rep1
TABLE test.myobj;
As we removed the clear text password and reset the password with new above encrypted password.


16: Different Versions of Goldengate Replication


Is it possible to have goldengate replicate between 10g database and 11g database or viceversa.
Answer, Yes.
Its not the databases versions , since Since goldengate trail files are independent to database and they contain their own format of trail files by reading redo/archive log files. And this trail files are only means for replication.
But if the target version of goldengate is lower than source version then this could be an issue, due to header format maintain the version in extract trail files.
Consider this scenario
SourceTarget
11gR2 Database10G/11gR1 Database
11gR2 GG Software11GR1 GG Software
Extract will generate trails in 11gR2 FormatReplicat will try to read those extract trail and file with
ERROR OGG-01389 File header failed to parse tokens. File /data/ggate/ex10919, last offset 100, data: 0x
To overcome this, The extract parameter FORMAT must be added to target version so that extract maintains the trail file headers in lower version format as like target. As you see the format release is matched with target gg version above.
./ggsci
edit params ext3
extract ext3
userid ggs_owner, password ggs_owner
rmthost 192.168.56.109, mgrport 7809
rmttrail /data/ggate/ex00, format release 11.1
table test.myobj6;

Once added, alter the extract to start over from next trail file using etrollover. (new sequence will be generated)
ggsci&gt; alter extract ext3, etrollover

On Target side, alter the replication process to start read from new extrail sequence

ggsci&gt; <span style="font-family: Helvetica, Arial, sans-serif;">alter replicat rep1 extseqno 1

Should now the replicate process proceed without issue.




17: Start, Stop, Report, Altering Extract – Regenerating, Rolling Over etc




There are numerous options for extract process and changes from version to version and many new introduced.
Out of them , The following will be useful in the cases as mentioned below.
Starting & Stopping Extract
stop extract ext3
start extract ext3
Starting and stopping extracts
Killing Extract
kill extract ext3
Some times extract process does not respond to stop and you need to kill it. 
Report Lag of Extract from source
lag extract ext3
Reports how much lag extract is from the database, it will provide more information than INFO command
Begin the extract againALTER EXTRACT EXT3, BEGIN NOW
Caution, This will make extract to restart from current SCN, so when you do this you are actually making extract to start fresh replication from current point.
When you are trying to fix and restarting extract, you should use
start extract ext3
Restart extract from specific date and time
ALTER EXTRACT ext3, BEGIN 2015-07-13
Useful when you missed some extract files and replication is abended
but ensure this will reset extract trail
Restart extract from specific date and time & rollover
ALTER EXTRACT ext3, BEGIN 2015-07-13, etrollover
This will restart the extract to read specific time and also start new sequence number. The replicat must be modified to read from this new sequence on target
alter replicat rep3 , extseqno 1
Extract to start processing at a specific location in the trail.
ALTER EXTRACT ext3, EXTSEQNO 26, EXTRBA 338
Useful when extract abended for any reasons and you want to restart the extract to regenerate those redo records from that particular sequence at particular RBS
You can find the RBA and SEQNO in extract info, where its abended. or replicat
info extract ext3, detail
info replicat rep3, detail
For RAC, read for specific thread
ALTER EXTRACT ext3, THREAD 4, BEGIN 2015-07-13
For rac environments if you want extract process reads from thread 4 for the said date.
Start new sequence for Extract
ALTER EXTRACT ext3, ETROLLOVER
This will create new extract sequence no. and replicat must ensure to start from new sequence
alter replicat rep3, extseqno 1
For Oracle , Particular SCN
ALTER EXTRACT ext3, SCN 778899

For particular log sequence
ALTER EXTRACT ext3, logseqno 18
For oracle , to read from specific scn & specific log file sequence, This is differ from extseqno
For SQL Server, Particular LSN
ALTER EXTRACT ext3, LSN 3454:875:445
For MS-SQL Server, to start over from particular LSN number
For DB2, particular LRIALTER EXTRACT ext3, TRANLOG LRI 8066.322711For DB2 LUW, to restart the extract from particular LRI
Unregister Unregister extract ext3 Unregister extract from database
Delete Extractdelete extract ext3Deletes the extract 
cleanupcleanup extract ext3this will just clean the records from checkpoint table , not deletes the extract




18: Start, Stop, Report , Altering Replicat – Repositioning etc.



As like extract altering, you can also alter the replicat process to reposition to start over replication process from a trail file, Along with reposition with specific Extseqno , you can also reposition to specific date and time especially useful when you regenerate extract trail files or replication abended for some reasons.
Start Stop Replicat
start replicat rep3
stop replicat rep3
stop replicat r*
start replicat r*
starting and stopping replicat process
stop/start replicat process or group that start with r*
Kill Replicatkill replicat rep3Kill the replicat process when the stop command does not respond
Lag Replicatelag replicat rep3Shows how much lag replicat is from the extract.
From paritcular extract sequence
ALTER REPLICAT rep3, EXTSEQNO 53
Useful when you know which sequence the replicat stop and restart from that point
From particular RBA address
ALTER REPLICAT rep3, EXTRBA 0
ALTER REPLICAT rep3, EXTRBA 1001
Useful when the extrail is available and you want to read from particular place to avoid duplicacy of data
0 - means from header
n - means from particular that point.
From Particular date
ALTER REPLICAT rep3, BEGIN 2011-01-07 08:00:00
Reads and start replicate from particular date and time
UnregisterUnregister replicat rep3 Rather delete if you want to unregister the replicat from database, so ti removes the information from the goldengate metadata.
Deletedelete replicat rep3deletes the replicat from process
cleanupcleanup replicate rep3cleansup records from checkpoint table , does not delete the replicat




20: Managing Extracts for abase Homes

If there is one instance of Oracle Database on the system, set the ORACLE_HOME and ORACLE_SID environment variables at the system level. If you cannot set them that way, use the following SETENV statements in the parameter file of every Extract and Replicat group that will be connecting to the instance. The SETENV parameters override the system settings and allow the Oracle GoldenGate process to set the variables at the session level when it connects to the database.
SETENV (ORACLE_HOME = "path to Oracle home location")
SETENV (ORACLE_SID = "SID")
If there are multiple Oracle instances on the system with Extract and Replicat processes connecting to them, you will need to use a SETENV statement in the parameter file of each process group. As input to the SETENV parameter, use the ORACLE_HOME and ORACLE_SID environment variables to point Oracle GoldenGate to the correct Oracle instance. For example, the following shows parameter files for two Extract groups, each capturing from a different Oracle instance.
In one extract parameter ora9a:
EXTRACT ora9a
SETENV (ORACLE_HOME = "/home/oracle/ora/product")
SETENV (ORACLE_SID = "oraa")
USERIDALIAS tiger1
RMTHOST sysb
RMTTRAIL /home/ggs/dirdat/rt
TABLE hr.emp;
TABLE hr.salary;
In Another extract parameter orab:
EXTRACT orab
SETENV (ORACLE_HOME = "/home/oracle/ora/product")
SETENV (ORACLE_SID = "orab")
USERIDALIAS tiger1
RMTHOST sysb
RMTTRAIL /home/ggs/dirdat/st
TABLE fin.sales;
TABLE fin.cust;

Comments

  1. I got here much interesting stuff. The post is great! Thanks for sharing it! Extract Ic Source information

    ReplyDelete

Post a Comment

Popular posts from this blog

ORACLE RAC QUESTION

EXADATA ARCHITECTURE IN ORACLE