Replicate Data from PostgreSQL to Autonomous Transaction Processing

Learn to replicate data from a PostgreSQL server database to Autonomous Transaction Processing using OCI GoldenGate.

Before you begin

To successfully complete this quicktart, you must have the following:

Environment set up: PostgreSQL

To set up the environment for this Quickstart:
  1. Run the following commands to install PostgreSQL.
    1. Install PostgreSQL server:
      sudo yum install postgresql-server
    2. Install postgresql-contrib module to avoid this SQL exception:
      sudo yum install postgresql-contrib
    3. Create a new PostgreSQL database cluster:
      sudo postgresql-setup --initdb
    4. Enable the postgresql.service:
      sudo systemctl enable postgresql.service
    5. Start the postgresql.service:
      sudo systemctl start postgresql.service
  2. By default, PostgreSQL only allows local connections. Allow remote connectivity to PostgreSQL.
    1. In /var/lib/pgsql/data/postgresql.conf, prepare the database for replication.
    2. Locate and uncomment listen_addresses = 'localhost' and change localhost to an asterisk (*):
      listen_addresses = '*'
    3. Set the following parameters as follows:
      • wal_level = logical
      • max_replication_slots = 1
      • max_wal_senders = 1
      • track_commit_timestamp = on

      Note:

      Configure /var/lib/pgsql/data/pg_hba.conf to ensure that client authentication is set to allow connections from an Oracle GoldenGate host. For example, add the following:
      #Allow connections from remote hosts
      host    all    all    0.0.0.0/0    md5
      See The pg_hba.conf File for more information.
    4. Restart PostgreSQL server:
      sudo systemctl restart postgresql.service
  3. If using Oracle Cloud Compute to host PostgreSQL, open port 5432:
    sudo firewall-cmd --permanent --add-port=5432/tcp
    sudo firewall-cmd --reload
    sudo firewall-cmd --list-all
  4. Open port 5432 in your VCN's security list.
  5. Connect to PostgreSQL.
    > sudo su - postgres
    > psql

    Note:

    Alternatively, you can enter sudo su - postgres psql if the above example doesn't work.
  6. Set up PostgreSQL.
    1. Download and run seedSRCOCIGGLL_PostgreSQL.sql to set up the database and load the sample data.
    2. Run the following commands to set up the user (ensure you replace <password> with an actual password):
      create user ggadmin with password '<password>';
      alter user ggadmin with SUPERUSER;
      GRANT ALL PRIVILEGES ON DATABASE ociggll TO ggadmin;

Environment set up: Autonomous Transaction Processing (ATP)

  1. Download and unzip the sample database schema.
  2. Unlock the GGADMIN user.
    1. In the Oracle Cloud console, select your ATP instance from the Autonomous Databases page to view its details and access Database Actions.
    2. Click Database Actions, and then click Database Users.
    3. Locate GGADMIN, and then click its ellipsis menu (three dots) and select Edit.
    4. In the Edit User panel, enter the GGADMIN password, confirm the password, and then deselect Account is Locked.
    5. Click Apply Changes.
  3. Load the target sample schema and data.
    1. From the Database Actions menu, select SQL.
    2. Copy and paste the script from OCIGGLL_OCIGGS_SETUP_USERS_ADW.sql into the SQL worksheet.
    3. Click Run Script. The Script Output tab displays confirmation messages.
    4. Clear the SQL worksheet and then copy and paste the SQL from OCIGGLL_OCIGGS_SRC_MIRROR_USER_SEED_DATA.sql.
    5. To verify that the tables were created successfully, close the SQL window and reopen it again. In the Navigator tab, look for the SRC_OCIGGLL schema and then select tables from their respective dropdowns.

Task 1: Create the OCI GoldenGate resources

