Book Image

Instant Oracle GoldenGate

By : Tony Bruzzese
Book Image

Instant Oracle GoldenGate

By: Tony Bruzzese

Overview of this book

Oracle GoldenGate is a comprehensive package for low-impact, real-time data capture, distribution, and delivery of transactional data across heterogeneous systems for continuous availability, zero downtime migration, and disaster recovery. All in all, it is a precise tool for data replication, regardless of the platform that you use in today’s environment. Instant Oracle GoldenGate exemplifies the ease of use of this package through the use of real-world examples. This book gives a good overview and hands-on approach to the most commonly used implementations in an Oracle GoldenGate environment.This How-to book will take you through a number of real-world examples quickly and effectively by eliminating much of the guess work for all users from novices to experienced users. You will learn about the key components of the architecture and simple one-way replication for a number of database tables or an entire schema. You’ll be covering key concepts and the implementation of high availability configurations such as Oracle RAC, encryption, and many different ways to transform and filter data to your target systems.
Table of Contents (7 chapters)

Configuring advanced settings (Simple)


In this section, we'll go over some advanced settings you could apply such as filtering, mapping, and data transformation.

How to do it…

OGG, in addition to replicating, allows data filtering, mapping, extraction, and transformation. Following, you'll discover a number of other functions that OGG can perform at either the source host or target host.

  1. To capture all table changes in a schema, use the following wildcard specification:

    TABLE   SCOTT.* ;
    
  2. When you need to exclude tables from being replicated, use the tableexclude clause as follows:

    TABLEEXLCUDE SCOTT.EMP ;
    TABLE   SCOTT.* ;
    
  3. OGG allows you to filter data based on Data Manipulation Language (DML) as follows:

    
    IGNOREDELETES
    MAP SCOTT.* , TARGET SCOTT.* ;
    
    
    
    IGNOREUPDATES
    MAP SCOTT.* , TARGET SCOTT.* ;
    
    
    
    IGNOREINSERTS
    MAP SCOTT.* , TARGET SCOTT.* ;
    
    
  4. You don't need to replicate every column of a table if the downstream system only requires a subset. We do it using the following:

    TABLE SCOTT.TCUSTMER, COLS(name,city,state) ;
    
    TABLE SCOTT.TCUSTMER, COLEXCEP(CODE_ID) ;
    
  5. You can also ignore specific users from being captured. This is useful when the majority of schemas are being replicated with a few exceptions. An example is as follows:

    
    TRANLOGOPTIONS EXCLUDEUSER <user>
    
    
  6. Filter rows based on specific column values or when specific conditions are met. This can be done using the following format:

    
    MAP SCOTT.TCUSTMER , TARGET SCOTT.TCUSTMER, WHERE (STATE in "CA")  ;
    
    
  7. Test for existence of a column in a data record as follows:

    
    MAP SCOTT.EMP , TARGET SCOTT.EMP,WHERE (SAL=@PRESENT AND SALARY > 999)  ;
    
    
  8. Data transformation is one of the tool's powerful capabilities for processes such as ETL (Extract-Transformation-Load). It can be done for the following:

    For mapping columns as follows:

    
    MAP SCOTT.EMP , TARGET SCOTT.EMP, COLMAP(USEDEFAULTS, SAL=SALARY);
    
    

    For entering default dates as follows:

    
    MAP SCOTT.TCUSTORD , TARGET SCOTT.TCUSTORD, COLMAP(USEDEFAULTS, ORDER_DATE=@DATENOW());
    
    

    For concatenating strings as follows:

    
    MAP SCOTT.EMP , TARGET SCOTT.EMP, COLMAP(USEDEFAULTS, NAME=@STRCAT(FIRST_NAME," ",LAST_NAME));
    
    
  9. We can perform the DML conversion in the following way. Inserts will become updates, updates will become deletes, and so on:

    INSERTUPDATES
    
    INSERTDELETES
    
    UPDATEDELETES
    
  10. For troubleshooting and reporting examples with OGG, tail the last 50 or so lines of the following file to view informational entries, warnings, and errors in OGG processing:

     $ <OGG_HOME>/ggserr.log      
    
  11. Viewing information about an Extract/Replicat's checkpoints, RBA, and trailfile sequence can be done using the following commands:

    $ GGSCI> info all | <group> 
    
  12. View the process report should the extract not start. Group can be an extract, data pump, or replicat.

    $ GGSCI> view report <group> 
    GGSCI> start ex01sand
    GGSCI> info all
    

    The output would be as follows:

    Program     Status      Group       Lag at Chkpt  Time Since Chkpt
    MANAGER     RUNNING
    EXTRACT     STOPPED     EX01SAND    00:00:00      00:02:59
    EXTRACT     RUNNING     PP01SAND    00:00:00      00:00:01
    REPLICAT    RUNNING     RE01SAND    00:00:00      00:00:03
    

    We can see that ex01sand won't start.

    GGSCI> view report ex01sand
    

    The output would be as follows:

    2012-12-12 19:46:23  ERROR   OGG-00664  OCI Error beginning session (status = 1017-ORA-01017: invalid username/password;
     logon denied).
    
    2012-12-12 19:46:23  ERROR   OGG-01668  PROCESS ABENDING.
    
  13. Edit the extract parameter file and make sure you update it with the correct password and then re-start the extract.

    GGSCI> edit param ex01sand 
    

    Ensure you add the correct password.

    GGSCI> start ex01sand
    GGSCI> info all
    

    The output should be as follows:

    Program     Status      Group       Lag at Chkpt  Time Since Chkpt
    MANAGER     RUNNING
    EXTRACT     RUNNING     EX01SAND    00:07:11      00:00:01
    EXTRACT     RUNNING     PP01SAND    00:00:00      00:00:02
    REPLICAT    RUNNING     RE01SAND    00:00:00      00:00:05
    

