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:

  • A PostgreSQL installation to serve as the source database (Installation instructions follow in Task 0.)
  • Open port 5432 in your VCN's security list
  • An Autonomous Transaction Processing instance to serve as the target database

Task 0: Set up the environment

To set up the environment for this Quickstart:
  1. Install PostgreSQL.
    1. Run the following commands:
      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:
      1. Locate and uncomment listen_addresses = 'localhost' and change localhost to an asterisk (*):
        listen_addresses = '*'
      2. 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.
    2. 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
  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:
      create user ggadmin with password 'W3lcome@1234';
      alter user ggadmin with SUPERUSER;
      GRANT ALL PRIVILEGES ON DATABASE ociggll TO ggadmin;
  7. Set up Autonomous Transaction Processing:
    1. Download and unzip the sample database schema.
    2. In the Oracle Cloud console, select your ATP instance from the Autonomous Databases page to view its details and access Database Actions.
    3. Click Database Actions.
    4. Enable the GGADMIN user:
      1. Under Administration, click Database Users.
      2. Locate GGADMIN, and then click its ellipsis menu (three dots) and select Edit.
      3. In the Edit User panel, enter the GGADMIN password, confirm the password, and then disable Account is Locked.
      4. Click Apply Changes.
    5. Load the target sample schema and data:
      1. From the Database Actions Selector menu, under Development, 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 W3lcome@1234.
    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. After signing in, open the navigation menu, and then click Configuration.
  3. Click Connect. Checkpoint table and TRANDATA fields appear if the connection is successful.
  4. Next to TRANDATA Information, click Add TRANDATA (plus icon).
  5. For Table Name, enter src_ociggll.*, and then click Submit.

    Note:

    You only need to click Submit once. 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. On the Administration Service page, click Add Extract (plus icon).
    2. On the Extract Type page, select Change Data Capture Extract, and then click Next.
    3. Complete the Extract Options as follows, and then click Next:
      • For Process Name, enter a name for the Extract, such as ECDCPSQL.
      • For Credential Domain, select Oracle GoldenGate.
      • For Credential Alias, select the alias.
      • For Begin, select Now.
      • For Trail Name, enter a two-character trail name, such as P1.
    4. On the Extract Parameters page, add the following:
      TABLE SRC_OCIGGLL.*;
    5. Click Create and Run.
  2. Add the Initial Load Extract:
    1. On the Deployments page, select the PostgreSQL deployment created in Task 1.
    2. On the deployment details page, click Launch Console.
    3. Sign in to the source PostgreSQL deployment console using the Administrator credentials specified when you created the deployment in Task 1.
    4. On the Administration Service Overview page, click Add Extract (plus icon).
    5. On the Extract Type page, select Initial Load Extract, and then click Next.
    6. Complete the Extract Options as follows, and then click Next:
      • For Process Name, enter a name, such as EINIPSQL.
      • For Credential Domain, select Oracle GoldenGate.
      • For Credential Alias, select the alias.
      • For Trail Name, enter a two-character trail name, such as I1.
    7. In the Extract Parameters text area, add the following, and then click Create and Run:
      EXTRACT EINIPSQL
      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.
    8. Click Create and Run.
You return to the Administration Service Overview 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.
  3. Create a user for the Distribution Path.
    1. Open the navigation menu, and then click Administrator.
    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 MySQL deployment console, create a credential for the user created in the previous step.
    1. Open the navigaton menu, and then select Configuration.
    2. Click Add Credential (plus icon), complete the fields as follows, and then click Submit:
      • For Credential Domain, enter GGSNetwork.
      • For Credential Alias, enter dpuser.
      • For Database Name, you can enter any name and leave the Database Server and Port fields blank, or use the default values.
      • For User ID, enter ggsnet
      • For Password, enter the same password used in the previous step.
  5. Create a Distribution Path.
    1. Click Distribution Service, and then click Add Path (plus icon).
    2. Complete the following fields, and click Create and Run:
      • For Path Name, enter a name for this path.
      • For Source Trail, leave blank.
      • For Trail Name, enter the Initial Load Extract trail name (I1).
      • For Target Authentication Method, select UserID Alias.
      • For Target, select wss.
      • For Target Host, enter the target Autonomous Database deployment URL, without the https:// or any trailing slashes.
      • For Port Number, enter 443.
      • For Trail Name, enter I1.
      • For Domain, enter the domain name created in the previous step.
      • For Alias, enter the alias created in the previous step.
    You're returned to the Distribution Service Overview 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 Receiver path details.