This quickstart example requires deployments and connections for both the source and target.
  1. Create a deployment for the source PostgreSQL database.
  2. Create a deployment for the target Autonomous Transaction Processing instance.
  3. Create a connection to the source PostgreSQL database.
    1. For Type, ensure that you select PostgreSQL Server.
    2. For Database name, enter ociggll.
    3. For Host, enter the public IP of the Compute instance that PostgreSQL runs on.
    4. For Port, enter 5432.
    5. For Username, enter ggadmin.
    6. For Password, enter a password.
    7. For Security Protocol, select Plain.
  4. Create connection for the target Autonomous Transaction Processing instance.
  5. Create a connection to GoldenGate, and then assign this connection to the source PostgreSQL deployment.
  6. Assign the source connection to the source PostgreSQL deployment.
  7. Assign the target connection to the target Oracle deployment.

Task 2: Enable supplemental logging

To enable supplemental logging:
  1. Launch the PostgreSQL GoldenGate deployment console:
    1. From the Deployments page, select the PostgreSQL deployment to view its details.
    2. On the PostgreSQL deployment details page, click Launch console.
    3. On the deployment console sign in page, enter the GoldenGate admin credentials provided in Task 1, step 1.
  2. In GoldenGate 23ai, click DB Connections in the left navigation, then the source PostgreSQL database, and then Trandata.
  3. On the Trandata page, next to TRANDATA Information, click Add Trandata (plus icon).
  4. In the Trandata panel, for Schema Name, enter src_ociggll.*, and then click Submit.

    Note:

    Use the search field to search for src_ociggll and verify the tables were added.

Task 3: Create the Extracts

  1. Add the Change Data Capture Extract:
    1. In the left navigation, click Extracts,
    2. On the Extracts page, click Add Extract (plus icon), and then complete the fields as follows:
      • On the Extract Information page:
        1. For Extract type, select Change Data Capture Extract.
        2. For Process Name, enter a name for the Extract, such as ECDC.
        3. Click Next.
      • On the Extract Options page:
        1. For Source credentials, select Oracle GoldenGate from the Domain dropdown
        2. Select the source PostgreSQL database from the Alias dropdown.
        3. For Extract Trail Name, enter a two-character trail name, such as C1.
        4. Click Next.
      • On the Extract Parameters page, replace MAP *.*, TARGET *.*; with the following:
        TABLE SRC_OCIGGLL.*;
    3. Click Create and Run.
  2. Add the Initial Load Extract:
    1. On the Extracts page, click Add Extract, and then complete the Add Extract form as follows:
      • On the Extract Information page:
        1. For Extract type, select Initial Load Extract.
        2. For Process Name, enter a name, such as EIL.
        3. Click Next.
      • On the Extract Options page:
        1. For Source credentials, select Oracle GoldenGate from the Domain dropdown.
        2. Select the PostgreSQL database from the Alias, dropdown.
        3. For Extract Trail Name, enter a two-character trail name, such as I1.
        4. Click Next.
      • On the Extract Parameters page, replace the contents of the text area with the following:
        EXTRACT EIL
        USERIDALIAS PostgreSQL_Compute, DOMAIN OracleGoldenGate
        EXTFILE I1, PURGE
        TABLE src_ociggll.*;

        Note:

        Ensure that you remove the SOURCEDB parameter in front of USERIDALIAS before you move on.
    2. Click Create and Run.
You return to the Extracts page, where you can observe the Extract starting.

