尋找 OCI GoldenGate 資料轉換

瞭解如何搭配使用 OCI GoldenGate 資料複製和資料轉型部署,以在兩個自治式資料庫之間載入和轉換資料。

開始之前

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

  • 載入範例資料並啟用補充日誌記錄的來源 Autonomous Database。

    秘訣:

    如果您需要使用範例資料,可以下載 OCI GoldenGate 範例資料
    • 使用 Autonomous Database 的資料庫動作 SQL 工具執行兩個命令檔來建立使用者綱要和表格。
    • 使用 SQL 工具啟用補充日誌記錄。
    請遵循實驗室 1、作業 3:載入可承諾量綱要中的步驟以取得更多明細。
  • 解除鎖定來源 Autonomous Database 執行處理的 GGADMIN 使用者
    1. 在 Autonomous Database 詳細資訊頁面上,從資料庫動作功能表選取資料庫使用者

      秘訣:

      如果出現提示,請使用在您建立要登入的執行處理時所提供的 Autonomous Database 管理員證明資料。
    2. 尋找 GGADMIN 使用者,然後從其省略符號 (三個點) 功能表中選取編輯
    3. 在「編輯使用者」面板中,輸入密碼並確認該密碼,然後取消選取帳戶已鎖定
    4. 按一下套用變更

作業 1:設定環境

  1. 建立資料複製部署
  2. 建立來源 Oracle Autonomous Transaction Processing (ATP) 連線
  3. 建立目標 Autonomous Data Warehouse (ADW) 連線
  4. 指定部署連線
  5. 使用 Autonomous Database 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. 開啟導覽功能表,然後按一下 DB 連線
    2. 按一下連接資料庫 SourceATP
    3. 在導覽功能表中,按一下 Trandata ,然後按一下 Add Trandata (加號圖示)。
    4. 對於結構名稱,輸入 SRC_OCIGGLL,然後按一下提交
    5. 若要驗證,請在「搜尋」欄位中輸入 SRC_OCIGGLL,然後按一下搜尋
    6. 開啟導覽功能表,然後按一下 DB 連線
    7. 按一下連接資料庫 TargetADW
    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_INSTATIATION_FILTERING 可對使用 Oracle Data Pump 匯入的表格啟用 CSN 篩選。如需詳細資訊,請參閱 DBOPTIONS Reference
  2. 執行來源資料庫的插入:
    1. 返回 Oracle Cloud 主控台,然後使用導覽功能表返回 Oracle DatabaseAutonomous Transaction Processing ,然後瀏覽 SourceATP
    2. 在「來源可承諾量明細」頁面上,按一下資料庫動作,然後按一下 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. 建立一般連線

    附註:

    例如,針對美國東部 (阿什本) 的自治式資料庫,請使用下列值:
    • 主機中,輸入 adb.us-ashburn-1.oraclecloud.com:1522
    • 子網路中,從下拉式清單中選取與部署相同的子網路。
  3. 將一般連線指派給部署
  4. 在 SRCMIRROR_OCIGGLL 的 Autonomous Data Warehouse (ADW) 執行處理中建立 TRG_CUSTOMER:
    1. 在 Oracle Cloud 主控台中,開啟導覽功能表,導覽至 Oracle Database ,然後選取 Autonomous Data Warehouse
    2. 在「自治式資料庫」頁上,按一下您的 ADW 執行處理。
    3. 在「ADW Autonomous Database 詳細資訊」頁面上,按一下資料庫動作,然後從下拉式清單中選取 SQL 。如果「資料庫」動作功能表載入的時間過長,您可以直接按一下「資料庫 (Database)」動作,然後從「資料庫動作 (Database Actions)」頁面選取 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. 建立專案
    1. 開啟導覽功能表,按一下專案
    2. 在「專案」頁面上,按一下建立專案
    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. CUST_ID
        SRC_CUSTOMER.CUSTID
      2. 特大
        CASE WHEN SRC_CUSTOMER.DEAR = 0 THEN 'Mr' WHEN SRC_CUSTOMER.DEAR = 1 THEN 'Mrs' ELSE 'Ms' END
      3. CUST_NAME
        SRC_CUSTOMER.FIRST_NAME || ' ' || UPPER(SRC_CUSTOMER.LAST_NAME)
      4. SALES_PERS
        SRC_SALES_PERSON.FIRST_NAME || ' ' ||UPPER(SRC_SALES_PERSON.LAST_NAME)
      5. CRE_DATE
        SYSDATE
      6. UPD_DATE
        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. 建立及管理工作