Sunteți pe pagina 1din 11

Oracle GoldenGate Hands-On Lab

This demo is intended to act as a prepared demo for Oracle->Oracle Transactional Data
Management that can be used to show some of the more interesting capabilities of Oracle
GoldenGate.
It includes:
* 1-1 mapping,
* 1 table mapping to 2 tables using a FILTER.
* using @STREXT, @STRFIND, and @STRLEN to split a source column into 2 on target.
* calling a SQLEXEC SQL statement to look up a value from another table and insert it.
* calling a SQLEXEC stored procedure to calculate a sum value
* using @CASE to select a column value based on another
* Auditing table that uses INSERTALLRECORDS to track all operations against a table
* A stored procedure that will create a reasonable load to demo latency/performance.
This demo has been set up for a laptop environment running Windows and Oracle.
To keep it simple, use a single Oracle instance for the demo environment, and install the Oracle
GoldenGate software twice: once under a source directory and again under a target directory.

Prerequisites:
 Oracle 9i, 10g or 11g has been installed. Full Oracle client software is installed
(GoldenGate needs access to the Oracle XDK libraries). **DO NOT USE INSTANT
CLIENT**; verify you can run a SQL*Plus session with both the source and target db users
and connect to the db; source and target users profiles are set up with correct Oracle
environment info; TNSNames is properly configured.
 Oracle GoldenGate has already been installed in a source directory <C:\ogg_source> by an
OS user with permissions to read the Oracle redo logs (user must log in as Administrator on
Windows). The default db username/password used in these scripts is oggs/source.
 GoldenGate has already been installed in a target directory <C:\ogg_target>. The default db
username/password used in theses scripts is oggt/target.
 Minimal supplemental logging is enabled for the source database. The database is in
archive log mode.
 Oracle db users (oggs and oggt) have been created on the source and target databases. For
the demo, give both users DBA privs to keep it simple. If you are wondering exactly which
privs are required, see the Oracle GoldenGate Install Guide for details.
 Note: although GoldenGate supports it, this demo is not set up to use ASM.

3. Create Tables on Source:


Create the source tables and procedures by running the following from
OGGProject\ogg_source
> sqlplus oggs/source < src_create.sql
You will get errors like table or view or sequence does not exist - thats ok.
You will get 4 Table created messages, a Sequence created message, and another Table
created message for the 5 source tables: customer, orders, order_details, products, biginsert_table

4. Create the target tables and procedures by running the following from
OGGProject \ogg_target
 sqlplus oggt/target < target_create.sql
You will get 8 Table created messages and one 1 row created message.
The target schema differs from the source in a number of ways.
* customers has been split into us_customers and non_us_customers. The correct table
will be populated by replicate by using a FILTER on the COUNTRY field.
* contactname in the customers table has been split into contactfirst and contactlast
and will be populated using @STR functions
* orders includes a new shippername field that will be populated by replicat using a
SQLEXEC lookup against the shippers table
* order_details includes a new total field that will be populated by replicat using a
stored proc
* products has the discontinued field changed to a varchar(8) that will be populated by
replicat using a CASE statement
* products_audit table that will have a row inserted for every operation on the
products table.
* a shippers table exists that is used by a SQLEXEC SQL to lookup shippername for
orders table.

5. Create GG Processes on Source:


If you havent already started the Manager, edit the obey scripts on the source and target to uncomment out the START MGR command.
Run the obey script via GGSCI which can optionally start the manager, will add TRANDATA
(table level supplemental logging), and create/register the extract and pump on the source
GGSCI> obey ER_src_setup.oby

This is what you should see:

GGSCI (D620-LT-VB) 3> obey ER_src_setup.oby


GGSCI (D620-LT-VB) 4> -- optionally start manager from here
GGSCI (D620-LT-VB) 5> --START MANAGER
GGSCI (D620-LT-VB) 6>
GGSCI (D620-LT-VB) 6> -- log in to create supplemental log groups
GGSCI (D620-LT-VB) 7> DBLOGIN USERID oggs PASSWORD source
Successfully logged into database.
GGSCI (D620-LT-VB) 8>
GGSCI (D620-LT-VB) 8> --add table level supplemental logging
GGSCI (D620-LT-VB) 9> --force logging on non-updated columns with COLS keyword b
ecause
GGSCI (D620-LT-VB) 10> --we need values in those 2 columns for parameter passing
later
GGSCI (D620-LT-VB) 11> ADD TRANDATA customers

Logging of supplemental redo data enabled for table OGGS.CUSTOMERS.


GGSCI (D620-LT-VB) 12> ADD TRANDATA orders

Logging of supplemental redo data enabled for table OGGS.ORDERS.


GGSCI (D620-LT-VB) 13> ADD TRANDATA order_details COLS (UNITPRICE, QUANTITY)

Logging of supplemental redo data enabled for table OGGS.ORDER_DETAILS.


