尋找 OCI GoldenGate 資料轉換

瞭解如何搭配使用 OCI GoldenGate Data Replication 和 Data Transforms 部署,在兩個自治式 AI 資料庫之間載入和轉換資料。

開始之前

若要順利完成此快速啟動,您需要:

作業 1:設定環境

  1. 建立資料複製部署

  2. 建立來源 OracleAutonomous AI 交易處理 (ATP) 連線

  3. 建立 targetAutonomous AI Lakehouse (ALK) 連線

  4. 指定部署連線

  5. 使用 SQL 工具啟用補充日誌記錄:

    ALTER DATABASE ADD SUPPLEMENTAL LOG DATA
  6. 在 SQL 工具中執行下列查詢,以確保來源資料庫中所有表格的 support_mode=FULL

    select * from DBA_GOLDENGATE_SUPPORT_MODE where owner = 'SRC_OCIGGLL';

任務 2:建立整合式擷取

「整合式擷取」會擷取來源資料庫的持續變更。

  1. 在部署詳細資料頁面上,選取啟動主控台

  2. 如有必要,請輸入 oggadmin 作為您在建立部署時所使用的使用者名稱和密碼,然後選取登入

  3. 新增交易資料和檢查點表格:

    1. 開啟導覽功能表,然後選取資料庫連線

    2. 選取連線至資料庫 SourceDB

    3. 在導覽功能表中,選取 Trandata ,然後選取新增 Trandata (加號圖示)。

    4. 結構名稱中,輸入 SRC_OCIGGLL,然後選取提交

    5. 若要驗證,請在「搜尋」欄位中輸入 SRC_OCIGGLL,然後選取搜尋

    6. 開啟導覽功能表,然後選取資料庫連線

    7. 選取連線至資料庫 TargetDB

    8. 在導覽功能表中,選取檢查點,然後選取新增檢查點 (加號圖示)。

    9. 檢查點資料表中,輸入 "SRCMIRROR_OCIGGLL"."CHECKTABLE",然後選取提交

  4. 新增擷取

    備註:請參閱其他擷取參數選項,以取得可用於指定來源表格之參數的詳細資訊。

    在「擷取參數」頁面上,將下列行附加至 EXTTRAIL <trail-name> 下:

    -- Capture DDL operations for listed schema tables
    ddl include mapped
    
    -- Add step-by-step history of
    -- to the report file. Very useful when troubleshooting.
    ddloptions report
    
    -- Write capture stats per table to the report file daily.
    report at 00:01
    
    -- Rollover the report file weekly. Useful when IE runs
    -- without being stopped/started for long periods of time to
    -- keep the report files from becoming too large.
    reportrollover at 00:01 on Sunday
    
    -- Report total operations captured, and operations per second
    -- every 10 minutes.
    reportcount every 10 minutes, rate
    
    -- Table list for capture
    table SRC_OCIGGLL.*;
  5. 檢查長時間執行的交易。在來源資料庫上執行下列命令檔:

    select start_scn, start_time from gv$transaction where start_scn < (select max(start_scn) from dba_capture);

    如果查詢傳回任何資料列,則您必須找出交易的 SCN,然後確認或倒回交易。

工作 3:使用 Oracle Data Pump (ExpDP) 匯出資料

