Bajwa Consulting Need senior Oracle DBA help? Performance tuning, Cloud migrations, GoldenGate, backup and DR. Plus 70+ free DBA scripts.
Visit bajwaconsulting.com →

Wednesday, November 25, 2026

Oracle GoldenGate Bidirectional Replication: On-Premises to AWS EC2

This post sets up bidirectional (active-active) replication with Oracle GoldenGate between an on-premises Oracle database and an Oracle database running on Amazon EC2. Both databases accept changes, and each change is copied to the other side. It is a common pattern during a cloud migration: you keep both sides live, move users over gradually, and keep a way back.

The commands use GoldenGate 21c or later (Microservices Architecture) with the Admin Client. Classic Architecture was deprecated in 19c and is not available in 21c and later, so new setups should use Microservices.

The setup

SideDatabaseExtractReplicat
On premisesONPREM (19c, PDB SALESPDB)EXTAREPA (applies changes from AWS)
AWS EC2AWSDB (19c, PDB SALESPDB)EXTBREPB (applies changes from on premises)

Each side runs its own GoldenGate deployment. A distribution path sends each side's trail files to the other side over a secure WebSocket connection.

Before you start: active-active rules

  • Every replicated table needs a primary key or unique key. Without one, GoldenGate cannot find the right row to update on the other side.
  • Avoid key collisions. If both sides insert rows using sequences, give each side its own range. The simplest way is odd and even numbers: on premises START WITH 1 INCREMENT BY 2, on AWS START WITH 2 INCREMENT BY 2. Identity columns need the same treatment.
  • Stop the loop. A change applied by Replicat must not be captured again by the local Extract and sent back. Integrated Replicat tags its transactions, and Extract excludes them with TRANLOGOPTIONS EXCLUDETAG.
  • Plan for conflicts. If the same row is changed on both sides at the same moment, one change must win. Oracle's automatic conflict detection and resolution (latest timestamp wins) handles most cases.
  • Triggers and cascading deletes should fire only for local user changes, not for rows applied by Replicat. Integrated Replicat suppresses triggers by default; check any custom code that runs on DML.

1. Network between on premises and AWS

  • Connect the data center and the VPC with Site-to-Site VPN or Direct Connect. Do not open GoldenGate ports to the internet.
  • Allow the GoldenGate ports between the two deployments only, in the EC2 security group and the on-premises firewall. The ports are the ones you chose when you created the deployments (Service Manager, Administration, Distribution and Receiver services).
  • Use TLS certificates for the deployments so the distribution paths use wss://.

2. Prepare both databases

Run on both ONPREM and AWSDB, in CDB$ROOT unless noted:

-- ARCHIVELOG mode and force logging
SELECT log_mode, force_logging FROM v$database;
ALTER DATABASE FORCE LOGGING;

-- Minimal supplemental logging and the GoldenGate parameter
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
ALTER SYSTEM SET enable_goldengate_replication = TRUE SCOPE=BOTH;
ALTER SYSTEM SET streams_pool_size = 2G SCOPE=BOTH;   -- for integrated Extract and Replicat

-- GoldenGate administrator (common user)
CREATE USER c##ggadmin IDENTIFIED BY "ChangeMe#2026" CONTAINER=ALL;
GRANT DBA TO c##ggadmin CONTAINER=ALL;
EXEC DBMS_GOLDENGATE_AUTH.GRANT_ADMIN_PRIVILEGE('C##GGADMIN', container => 'ALL');

Use a strong password of your own and store it only in the GoldenGate credential store.

3. Credentials and schema logging (each side)

In the Admin Client, connected to that side's deployment:

ALTER CREDENTIALSTORE ADD USER c##ggadmin@onprem-scan:1521/ONPREM ALIAS onprem_root DOMAIN OracleGoldenGate
ALTER CREDENTIALSTORE ADD USER c##ggadmin@onprem-scan:1521/SALESPDB ALIAS onprem_pdb DOMAIN OracleGoldenGate

DBLOGIN USERIDALIAS onprem_pdb DOMAIN OracleGoldenGate
ADD SCHEMATRANDATA sales ALLCOLS