Task 4: Create the Distribution Path for Initial Load Extract

  1. On the Deployments page, select the target Autonomous Database deployment.
  2. On the deployment details page, click Launch Console, and then log in as the admin user.
  3. If using IAM credential store, proceed to the Create a Distribution Path step. If using GoldenGate credential store, create a user with which the source GoldenGate uses to connect to the target GoldenGate.
    1. In the navigation menu, click User Administration.
    2. Click Add New User (plus icon), complete the fields as follows, and then click Submit:
      • For Username, enter ggsnet.
      • For Role, select Operator.
      • Enter the password twice for verification.
  4. In the source PostgreSQL deployment console, create a Path Connection for the user created in the previous step.
    1. In the navigaton menu, click Path Connections.
    2. Click Add Path Connection (plus icon), complete the fields as follows, and then click Submit:
      • For Credential Alias, enter dpuser.
      • For User ID, enter ggsnet
      • For Password, enter the same password used in the previous step.
  5. Create a Distribution Path.
    1. In the service menu bar, click Distribution Service, and then click Add Distribution Path (plus icon).
    2. Complete the Add Path form as follows:
      • On the Path Information page:
        1. For Path Name, enter a name for this path.
        2. Click Next.
      • On the Source Options page:
        1. For Source Extract, leave blank.
        2. For Trail Name, enter the Initial Load Extract trail name (I1).
        3. Click Next.
      • On the Target Options page:
        1. For Target, select wss.
        2. For Target Host, enter the target deployment URL, without the https:// or any trailing slashes.
        3. For Port Number, enter 443.
        4. For Trail Name, enter I1.
        5. For Target Authentication Method, select UserID Alias.
        6. For Domain, enter the domain name created in the previous step.
        7. For Alias, enter the alias created in the previous step (dpuser).
        8. Click Next.
    3. Click Create and Run.
    You return to the Distribution Service page where you can review the path created.
  6. In the target Autonomous Database deployment console, review the Receiver path created as a result of the Distribution path:
    1. Click Receiver Service.
    2. Review the Distribution Path details.

Task 5: Add a Replicat for Initial Load

  1. In the target Autonomous Database deployment, add a Checkpoint table.
    1. In the navigation menu, click DB Connections
    2. Select the target Autonomous Database instance, and then Checkpoints.
    3. On the Checkpoints page, click Add Checkpoint (plus icon).
    4. In the Checkpoint panel, for Schema Table, enter SRCMIRROR_OCIGGLL.CHECKTABLE.
    5. Click Submit.
  2. Add the Replicat.
    1. In the navigation menu, click Replicats.
    2. On the Replicats page, click Add Replicat (plus icon), then complete the Add Replicat fields as follows:
      • On the Replicat Information page:
        1. For Replicat type, select Nonintegrated Replicat.
        2. For Process Name, enter a name, such as RIL.
        3. Click Next
      • On the Replicat Options page:
        1. For Replicat Trail Name, enter the name of the Trail from Task 2 (I1).
        2. For Target Credentials, select the Domain and Alias for the Autonomous Database connection.
        3. For Checkpoint Table, select the Checkpoint table you created in Step 1.
        4. Click Next.
      • On the Parameter File page, replace MAP *.*, TARGET *.*; with the following:
        MAP SRC_OCIGGLL.*, TARGET SRCMIRROR_OCIGGLL.*;
    3. Click Create and Run.
      You return to the Replicats page, where you can review the Replicat details.
  3. Select the Replicat (RIL) and view its Details.
  4. Click Statistics and review the number of Inserts. Refresh the page.
    • If the number of Inserts doesn't change, then all the records from the Initial Load have been loaded and you can stop the Replicat (RIL)
    • If the number of Inserts continues to increase, then keep refreshing the page until the Initial Load records are all loaded before continuing.
  5. Verify the Initial Load.
    1. In the Oracle Cloud console, on the Autonomous Database details page, click Database actions and then click SQL.
    2. In the SQL tool, enter each of the following statements into the worksheet and click Run Statement:
      SELECT * FROM SRCMIRROR_OCIGGLL.SRC_CITY;
      SELECT * FROM SRCMIRROR_OCIGGLL.SRC_CUSTOMER;
    The output should return the data that was loaded into the target database tables as a result of the Initial Load.