GGSCI (D620-LT-VB) 14> ADD TRANDATA products

Logging of supplemental redo data enabled for table OGGS.PRODUCTS.


GGSCI (D620-LT-VB) 15> ADD TRANDATA biginsert_table

Logging of supplemental redo data enabled for table OGGS.BIGINSERT_TABLE.


GGSCI (D620-LT-VB) 16>
GGSCI (D620-LT-VB) 16> --verify supplemental log groups were created
GGSCI (D620-LT-VB) 17> INFO TRANDATA *

Logging of supplemental redo log data is enabled for table OGGS.BIGINSERT_TABLE


Logging of supplemental redo log data is enabled for table OGGS.CUSTOMERS
Logging of supplemental redo log data is enabled for table OGGS.ORDERS
Logging of supplemental redo log data is enabled for table OGGS.ORDER_DETAILS
Logging of supplemental redo log data is enabled for table OGGS.PRODUCTS
GGSCI (D620-LT-VB) 18>
GGSCI (D620-LT-VB) 18> --register log based extract to the manager starting now

GGSCI (D620-LT-VB) 19> ADD EXTRACT ggs_ext, TRANLOG, BEGIN now


EXTRACT added.

GGSCI (D620-LT-VB) 20>


GGSCI (D620-LT-VB) 20> --register the extacts trail info
GGSCI (D620-LT-VB) 21> ADD EXTTRAIL .\dirdat\et, EXTRACT ggs_ext
EXTTRAIL added.

GGSCI (D620-LT-VB) 22>


GGSCI (D620-LT-VB) 22> --register the pump process
GGSCI (D620-LT-VB) 23> --pump reads from exttrailsource file named et
GGSCI (D620-LT-VB) 24> ADD EXTRACT ggs_pump, EXTTRAILSOURCE .\dirdat\et

EXTRACT added.

GGSCI (D620-LT-VB) 25>


GGSCI (D620-LT-VB) 25> --register the remote trail
GGSCI (D620-LT-VB) 26> --pump writes to remote trailfile named rt
GGSCI (D620-LT-VB) 27> ADD RMTTRAIL .\dirdat\rt, EXTRACT ggs_pump
RMTTRAIL added.

GGSCI (D620-LT-VB) 28>

6. Create GG Processes on Target:


Run obey script via GGSCI to start the manager (which may already be started from your
installation steps which were done prior to these instructions) and create the replicat on the target
GGSCI> obey ER_target_setup.oby
You should see this:
GGSCI (D620-LT-VB) 18> obey ER_target_setup.oby
GGSCI (D620-LT-VB) 19> --START MANAGER
GGSCI (D620-LT-VB) 20>
GGSCI (D620-LT-VB) 20> --Login to Database
GGSCI (D620-LT-VB) 21> dblogin userid oggt, password target
Successfully logged into database.
GGSCI (D620-LT-VB) 22>
GGSCI (D620-LT-VB) 22> --Adds Checkpoint Table
GGSCI (D620-LT-VB) 23> add checkpointtable OGGT.GGSCHKPT

Successfully created checkpoint table OGGT.GGSCHKPT.


GGSCI (D620-LT-VB) 24>
GGSCI (D620-LT-VB) 24> --Adds the replicat process
GGSCI (D620-LT-VB) 25> ADD REPLICAT GGS_REP, EXTTRAIL .\dirdat\rt, CHECKPOINTTAB
LE OGGT.GGSCHKPT

REPLICAT added.

GGSCI (D620-LT-VB) 26>

7. Run the DEFGEN utility on the source side


From the directory of your source OGG installation:
ogg_source> defgen paramfile .\dirprm\defgen.prm
You should see this:
C:\ogg_source>defgen paramfile .\dirprm\defgen.prm
***********************************************************************
Oracle GoldenGate Table Definition Generator for Oracle
Version 10.4.0.19 Build 002
Windows (optimized), Oracle 10 on Sep 18 2009 16:01:47
Copyright (C) 1995, 2009, Oracle and/or its affiliates. All rights reserved.

Starting at 2009-12-01 15:21:01


***********************************************************************
Operating System Version:
Microsoft Windows XP Professional, on x86
Version 5.1 (Build 2600: Service Pack 3)
Process id: 10160
***********************************************************************
**
Running with the following parameters
**
***********************************************************************
--paramter file to run the defgen utility
--to document source metadata
--for heterogenous replication
--from ogg_source directory issue
--DEFGEN PARAMFILE .\dirprm\defgen.prm
--write out source defs file to local directory
--then copy it to targets dirdef directory
DEFSFILE .\dirdef\source.def, PURGE
--log in to get meta data
USERID oggs, PASSWORD ******
--get definitions for these tables