Do the same on AWS with aliases aws_root and aws_pdb.

4. Automatic conflict detection and resolution

Turn on Oracle's automatic CDR for each replicated table, on both databases. It adds a hidden timestamp column and resolves update conflicts with "latest timestamp wins":

BEGIN
  FOR t IN (SELECT table_name FROM dba_tables WHERE owner = 'SALES') LOOP
    DBMS_GOLDENGATE_ADM.ADD_AUTO_CDR(schema_name => 'SALES', table_name => t.table_name);
  END LOOP;
END;
/
SELECT table_owner, table_name FROM dba_gg_auto_cdr_tables;

5. Extract on each side

Parameter file for EXTA (on premises). EXTB on AWS is the same with its own names:

EXTRACT exta
USERIDALIAS onprem_root DOMAIN OracleGoldenGate
EXTTRAIL ea
TRANLOGOPTIONS EXCLUDETAG 00        -- skip changes applied by the local Replicat
DDL INCLUDE MAPPED
TABLE salespdb.sales.*;
DBLOGIN USERIDALIAS onprem_root DOMAIN OracleGoldenGate
ADD EXTRACT exta, INTEGRATED TRANLOG, BEGIN NOW
REGISTER EXTRACT exta DATABASE CONTAINER (salespdb)
ADD EXTTRAIL ea, EXTRACT exta
START EXTRACT exta

6. Initial load

If the AWS database starts empty, load it from on premises before starting the Replicats. The safest method is an export at a known SCN (Data Pump FLASHBACK_SCN), then starting the AWS Replicat after that SCN. I describe it step by step in my tutorial on GoldenGate initial load at SCN. Do not allow users to change data on AWS until the initial load is complete and REPB has caught up.

7. Distribution paths

From the on-premises deployment, send trail ea to AWS; from the AWS deployment, send trail eb back:

-- On premises
ADD DISTPATH dp_to_aws SOURCE trail://localhost:9002/services/v2/sources?trail=ea
    TARGET wss://ec2-gg.example.internal:9103/services/v2/targets?trail=ra

-- On AWS
ADD DISTPATH dp_to_onprem SOURCE trail://localhost:9002/services/v2/sources?trail=eb
    TARGET wss://onprem-gg.example.internal:9103/services/v2/targets?trail=rb

Replace the host names and ports with your own Distribution and Receiver service ports.

8. Replicat on each side

REPLICAT repb
USERIDALIAS aws_pdb DOMAIN OracleGoldenGate
DBOPTIONS INTEGRATEDPARAMS (parallelism 4)
MAP salespdb.sales.*, TARGET sales.*;
ADD REPLICAT repb, INTEGRATED, EXTTRAIL ra
START REPLICAT repb, AFTERCSN 4517823     -- the SCN of the initial load

Integrated Replicat tags its transactions with tag 00 by default, which is why each Extract uses EXCLUDETAG 00. Start REPA on premises the same way, reading trail rb.

9. Test before you trust it

  1. Insert a row on premises; it should appear on AWS within seconds. Repeat in the other direction.
  2. Update the same row on both sides at almost the same time; check that both end up with the newer value and that DBA_APPLY_ERROR is empty.
  3. Check that the row did not bounce back and forth: the trail statistics should show it once in each direction.
  4. Watch lag: INFO ALL and LAG REPLICAT repb in the Admin Client, or the Performance Metrics page in the web UI.
  5. Stop the network link for a few minutes and restart it; both sides should catch up without errors.

Day-to-day checks

INFO ALL
STATS REPLICAT repb, TOTAL, LATEST
VIEW REPORT repb

-- In the database
SELECT apply_name, status FROM dba_apply;
SELECT * FROM dba_apply_error;

Oracle GoldenGate is licensed separately from the database. Check your license before you build this in production, and test the whole design, including conflicts and a cutover, on test databases first.

More DBA scripts are in my GitHub repository: github.com/sbajwa55/dba-scripts. For help with Oracle, cloud migrations or AWS, visit Bajwa Consulting Services.

No comments:

Post a Comment