Task 6: Create a Distribution Path for Change Data Capture Extract

  1. In the source PostgreSQL deployment console, click Distribution Service.
  2. Click Add Distribution Path.
  3. Complete the Add Path form as follows:
    1. On the Path Information page:
      1. For Path Name, enter a name.
      2. Click Next.
    2. On the Source Options page:
      1. For Source Extract, select the Change Data Capture Extract (ECDC).
      2. For Trail Name, select the Change Data Capture trail file (C1).
      3. Click Next.
    3. On the Target Options page:
      1. For Target, select wss.
      2. For Target Host, enter the target deployment console URL (you can find this on the deployment details page, without the https:// or any trailing slashes.
      3. For Port Number, enter 443.
      4. For Trail Name, enter C1.
      5. For Target Authentication Method, select UserID Alias.
      6. For Domain, enter the domain name.
      7. For Alias, enter the alias.
    4. Click Create Path and Run.
  4. In the target Autonomous Database deployment console, click Receiver Service, and then review the Receiver path created.

Task 7: Add a Replicat for Change Data Capture

  1. In the target Autonomous Database deployment console, add a Replicat.
    1. In the Administration Service navigation menu, click Replicats.
    2. On the Replicats page, click Add Replicat (plus icon), and then complete the Add Replicat form as follows:
      • On the Replicat Information page:
        1. For Replicat type, select Nonintegrated Replicat.
        2. For Process Name, enter a name, such as RCDC.
        3. Click Next.
      • On the Replicat Options page:
        1. For Replicat Trail Name, enter the name of the Trail from Task 3 (C1).
        2. For Target Credentials, select the Domain and Alias for the Autonomous Database connection.
        3. For Checkpoint Table, select the Checkpoint table.
      • On the Replicat Parameters page, replace MAP *.*, TARGET *.*; with the following mapping:
        MAP SRC_OCIGGLL.*, TARGET SRCMIRROR_OCIGGLL.*;
    3. Click Create. Do not run the Replicat.
  2. On the Replicats page, select the Replicat for Initial Load (RIL) and view its Details.
  3. Click Statistics and review the number of Inserts. Refresh the page.
    • If the number of Inserts doesn't change, then all the records from the Initial Load have been loaded and you can stop the Replicat (RIL)
    • If the number of Inserts continues to increase, then keep refreshing the page until theInitial Load records are all loaded before continuing.

    Note:

    If you don't see any Inserts, click Performance Metrics Service, select the Extract, and then click Database Statistics.
  4. Return to the Replicats page and then start the Replicat for Change Data Capture (RCDC).
  5. After starting the Replicat for Change Data Capture, review its Details and Statistics to view the number of Inserts.
  6. Verify replication:
    1. Run the following script to perform inserts into the PostgreSQL database:
      Insert into src_ociggll.src_city (CITY_ID,CITY,REGION_ID,POPULATION) values (1000,'Houston',20,743113);
      Insert into src_ociggll.src_city (CITY_ID,CITY,REGION_ID,POPULATION) values (1001,'Dallas',20,822416);
      Insert into src_ociggll.src_city (CITY_ID,CITY,REGION_ID,POPULATION) values (1002,'San Francisco',21,157574);
      Insert into src_ociggll.src_city (CITY_ID,CITY,REGION_ID,POPULATION) values (1003,'Los Angeles',21,743878);
      Insert into src_ociggll.src_city (CITY_ID,CITY,REGION_ID,POPULATION) values (1004,'San Diego',21,840689);
      Insert into src_ociggll.src_city (CITY_ID,CITY,REGION_ID,POPULATION) values (1005,'Chicago',23,616472);
      Insert into src_ociggll.src_city (CITY_ID,CITY,REGION_ID,POPULATION) values (1006,'Memphis',23,580075);
      Insert into src_ociggll.src_city (CITY_ID,CITY,REGION_ID,POPULATION) values (1007,'New York City',22,124434);
      Insert into src_ociggll.src_city (CITY_ID,CITY,REGION_ID,POPULATION) values (1008,'Boston',22,275581);
      Insert into src_ociggll.src_city (CITY_ID,CITY,REGION_ID,POPULATION) values (1009,'Washington D.C.',22,688002);
    2. In the source PostgreSQL deployment console, select the Change Data Capture Extract (ECDC), and then click Statistics. Verify that src_ociggll.src_city has 10 inserts.

      Note:

      If the Extract captured no inserts, then restart the ECDC Extract.
    3. In the target Autonomous Database deployment console, select the Replicat name (RCDC), view its Details, and then check Statistics. Verify that SRCMIRROR_OCIGGLL.SRC_CITY has 10 inserts.

Task 8: Monitor and maintain processes

  1. Monitor performance.
  2. Manage Trail files.