使用 Oracle Data Pump (ExpDP) 將資料從來源資料庫匯出至 Oracle Object Store。

  1. 建立 Oracle Object Store 儲存桶

    記下用於「匯出」和「匯入」命令檔的命名空間和儲存桶名稱。

  2. 建立認證權杖,然後將權杖字串複製並貼到文字編輯器以供日後使用。

  3. 在您的來源資料庫中建立證明資料,將 <user-name><token> 取代為您的 Oracle Cloud 帳戶使用者名稱和您在上一個步驟中建立的權杖字串:

    BEGIN
      DBMS_CLOUD.CREATE_CREDENTIAL(
        credential_name => 'ADB_OBJECTSTORE',
        username => '<user-name>',
        password => '<token>'
      );
    END;
  4. 在您的來源資料庫中執行下列命令檔,以建立「匯出資料」工作。請確定已相應地取代物件存放區 URI 中的 <region><namespace><bucket-name>SRC_OCIGGLL.dmp 是執行此命令檔時將建立的檔案。

    DECLARE
    ind NUMBER;              -- Loop index
    h1 NUMBER;               -- Data Pump job handle
    percent_done NUMBER;     -- Percentage of job complete
    job_state VARCHAR2(30);  -- To keep track of job state
    le ku$_LogEntry;         -- For WIP and error messages
    js ku$_JobStatus;        -- The job status from get_status
    jd ku$_JobDesc;          -- The job description from get_status
    sts ku$_Status;          -- The status object returned by get_status
    
    BEGIN
    
    -- Create a (user-named) Data Pump job to do a schema export.
    h1 := DBMS_DATAPUMP.OPEN('EXPORT','SCHEMA',NULL,'SRC_OCIGGLL_EXPORT','LATEST');
    
    -- Specify a single dump file for the job (using the handle just returned)
    -- and a directory object, which must already be defined and accessible
    -- to the user running this procedure.
    DBMS_DATAPUMP.ADD_FILE(h1,'https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket-name>/o/SRC_OCIGGLL.dmp','ADB_OBJECTSTORE','100MB',DBMS_DATAPUMP.KU$_FILE_TYPE_URIDUMP_FILE,1);
    
    -- A metadata filter is used to specify the schema that will be exported.
    DBMS_DATAPUMP.METADATA_FILTER(h1,'SCHEMA_EXPR','IN (''SRC_OCIGGLL'')');
    
    -- Start the job. An exception will be generated if something is not set up properly.
    DBMS_DATAPUMP.START_JOB(h1);
    
    -- The export job should now be running. In the following loop, the job
    -- is monitored until it completes. In the meantime, progress information is displayed.
    percent_done := 0;
    job_state := 'UNDEFINED';
    while (job_state != 'COMPLETED') and (job_state != 'STOPPED') loop
      dbms_datapump.get_status(h1,dbms_datapump.ku$_status_job_error + dbms_datapump.ku$_status_job_status + dbms_datapump.ku$_status_wip,-1,job_state,sts);
      js := sts.job_status;
    
    -- If the percentage done changed, display the new value.
    if js.percent_done != percent_done
    then
      dbms_output.put_line('*** Job percent done = ' \|\| to_char(js.percent_done));
      percent_done := js.percent_done;
    end if;
    
    -- If any work-in-progress (WIP) or error messages were received for the job, display them.
    if (bitand(sts.mask,dbms_datapump.ku$_status_wip) != 0)
    then
      le := sts.wip;
    else
      if (bitand(sts.mask,dbms_datapump.ku$_status_job_error) != 0)
      then
        le := sts.error;
      else
        le := null;
      end if;
    end if;
    if le is not null
    then
      ind := le.FIRST;
      while ind is not null loop
        dbms_output.put_line(le(ind).LogText);
        ind := le.NEXT(ind);
      end loop;
    end if;
      end loop;
    
      -- Indicate that the job finished and detach from it.
      dbms_output.put_line('Job has completed');
      dbms_output.put_line('Final job state = ' \|\| job_state);
      dbms_datapump.detach(h1);
    END;

作業 4:使用 Oracle Data Pump (ImpDP) 建立目標資料庫