Task 5: Add a Replicat for Initial Load

  1. In the target Autonomous Database deployment, add a checkpoint table.
    1. Click Administration Service, and then open the navigation menu, and select Configuration.
    2. Click the connect icon for the target Autonomous Database instance.
    3. Click Add Checkpoint (plus icon).
    4. For Checkpoint Table, enter SRCMIRROR_OCIGGLL.CHECKTABLE.
    5. Click Submit.
  2. Add the Replicat.
    1. Open the navigation menu, select Overview, and then click Add Replicat (plus icon).
    2. On the Add Replicat page, under Replicat type, select Nonintegrated Replicat, and then click Next.
    3. On the Replicat Options page, complete the following form fields, and then click Next:
      • For Process Name, enter a name, such as RIL.
      • For Credential Domain, select the domain for the Autonomous Database connection.
      • For Credential Alias, select the alias of the Autonomous Database connection.
      • For Trail Name, enter the name of the Trail from Task 2 (I1).
      • For Checkpoint Table, select the Checkpoint table you created in Step 1.
    4. On the Replicat Parameters page, add the following mapping, and then click Next:
      MAP SRC_OCIGGLL.*, TARGET SRCMIRROR_OCIGGLL.*;
  3. Click Create and Run.
    You return to the Overview page, where you can review the Replicat details.
  4. Select the Replicat (RIL) and view its Details.
  5. 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.

Task 6: Verify the initial load

  1. In the Oracle Cloud console, open Database actions from the Autonomous Data Warehouse database details page.
  2. In Database Actions, under Development, click SQL.
  3. 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 7: Create a Distribution Path for Change Data Capture

  1. In the source MySQL deployment console, click Distribution Service.
  2. Click Add Path.
  3. Complete the following fields, and then click Create and Run:
    1. For Path Name, enter a name.
    2. For Source Extract, select the Change Data Capture Extract (ECDCPSQL).
    3. For Trail Name, select the Change Data Capture Extract trail file (P1)
    4. For Target Authentication Method, select UserID Alias.
    5. For Target, select wss.
    6. For Target Host, enter the target Autonomous Database deployment console URL, without the https:// or any trailing slashes.
    7. For Port Number, enter 443.
    8. For Trail Name, enter P1.
    9. For Domain, enter the domain name created in task 3.
    10. For Alias, enter the alias created in task 3.
  4. In the target Autonomous Database deployment console, click Receiver Service, and then review the Receiver path created.

Task 8: Add a Replicat for Change Data Capture

  1. Add a Replicat.
    1. Click Administrator Service, and then click Add Replicat (plus icon).
    2. On the Add Replicat page, under Replicat type, select Nonintegrated Replicat, and then click Next.
    3. On the Replicat Options page, complete the following form fields, and then click Next:
      • For Process Name, enter a name, such as RCDC.
      • For Credential Domain, select the domain for the Autonomous Database connection.
      • For Credential Alias, select the alias of the Autonomous Database connection.
      • For Trail Name, enter the name of the Trail from Task 2 (P1).
      • For Checkpoint Table, select the Checkpoint table you created in Step 1.
    4. On the Replicat Parameters page, add the following mapping, and then click Next:
      MAP SRC_OCIGGLL.*, TARGET SRCMIRROR_OCIGGLL.*;
    5. Click Create. Do not run the Replicat.
  2. On the Administration Service Overview 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 the Initial 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 Administration Service Overview 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.

Task 9: Verify Change Data Capture

Perform updates to the source PostgreSQL database to verify replication to Autonomous Transaction Processing.
  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 name (ECDCPSQL), and then click Statistics. Verify that src_ociggll.src_city has 10 inserts.

    Note:

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

Task 10: Monitor and maintain processes

  1. Monitor performance.
  2. Manage Trail files.