Part 2 – Build GoldenGate Bi-Direction Replication in few minutes on Docker

Part 2 – Build GoldenGate Bi-Direction Replication in few minutes on Docker

Now that we have completed Part 1 to set up the Container infrastructure, it’s time to create the GoldenGate replication. The script below will auto-create everything we need to enable a Bi-directional replication for the West and East databases (created in Part 1). If you have not completed Part 1, please go back and look at that post.

One of the great features of Oracle GoldenGate Microservices is the ability to communicate with GoldenGate remotely through a series of REST APIs. 

The script will perform the following steps:

  • Create database connections (West and East Regions)
  • Add schematrandata, checkpoint and heartbeat tables to both databases
  • Add two extracts, one for each region
  • Add two replicats, one for each region

1- Make sure the infrastructure created on PART 1 is completed build and healthy:

alexlima@alexlima-mac compose % docker ps
CONTAINER ID   IMAGE                                COMMAND                  CREATED              STATUS                        PORTS                                           NAMES
b28688e7545e   alexlima/goldengate-free:latest      "/u01/oggf/bin/boots…"   About a minute ago   Up About a minute (healthy)   80/tcp, 0.0.0.0:415->443/tcp, :::415->443/tcp   ogg233demo
6a26e05c961f   alexlima/oracle-free:23.3-slim-ogg   "/opt/oracle/run.sh"     About a minute ago   Up About a minute             0.0.0.0:1523->1521/tcp, :::1523->1521/tcp       db233demoE
05d55f7a2264   alexlima/oracle-free:23.3-slim-ogg   "/opt/oracle/run.sh"     About a minute ago   Up About a minute             0.0.0.0:1522->1521/tcp, :::1522->1521/tcp       db233demoW

2- Copy and paste the script below to a file (create_replication.sh) on your local desktop where the containers are running

#!/bin/bash

#docker compose up -d
#echo 
#echo " --->>> WATTING ~40 Seconds for all OGG Services to start ..........."
#sleep 40

hostname_ogg=("localhost")                             # Default to localhost for local Docker build
conn_propeties=("WEST:172.28.0.2" "EAST:172.28.0.3")   # Database Connection Properties: (<alias name>:<database host>)
list_region=("WEST" "EAST")                            # Database Regions Name
extract_properties=("WEST:EWEST:ew" "EAST:EEAST:ee")   # Name for the Extract (<connection alias>:<Extract_name>:<trail>)
replicat_properties=("WEST:REAST:ee" "EAST:RWEST:ew")  # Name for the replicat represents where the data come from (<connection alias>:<Replicat_name>:<trail>)

#Create Connection to the all Databases
for region in "${conn_propeties[@]}"
do
    conn_name=`echo $region | awk -F':' '{print $1}'`
    ip=`echo $region | awk -F':' '{print $2}'`
    curl -k -X POST 'https://'$hostname_ogg':415/services/v2/credentials/OracleGoldenGate/'$conn_name'' \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -H 'Authorization: Basic b2dnYWRtaW46V2VsY29tZSMjMTIz' \
    -d '{"userid":"oggadmin@'$ip':1521/freepdb1","password":"Welcome##123"}'
    echo 
    echo
done

# Add Schematranda, heartbeat and checkpoint tables to all Databases
for region in "${list_region[@]}"
do
    curl -k -X POST 'https://'$hostname_ogg':415/services/v2/connections/OracleGoldenGate.'$region'/trandata/schema' \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -H 'Authorization: Basic b2dnYWRtaW46V2VsY29tZSMjMTIz' \
    -d '{"operation":"add","schemaName":"hr","allColumns": true}'
    echo
    echo
    curl -k -X POST 'https://'$hostname_ogg':415/services/v2/connections/OracleGoldenGate.'$region'/tables/heartbeat' \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -H 'Authorization: Basic b2dnYWRtaW46V2VsY29tZSMjMTIz' \
    -d '{"frequency":60}'
    echo
    echo
    curl -k -X POST 'https://'$hostname_ogg':415/services/v2/connections/OracleGoldenGate.'$region'/tables/checkpoint' \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -H 'Authorization: Basic b2dnYWRtaW46V2VsY29tZSMjMTIz' \
    -d '{"operation":"add","name":"oggadmin.checkpoints"}'
    echo
    echo
done