使用 Oracle Data Pump (ImpDP) 從來源資料庫匯出的 SRC_OCIGGLL.dmp,將資料匯入目標資料庫。

  1. 在您的目標資料庫中建立證明資料以存取 Oracle Object Store (使用前一節中的相同資訊)。

    BEGIN
      DBMS_CLOUD.CREATE_CREDENTIAL(
        credential_name => 'ADB_OBJECTSTORE',
        username => '<user-name>',
        password => '<token>'
      );
    END;
  2. 在目標資料庫中執行下列命令檔,以從 SRC_OCIGGLL.dmp 匯入資料。請確定已相應地取代物件存放區 URI 中的 <region><namespace><bucket-name>

    DECLARE
    ind NUMBER;  -- Loop index
    h1 NUMBER;  -- Data Pump job handle
    percent_done NUMBER;  -- Percentage of job complete
    job_state VARCHAR2(30);  -- To keep track of job state
    le ku$_LogEntry;  -- For WIP and error messages
    js ku$_JobStatus;  -- The job status from get_status
    jd ku$_JobDesc;  -- The job description from get_status
    sts ku$_Status;  -- The status object returned by get_status
    BEGIN
    
    -- Create a (user-named) Data Pump job to do a "full" import (everything
    -- in the dump file without filtering).
    h1 := DBMS_DATAPUMP.OPEN('IMPORT','FULL',NULL,'SRCMIRROR_OCIGGLL_IMPORT');
    
    -- Specify the single dump file for the job (using the handle just returned)
    -- and directory object, which must already be defined and accessible
    -- to the user running this procedure. This is the dump file created by
    -- the export operation in the first example.
    
    DBMS_DATAPUMP.ADD_FILE(h1,'https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket-name>/o/SRC_OCIGGLL.dmp','ADB_OBJECTSTORE',null,DBMS_DATAPUMP.KU$_FILE_TYPE_URIDUMP_FILE);
    
    -- A metadata remap will map all schema objects from SRC_OCIGGLL to SRCMIRROR_OCIGGLL.
    DBMS_DATAPUMP.METADATA_REMAP(h1,'REMAP_SCHEMA','SRC_OCIGGLL','SRCMIRROR_OCIGGLL');
    
    -- If a table already exists in the destination schema, skip it (leave
    
    -- the preexisting table alone). This is the default, but it does not hurt
    
    -- to specify it explicitly.
    DBMS_DATAPUMP.SET_PARAMETER(h1,'TABLE_EXISTS_ACTION','SKIP');
    
    -- Start the job. An exception is returned if something is not set up properly.
    DBMS_DATAPUMP.START_JOB(h1);
    
    -- The import job should now be running. In the following loop, the job is
    
    -- monitored until it completes. In the meantime, progress information is
    
    -- displayed. Note: this is identical to the export example.
    percent_done := 0;
    job_state := 'UNDEFINED';
    while (job_state != 'COMPLETED') and (job_state != 'STOPPED') loop
      dbms_datapump.get_status(h1,
        dbms_datapump.ku$_status_job_error +
        dbms_datapump.ku$_status_job_status +
        dbms_datapump.ku$_status_wip,-1,job_state,sts);
        js := sts.job_status;
    
      -- If the percentage done changed, display the new value.
      if js.percent_done != percent_done
      then
        dbms_output.put_line('*** Job percent done = ' \|\|
        to_char(js.percent_done));
        percent_done := js.percent_done;
      end if;
    
      -- If any work-in-progress (WIP) or Error messages were received for the job, display them.
      if (bitand(sts.mask,dbms_datapump.ku$_status_wip) != 0)
      then
        le := sts.wip;
      else
        if (bitand(sts.mask,dbms_datapump.ku$_status_job_error) != 0)
        then
          le := sts.error;
        else
          le := null;
        end if;
      end if;
      if le is not null
      then
        ind := le.FIRST;
        while ind is not null loop
          dbms_output.put_line(le(ind).LogText);
          ind := le.NEXT(ind);
        end loop;
      end if;
    end loop;
    
    -- Indicate that the job finished and gracefully detach from it.
    dbms_output.put_line('Job has completed');
    dbms_output.put_line('Final job state = ' \|\| job_state);
    dbms_datapump.detach(h1);
    END;

作業 5:新增並執行非整合式 Replicat

  1. 新增並執行 Replicat

    參數檔畫面上,使用下列指令碼取代 MAP *.*, TARGET *.*;

    -- Capture DDL operations for listed schema tables
    ddl include mapped
    
    -- Add step-by-step history of ddl operations captured
    -- to the report file. Very useful when troubleshooting.
    ddloptions report
    
    -- Write capture stats per table to the report file daily.
    report at 00:01
    
    -- Rollover the report file weekly. Useful when PR runs
    -- without being stopped/started for long periods of time to
    -- keep the report files from becoming too large.
    reportrollover at 00:01 on Sunday
    
    -- Report total operations captured, and operations per second
    -- every 10 minutes.
    reportcount every 10 minutes, rate
    
    -- Table map list for apply
    DBOPTIONS ENABLE_INSTANTIATION_FILTERING;
    MAP SRC_OCIGGLL.*, TARGET SRCMIRROR_OCIGGLL.*;

    注意:DBOPTIONS ENABLE_INSTANTIATION_FILTERING 會對使用 Oracle Data Pump 匯入的表格啟用 CSN 篩選。如需詳細資訊,請參閱 DBOPTIONS Reference

  2. 執行來源資料庫的插入:

    1. 返回 Oracle Cloud 主控台,然後使用導覽功能表返回 Oracle AI DatabaseAutonomous AI Transaction Processing ,然後瀏覽 SourceDB

    2. 在「SourceDB 詳細資訊」頁面上,選取資料庫動作,然後選取 SQL

    3. 輸入下列插入,然後選取執行命令檔

      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);
    4. 在 OCI GoldenGate 部署主控台中,選取擷取名稱 (UAEXT) ,然後選取統計資料。確認已列出 SRC_OCIGGLL.SRC_CITY 與 10 個插入。

    5. 回到「總覽」畫面,選取 Replicat 名稱 (REP) ,然後選取統計資料。確認已列出 SRCMIRROR_OCIGGLL.SRC_CITY 與 10 個插入