How it works…

Oracle GoldenGate is very flexible when it comes to dealing with data transformation and row filtering. Not only can it filter rows, but it can also filter based on the type of DML operations, such as updates, inserts, and deletes.

We've seen data capture by specifying explicitly the table name. However, you can use wild cards as well for an entire schema, or a specific table pattern such as TABLE SCOTT.*_TMP.

When you want to capture an entire schema and would like to exclude one or more tables from the capture process, make certain that the TABLEEXCLUDE clause is placed before the TABLE capture.

You might wonder why you would filter based on the DML statements, but consider the following; say you have source data where you have deletes but you don't want to propagate them to the target so as to keep a record of the row. You would ignore that delete operation on the target by stating IGNOREDELETES in the Replicat parameter file.

When extracting tables, you don't necessarily have to extract every column if they are not needed in the downstream system. You can use the COLS and COLSEXCEPT clause to control the columns of interest at the source.

Filtering rows is a nice way to ensure you only extract those rows with specific column values for delivery to your downstream system. Another useful operation is the presence or absence of particular column values such as the built in column function @PRESENT. GoldenGate has a number of functions that are preceded by the @ sign. Other examples are; @ABSENT and @NULL. Another way to filter is based on the FILTER clause on specific DML operations. We have not seen it yet, but here is an example:

TABLE SCOTT.SAL, FILTER (ON UPDATE, ON DELETE, SALARY > 499);
TABLE SCOTT.SAL, FILTER (ON INSERT, SALARY < 500);

When transforming data using COLMAP, you need to determine whether or not to use a definitions file. This depends whether or not source and target column structures are identical as defined by Oracle GoldenGate. GoldenGate considers columns identical when they have the same names, lengths, data type, semantics, and column order. As in the preceding example with data transformation, the @DATE function is synonymous to the SYSDATE function in Oracle and @STRCAT, is a string concatenation function.

The USEDEFAULTS clause applies default mapping rules to map source and target columns automatically if they have the same name.

DML conversions are interesting for the following reasons:

  • The INSERTUPDATES clause converts source updates to inserts at the target. This is useful for maintaining a transaction history on that table.

  • The INSERTDELETES clause converts source deletes to inserts at the target. This is necessary for retaining a history of all records that were present at the source.

  • The UPDATEDELETES clause converts source deletes to updates at the target.

The error log file ggserr.log located at the root directory of your OGG installation, is one of the first sources of troubleshooting and diagnosing problems. It is a chronological log of events, commands, statistics, information, warnings, errors, and so on.

The INFO command is a quick way to view status information regarding the OGG processes, whether they are running, stopped, or abended, and, followed by the VIEW REPORT <group> as in the preceding example, will often point you to the root cause of the error.