# Add Extracts
for extract in "${extract_properties[@]}"
do
    region_name=`echo $extract | awk -F':' '{print $1}'`
    extract_name=`echo $extract | awk -F':' '{print $2}'`
    extract_file=`echo $extract | awk -F':' '{print $3}'`
    echo "#######################################"
    echo "Creating extract "$extract_name" ......"
    echo "#######################################"
    curl -k -X POST 'https://'$hostname_ogg':415/services/v2/extracts/'$extract_name'' \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -H 'Authorization: Basic b2dnYWRtaW46V2VsY29tZSMjMTIz' \
    -d '{
    "description":"Create Extract Demo",
    "config":[
        "EXTRACT '$extract_name'",
        "EXTTRAIL '$extract_file'",
        "USERIDALIAS '$region_name' DOMAIN OracleGoldenGate",
        "TRANLOGOPTIONS EXCLUDETAG 00",
        "DDL INCLUDE MAPPED",
        "TABLE HR.*;"
    ],
    "source":"tranlogs",
    "credentials":{
        "alias":"'$region_name'"
    },
    "registration":"default",
    "begin":"now",
    "targets":[
        {
        "name":"'$extract_file'",
        "sizeMB":50
        }
    ],
    "status":"running"
    }'
    echo
    echo  
done

# Add Replicat
for replicat in "${replicat_properties[@]}"
do
    region_name=`echo $replicat | awk -F':' '{print $1}'`
    replicat_name=`echo $replicat | awk -F':' '{print $2}'`
    replicat_file=`echo $replicat | awk -F':' '{print $3}'`
    echo "#########################################"
    echo "Creating replicat "$replicat_name" ......"
    echo "#########################################"
    curl -k -X POST 'https://'$hostname_ogg':415/services/v2/replicats/'$replicat_name'' \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -H 'Authorization: Basic b2dnYWRtaW46V2VsY29tZSMjMTIz' \
    -d '{
    "description":"Create Replicat Demo",
    "config":[
        "REPLICAT '$replicat_name'",
        "USERIDALIAS '$region_name' DOMAIN OracleGoldenGate",
        "DDL INCLUDE MAPPED",
        "MAP hr.*, TARGET hr.*;"
        ],
        "credentials": {"alias":"'$region_name'"},
        "mode": {"parallel":false,"type":"integrated"},
        "source": {"name": "'$replicat_file'"},
        "checkpoint":{"table":"oggadmin.checkpoints"},
        "status": "running"
    }'
    echo
    echo  
done
echo "#########################################################################"
echo "# Please visit https://localhost:415/ogg to explore GoldenGate 23c Free #"
echo "#########################################################################"

3- Execute the “create_replication.sh” script and watch the JSON output.

alexlima@alexlima-mac compose % ./create_replication.sh
{"$schema":"api:standardResponse","links":[{"rel":"canonical","href":"https://localhost:415/services/v2/credentials/OracleGoldenGate/WEST","mediaType":"application/json"},{"rel":"self","href":"https://localhost:415/services/v2/credentials/OracleGoldenGate/WEST","mediaType":"application/json"}],"messages":[{"$schema":"ogg:message","title":"Credential store altered.","code":"OGG-15114","severity":"INFO","issued":"2024-01-08T20:24:17Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"}]}

{"$schema":"api:standardResponse","links":[{"rel":"canonical","href":"https://localhost:415/services/v2/credentials/OracleGoldenGate/EAST","mediaType":"application/json"},{"rel":"self","href":"https://localhost:415/services/v2/credentials/OracleGoldenGate/EAST","mediaType":"application/json"}],"messages":[{"$schema":"ogg:message","title":"Credential store altered.","code":"OGG-15114","severity":"INFO","issued":"2024-01-08T20:24:18Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"}]}

{"$schema":"api:standardResponse","links":[{"rel":"canonical","href":"https://localhost:415/services/v2/connections/OracleGoldenGate.WEST/trandata/schema","mediaType":"application/json"},{"rel":"self","href":"https://localhost:415/services/v2/connections/OracleGoldenGate.WEST/trandata/schema","mediaType":"application/json"}],"messages":[{"$schema":"ogg:message","title":"SCHEMATRANDATA has been added on schema \"hr\".","code":"OGG-01788","severity":"INFO","issued":"2024-01-08T20:24:27Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"Partial JSON Update is disabled on schema \"hr\".","code":"OGG-30198","severity":"INFO","issued":"2024-01-08T20:24:27Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"SCHEMATRANDATA for scheduling columns has been added on schema \"hr\".","code":"OGG-01976","severity":"INFO","issued":"2024-01-08T20:24:27Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"SCHEMATRANDATA for all columns has been added on schema \"hr\".","code":"OGG-01977","severity":"INFO","issued":"2024-01-08T20:24:27Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"Schema level PREPARECSN set to mode NOWAIT on schema \"hr\"","code":"OGG-10154","severity":"INFO","issued":"2024-01-08T20:24:27Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"}]}