工作 6:建立資料轉換資源

  1. 建立資料轉換部署

  2. 建立一般連線

    注意:例如,對於美國東部 (阿什本) 的自治式 AI 資料庫,請使用下列值:

    • 主機中,輸入 adb.us-ashburn-1.oraclecloud.com:1522

    • 子網路中,從下拉式清單中選取與部署相同的子網路。

  3. 將一般連線指派給部署

  4. 在您的 Autonomous AI Lakehouse (ADW) 執行處理中,於 SRCMIRROR_OCIGGLL 建立 TRG_CUSTOMER:

    1. 在 Oracle Cloud 主控台中,開啟導覽功能表,導覽至 Oracle AI Database ,然後選取 Autonomous AI Lakehouse

    2. 自治式資料庫頁面上,選取 ADW 執行處理。

    3. 在「ADW 自治式 AI 資料庫詳細資訊」頁面上,選取資料庫動作,然後從下拉式清單中選取 SQL 。如果「資料庫」動作功能表載入時間過長,您可以直接選取「資料庫」動作,然後從「資料庫」動作頁面選取 SQL。

    4. 在「工作表」中輸入下列內容,然後選取執行陳述式

      create table SRCMIRROR_OCIGGLL.TRG_CUSTOMER (
         CUST_ID              NUMBER(10,0)     not null,
         DEAR                 VARCHAR2(4 BYTE),
         CUST_NAME            VARCHAR2(50 BYTE),
         ADDRESS              VARCHAR2(100 BYTE),
         CITY_ID              NUMBER(10,0),
         PHONE                VARCHAR2(50 BYTE),
         AGE                  NUMBER(3,0),
         AGE_RANGE            VARCHAR2(50 BYTE),
         SALES_PERS           VARCHAR2(50 BYTE),
         CRE_DATE             DATE,
         UPD_DATE             DATE,
         constraint PK_TRG_CUSTOMER primary key (CUST_ID)
      );
  5. 啟動「資料轉換」部署主控台:

    1. 回瀏覽至「部署」頁面,然後選取您在「任務 6」中建立的部署。

    2. 在「建置詳細資訊」頁面上,選取啟動主控台

    3. 登入「資料轉換」部署主控台。

  6. 建立 ADW 連線:

    1. 開啟導覽功能表,選取連線,然後選取建立連線

    2. 在「選取類型」頁面的「資料庫」下,選取 Oracle ,然後選取下一步

    3. 在「連線」詳細資訊頁面上,依下列方式完成表單欄位,然後選取建立

      1. 在「名稱」中輸入 ADW_IAD

      2. 選取使用證明資料檔案

      3. 若為「公事包檔案」,請上傳您的 (ADW) 公事包檔案。

        注意:若要下載 ADW 公事包檔案,請在 ADW 詳細資訊頁面選取資料庫連線

      4. 從「服務」下拉式清單中,選取 <name>_low

      5. 針對「使用者」,輸入 ADMIN

      6. 若為「密碼」,請輸入您的 ADW 密碼。

  7. 匯入資料實體 :

    1. 開啟導覽功能表,選取資料實體,然後選取匯入資料實體

    2. 若為「連線」,請從下拉式清單中選取 ADW_IAD

    3. 若為「綱要」,請從下拉式清單中選取 SRCMIRROR_OCIGGLL

    4. 選取開始

  8. 建立專案:{0}

    1. 開啟導覽功能表,選取專案

    2. 在「專案 (Projects)」頁面上,選取建立專案 (Create Project)

    3. 在「建立專案」對話方塊中,針對「名稱」,輸入 demo-pipeline ,然後選取建立