TABLE OGGS.CUSTOMERS;
Retrieving definition for OGGS.CUSTOMERS
TABLE OGGS.ORDERS;
Retrieving definition for OGGS.ORDERS
TABLE OGGS.ORDER_DETAILS;
Retrieving definition for OGGS.ORDER_DETAILS
TABLE OGGS.PRODUCTS;
Retrieving definition for OGGS.PRODUCTS
TABLE OGGS.BIGINSERT_TABLE;
Retrieving definition for OGGS.BIGINSERT_TABLE

Definitions generated for 5 tables in .\dirdef\source.def

C:\ogg_source>

8. Move the <ogg_source>\dirdef\source.def file to <ogg_target> \dirdef

9. Start GG processes on Source and Target


Run the following from both source and target GGSCI sessions:
GGSCI> start ER *
GGSCI> info ER *

/*which will confirm extract, pump, and replicat are running*/

10. Load Source Database


Run the following on the source from OGGProject\ogg_source
This is a windows batch file to load all data tables:
> src_load.bat

This query will run count(*) on each table to confirm load.


> sqlplus oggs/source < src_count.sql
customers = 91
orders = 830
order_detail = 2155
products = 77
biginsert_table = 0
11. Show replication working correctly.
Since GG is up and running the data will be replicated to the target.
Run the following on the target from OGGProject\ogg_target to confirm:
sqlplus oggt/target < target_count.sql
/* will run count(*) on each table to confirm replication */
us_customers = 13
non_us_customers = 78
orders = 830
order_detail = 2155
products = 77
products_audit = 77
biginsert_table = 0
(Optional) Show report on replicate to show how many records were inserted on each table:
GGSCI> send ggs_rep, report
GGSCI> view report ggs_rep, details

Individual Capability Demonstration

Run individual demo scripts to show features. Generally there is one script to make changes on the
source and a second to select the changed/added rows on the target. Scripts are run from sqlplus
from the OGGProject\ogg_source or OGGProject\ogg_target demo directories:

1. Customers - shows FILTER on country field splitting records between two tables on target.
Also shows string manipulation functions splitting a string column into 2 columns on the target.
On source: CMD> sqlplus oggs/source < insert_cust.sql
On target: CMD> sqlplus oggt/target < select_cust.sql

2. Orders - shows SQL lookup of shippername using shipvia column first via an insert and then an
update.
On source: CMD> sqlplus oggs/source < insert_orders.sql
On target: CMD> sqlplus oggt/target < select_orders.sql
On source: CMD> sqlplus oggs/source < update_orders.sql
On target: CMD> sqlplus oggt/target < select_orders.sql

3. Order_Details - shows total field being filled in by a stored procedure via an update.
On target: CMD> sqlplus oggt/target < select_order_det.sql
On source: CMD> sqlplus oggs/source < update_order_det.sql
On target: CMD> sqlplus oggt/target < select_order_det.sql

4. Products - shows @CASE() used to translate discontinued field from number to varchar (1 =
Yes, 0 = No, null = unknown)
On target: CMD> sqlplus oggt/target < select_prod.sql
On source: CMD> sqlplus oggs/source < update_prod.sql
On target: CMD> sqlplus oggt/target < select_prod.sql

5. Products_Audit - shows table that records all transactions while adding additional information
via functions and user tokens (HOSTNAME and USERID).
On target: CMD> sqlplus oggt/target < select_audit.sql /* show insert and update records
On source: CMD> sqlplus oggs/source < delete_prod.sql
On target: CMD> sqlplus oggt/target < select_audit.sql /* show delete records

6. Show report on replicate in order to show changed record reporting on each table and lag time
GGSCI> send ggs_rep, report
GGSCI> view report ggs_rep, details
/* inspect report */

GGSCI> lag ggs_rep


/* expect 1-2 seconds */

7. Biginsert stored procedure


This calls a stored procedure that by default does 1000 transactions each inserting 100 records.
This can be used to show off performance. Edit the file <ogg_source>\ggsdemo_src\biginsert.sql to
change the number of transactions or the operations per transaction.
Run the following on the target to reset stats:
GGSCI> stats ggs_rep, reset

/* reset stats so as not to include earlier lower activity.*/

Run the following on the source side to invoke the stored procedure
CMD> sqlplus oggs/source < biginsert.sql

Run the following on the target machine during and afterward to show operation rates
GGSCI> stats ggs_rep, reportrate sec
Operation rates were generally between 1000-1600 per sec

10

Note: these numbers are transaction processed since reset - so you should run ASAP after
running the biginsert.sql script to get the most accurate numbers. Sitting idle drops the ops/sec rate.
There is also a REPORTCOUNT EVERY 1 MINUTES, rate in the ggs_rep parameter file, that
will print the number of records processed and the rate in the ggs_rep report file. It only does this
while the replicat is actively processing records.
To view:
GGSCI> view report ggs_rep, details

Misc.
There are several utility sql scripts:
src_clean.sql
target_clean.sql
src_count.sql
target_count.sql

/* truncates all source tables


/* truncates all target tables except shippers
/* count records on all source tables
/* count records on all target tables

11

S-ar putea să vă placă și