{"$schema":"api:standardResponse","links":[{"rel":"canonical","href":"https://localhost:415/services/v2/connections/OracleGoldenGate.WEST/tables/heartbeat","mediaType":"application/json"},{"rel":"self","href":"https://localhost:415/services/v2/connections/OracleGoldenGate.WEST/tables/heartbeat","mediaType":"application/json"}],"messages":[{"$schema":"ogg:message","title":"Successfully added heartbeat table.","code":"OGG-14101","severity":"INFO","issued":"2024-01-08T20:24:32Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"}]}

{"$schema":"api:standardResponse","links":[{"rel":"canonical","href":"https://localhost:415/services/v2/connections/OracleGoldenGate.WEST/tables/checkpoint","mediaType":"application/json"},{"rel":"self","href":"https://localhost:415/services/v2/connections/OracleGoldenGate.WEST/tables/checkpoint","mediaType":"application/json"}],"messages":[]}

{"$schema":"api:standardResponse","links":[{"rel":"canonical","href":"https://localhost:415/services/v2/connections/OracleGoldenGate.EAST/trandata/schema","mediaType":"application/json"},{"rel":"self","href":"https://localhost:415/services/v2/connections/OracleGoldenGate.EAST/trandata/schema","mediaType":"application/json"}],"messages":[{"$schema":"ogg:message","title":"SCHEMATRANDATA has been added on schema \"hr\".","code":"OGG-01788","severity":"INFO","issued":"2024-01-08T20:24:38Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"Partial JSON Update is disabled on schema \"hr\".","code":"OGG-30198","severity":"INFO","issued":"2024-01-08T20:24:38Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"SCHEMATRANDATA for scheduling columns has been added on schema \"hr\".","code":"OGG-01976","severity":"INFO","issued":"2024-01-08T20:24:38Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"SCHEMATRANDATA for all columns has been added on schema \"hr\".","code":"OGG-01977","severity":"INFO","issued":"2024-01-08T20:24:38Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"Schema level PREPARECSN set to mode NOWAIT on schema \"hr\"","code":"OGG-10154","severity":"INFO","issued":"2024-01-08T20:24:38Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"}]}

{"$schema":"api:standardResponse","links":[{"rel":"canonical","href":"https://localhost:415/services/v2/connections/OracleGoldenGate.EAST/tables/heartbeat","mediaType":"application/json"},{"rel":"self","href":"https://localhost:415/services/v2/connections/OracleGoldenGate.EAST/tables/heartbeat","mediaType":"application/json"}],"messages":[{"$schema":"ogg:message","title":"Successfully added heartbeat table.","code":"OGG-14101","severity":"INFO","issued":"2024-01-08T20:24:42Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"}]}

{"$schema":"api:standardResponse","links":[{"rel":"canonical","href":"https://localhost:415/services/v2/connections/OracleGoldenGate.EAST/tables/checkpoint","mediaType":"application/json"},{"rel":"self","href":"https://localhost:415/services/v2/connections/OracleGoldenGate.EAST/tables/checkpoint","mediaType":"application/json"}],"messages":[]}