作業 7:建立與執行工作流程

  1. 建立資料流程:

    注意: 進一步瞭解資料流程編輯器

    1. 選取專案的名稱。

    2. 在「專案詳細資訊」頁面的「資源」下,選取資料流程,然後選取建立資料流程

    3. 在「建立資料流程」對話方塊中,針對「名稱」,輸入載入 TRG_CUSTOMER ,並選擇性地輸入描述。選取建立。即會開啟設計畫面。

    4. 在「新增綱要」對話方塊中,依下列方式完成表單欄位,然後選取確定

      1. 若為「連線」,請從下拉式清單中選取 ADW_IAD

      2. 若為「綱要」,請從下拉式清單中選取 SRCMIRROR_OCIGGLL

    5. 將下列資料實體和元件拖曳至設計工作區:

      1. 在「資料實體」面板中,展開 SRCMIRROR_OCIGGLL 綱要。將 SRC_AGE_GROUP 資料實體拖曳至設計畫面。

      2. 在「資料實體」面板中,展開 SRCMIRROR_OCIGGLL 綱要。將 SRC_SALES_PERSON 資料實體拖曳至設計畫面。

      3. 從「資料轉換」工具列,將查詢元件拖曳至設計工作區。

      4. 從「資料轉換」工具列,將結合元件拖曳至設計工作區。

      5. 在「資料實體」面板的 SRCMIRROR_OCIGGLL 下,將 SRC_CUSTOMER 資料實體拖曳至設計工作區。

    6. 將下列資料實體連線至查尋元件:

      1. 選取 SRC_AGE_GROUP 「連線器」圖示,然後將圖示拖曳至查詢元件。

      2. 選取 SRC_CUSTOMER 「連線器」圖示,然後將圖示拖曳至查詢元件。

    7. 在設計畫面上,選取查尋以開啟「查尋」面板。在「查閱」面板中,切換至屬性頁籤,然後將下列查詢貼至查閱條件

      SRC_CUSTOMER.AGE between SRC_AGE_GROUP.AGE_MIN and SRC_AGE_GROUP.AGE_MAX
    8. 將下列元件連線至結合元件:

      1. 選取 SRC_SALES_PERSON 連線器圖示,然後將圖示拖曳至結合元件。

      2. 查詢連線器圖示上選取,然後將圖示拖曳至結合元件。

    9. 在設計工作區上,選取結合以開啟「結合」面板。在「結合」面板中,切換至屬性頁籤,然後將下列查詢貼到結合條件中:

      SRC_CUSTOMER.SALES_PERS_ID=SRC_SALES_PERSON.SALES_PERS_ID
    10. 將下列資料實體和元件拖曳至設計畫面:

      1. 在「資料實體」面板的 SRCMIRROR_OCIGGLL 下,將 TRG_CUSTOMER 資料實體拖曳至設計工作區。

      2. 選取結合連線器圖示,然後將圖示拖曳至 TRG_CUSTOMER 資料實體。

      3. 在設計畫面上,選取 TRG_CUSTOMER 並展開資料實體。

    11. 屬性頁籤上,啟用 CUST_ID 的索引鍵,並停用 CRE_DATE 的「更新」,並停用 UPD_DATE 的「插入」。

    12. 資料欄對應頁籤上,確定「名稱」與「表示式」相符:

      1. 客戶 ID

        SRC_CUSTOMER.CUSTID
      2. 特別

        CASE WHEN SRC_CUSTOMER.DEAR = 0 THEN 'Mr' WHEN SRC_CUSTOMER.DEAR = 1 THEN 'Mrs' ELSE 'Ms' END
      3. 客戶名稱

        SRC_CUSTOMER.FIRST_NAME \|\| ' ' \|\| UPPER(SRC_CUSTOMER.LAST_NAME)
      4. 銷售人員

        SRC_SALES_PERSON.FIRST_NAME \|\| ' ' \|\|UPPER(SRC_SALES_PERSON.LAST_NAME)
      5. 建立日期 (_D)

        SYSDATE
      6. 更新日期

        SYSDATE
      7. 依原樣使用其他對應。

    13. 選項頁籤上,針對「模式」,從下拉式清單中選取增量更新

    14. 收合 TRG_CUSTOMER

    15. 選取儲存資料流程

  2. 建立工作流程:

    1. 選取專案的名稱,選取工作流程,然後選取建立工作流程

    2. 針對名稱,輸入協調資料倉儲載入。選取建立

    3. 拖曳設計工作區上的 SQL 圖示。

    4. 按兩下編輯器中的 SQL 步驟以開啟步驟特性頁面。

    5. 一般頁籤中,輸入資料清除作為名稱。

    6. 選取屬性頁籤,針對「連線」,從下拉式清單中選取 ADW_IAD

    7. 若為 SQL,請複製下列查詢:

      delete from SRCMIRROR_OCIGGLL.TRG_CUSTOMER where CITY_ID > 110
    8. 收合 SQL

    9. 在「資料流程」底下,將 TRG_CUSTOMER 資料流程拖曳至設計畫面。

    10. 資料清除 SQL 工作流程行中選取,然後將確定 (綠色箭號) 圖示拖曳至 TRG_CUSTOMER 資料流程。

    11. 選取儲存工作流程,然後選取啟動工作流程

  3. 建立及管理工作