#######################################
Creating extract EWEST ......
#######################################
{"$schema":"api:standardResponse","links":[{"rel":"canonical","href":"https://localhost:415/services/v2/extracts/EWEST","mediaType":"application/json"},{"rel":"self","href":"https://localhost:415/services/v2/extracts/EWEST","mediaType":"application/json"}],"messages":[{"$schema":"ogg:message","title":"Integrated Extract added.","code":"OGG-08100","severity":"INFO","issued":"2024-01-08T20:24:43Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"Extract group EWEST successfully registered with database at SCN 2379748.","code":"OGG-02003","severity":"INFO","issued":"2024-01-08T20:25:54Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"Parameter file EWEST.prm passed validity check.","code":"OGG-10183","severity":"INFO","issued":"2024-01-08T20:25:56Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"EXTTRAIL added.","code":"OGG-08100","severity":"INFO","issued":"2024-01-08T20:25:56Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"Extract group EWEST starting.","code":"OGG-00975","severity":"INFO","issued":"2024-01-08T20:25:56Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"Extract group EWEST started.","code":"OGG-15426","severity":"INFO","issued":"2024-01-08T20:25:56Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"}]}

#######################################
Creating extract EEAST ......
#######################################
{"$schema":"api:standardResponse","links":[{"rel":"canonical","href":"https://localhost:415/services/v2/extracts/EEAST","mediaType":"application/json"},{"rel":"self","href":"https://localhost:415/services/v2/extracts/EEAST","mediaType":"application/json"}],"messages":[{"$schema":"ogg:message","title":"Integrated Extract added.","code":"OGG-08100","severity":"INFO","issued":"2024-01-08T20:25:57Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"Extract group EEAST successfully registered with database at SCN 2380224.","code":"OGG-02003","severity":"INFO","issued":"2024-01-08T20:26:22Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"Parameter file EEAST.prm passed validity check.","code":"OGG-10183","severity":"INFO","issued":"2024-01-08T20:26:23Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"EXTTRAIL added.","code":"OGG-08100","severity":"INFO","issued":"2024-01-08T20:26:23Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"Extract group EEAST starting.","code":"OGG-00975","severity":"INFO","issued":"2024-01-08T20:26:23Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"Extract group EEAST started.","code":"OGG-15426","severity":"INFO","issued":"2024-01-08T20:26:23Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"}]}

#########################################
Creating replicat REAST ......
#########################################
{"$schema":"api:standardResponse","links":[{"rel":"canonical","href":"https://localhost:415/services/v2/replicats/REAST","mediaType":"application/json"},{"rel":"self","href":"https://localhost:415/services/v2/replicats/REAST","mediaType":"application/json"}],"messages":[{"$schema":"ogg:message","title":"Integrated Replicat added.","code":"OGG-08100","severity":"INFO","issued":"2024-01-08T20:26:23Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"Parameter file REAST.prm passed validity check.","code":"OGG-10183","severity":"INFO","issued":"2024-01-08T20:26:24Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"Replicat group REAST starting.","code":"OGG-00975","severity":"INFO","issued":"2024-01-08T20:26:24Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"Replicat group REAST started.","code":"OGG-15445","severity":"INFO","issued":"2024-01-08T20:26:24Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"}]}

#########################################
Creating replicat RWEST ......
#########################################
{"$schema":"api:standardResponse","links":[{"rel":"canonical","href":"https://localhost:415/services/v2/replicats/RWEST","mediaType":"application/json"},{"rel":"self","href":"https://localhost:415/services/v2/replicats/RWEST","mediaType":"application/json"}],"messages":[{"$schema":"ogg:message","title":"Integrated Replicat added.","code":"OGG-08100","severity":"INFO","issued":"2024-01-08T20:26:24Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"Parameter file RWEST.prm passed validity check.","code":"OGG-10183","severity":"INFO","issued":"2024-01-08T20:26:24Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"Replicat group RWEST starting.","code":"OGG-00975","severity":"INFO","issued":"2024-01-08T20:26:24Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"},{"$schema":"ogg:message","title":"Replicat group RWEST started.","code":"OGG-15445","severity":"INFO","issued":"2024-01-08T20:26:24Z","type":"https://docs.oracle.com/en/middleware/goldengate/core/23.3/error-messages/"}]}

#########################################################################
# Please visit https://localhost:415/ogg to explore GoldenGate 23c Free #
#########################################################################

4- Now let’s login to GoldenGate and see what we have just created

https://localhost:415/services/west/adminsrvr/v2/content/index.html


DB Connections Created:


Connect to the database to see the checkpoint, heartbeat tables created and trandata enabled:


Check both Extracts Created:


Check Extract Checkpoint information:


Check Extract Parameter file, note HR schema is configured:


Check the Replicat Parameter file:


Check the trail file management info:


5- At this point, your Bi-Directional configuration is completed, and you can log in to the database and make changes to the HR tables to see the data movement.

Connect to West (Note the PORT)

Connect to East Database (note the PORT)


6- Once you have finish testing, you can showdown the containers or stop them

alexlima@alexlima-mac compose % docker compose stop
[+] Stopping 3/3
 ✔ Container ogg233demo  Stopped                                                                                                                                                                                            11.0s
 ✔ Container db233demoW  Stopped                                                                                                                                                                                            11.0s
 ✔ Container db233demoE  Stopped                                                                                                                                                                                            11.2s
alexlima@alexlima-mac compose %

alexlima@alexlima-mac compose % docker compose down
[+] Running 4/4
 ✔ Container db233demoE                Removed                                                                                                                                                                              10.7s
 ✔ Container ogg233demo                Removed                                                                                                                                                                              11.0s
 ✔ Container db233demoW                Removed                                                                                                                                                                              11.2s
 ✔ Network compose_ogg_docker_network  Removed

This concludes the two-part series on deploying a Bi-Direction (active/active) GoldenGate replication in 3 containers. If you run into resource issues, you will need to increase your CPU and Memory allocation for Docker. If you have any questions, please let me know, and I will be happy to try to help.

I use Rancher Desktop and here is my configuration:

One thought on “Part 2 – Build GoldenGate Bi-Direction Replication in few minutes on Docker

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.