Replicare i dati tra database cloud nella stessa area

Scopri come impostare Oracle Cloud Infrastructure GoldenGate per replicare i dati tra due database autonomi.

Panoramica

Oracle Cloud Infrastructure GoldenGate ti consente di replicare i database supportati all'interno della stessa area. I passi riportati di seguito illustrano come creare un'istanza di un database di destinazione utilizzando Oracle Data Pump e replicare i dati dall'origine alla destinazione.

Questa Quickstart è disponibile anche come LiveLab: Visualizza il workshop.

Segue la descrizione dello stesso-region.png
Descrizione dell'immagine same-region.png

Prima di iniziare

Per continuare, è necessario disporre dei seguenti elementi:

Task 1: Impostare l'ambiente

  1. Creare una distribuzione di Data Replication.
  2. Creare una connessione ATP (Oracle Autonomous Transaction Processing) di origine.
  3. Creare una connessione ADW (Autonomous Data Warehouse) di destinazione.
  4. Assegnare una connessione alla distribuzione.
  5. Utilizzare lo strumento SQL di Autonomous Database per abilitare il log supplementare:
    ALTER DATABASE ADD SUPPLEMENTAL LOG DATA
  6. Eseguire la query seguente nello strumento SQL per assicurarsi che support_mode=FULL per tutte le tabelle nel database di origine:
    
    select * from DBA_GOLDENGATE_SUPPORT_MODE where owner = 'SRC_OCIGGLL';

Task 2: Creare l'estrazione integrata

Un'estrazione integrata acquisisce le modifiche in corso al database di origine.

  1. Nella pagina Dettagli distribuzione, fare clic su Avvia console.
  2. Se necessario, immettere oggadmin per il nome utente e la password utilizzati durante la creazione della distribuzione, quindi fare clic su Accedi.
  3. Aggiungi dati transazione e una tabella checkpoint:
    1. Aprire il menu di navigazione, quindi fare clic su Connessioni al database.
    2. Fare clic su Connetti al database SourceATP.
    3. Nel menu di navigazione, fare clic su Trandata, quindi su Aggiungi trandata (icona più).
    4. Per Nome schema, immettere SRC_OCIGGLL, quindi fare clic su Sottometti.
    5. Per verificare, immettere SRC_OCIGGLL nel campo Cerca e fare clic su Cerca.
    6. Aprire il menu di navigazione, quindi fare clic su Connessioni al database.
    7. Fare clic su Connetti al database TargetADW.
    8. Nel menu di navigazione, fare clic su Checkpoint, quindi su Aggiungi checkpoint (icona più).
    9. Per Tabella checkpoint, immettere "SRCMIRROR_OCIGGLL"."CHECKTABLE", quindi fare clic su Sottometti.
  4. Aggiungere un'estrazione.

    Nota

    Per ulteriori informazioni sui parametri che è possibile utilizzare per specificare le tabelle di origine, vedere opzioni aggiuntive dei parametri di estrazione.
    Nella pagina Parametri estrazione aggiungere le righe seguenti in 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. Verifica la presenza di transazioni con tempi di esecuzione lunghi. Eseguire il seguente script nel database di origine:
    select start_scn, start_time from gv$transaction where start_scn < (select max(start_scn) from dba_capture);

    Se la query restituisce righe, è necessario individuare l'SCN della transazione, quindi eseguire il commit o il rollback della transazione.

Task 3: Esportare i dati utilizzando Oracle Data Pump (ExpDP)

Utilizzare Oracle Data Pump (ExpDP) per esportare i dati dal database di origine nell'area di memorizzazione degli oggetti Oracle.

  1. Creare un bucket dell'area di memorizzazione degli oggetti Oracle.

    Prendere nota dello spazio di nomi e del nome del bucket da utilizzare con gli script di esportazione e importazione.

  2. Creare un token di autenticazione, quindi copiare e incollare la stringa di token in un editor di testo per utilizzarla in un secondo momento.
  3. Creare una credenziale nel database di origine, sostituendo <user-name> e <token> con il nome utente dell'account Oracle Cloud e la stringa di token creata nel passo precedente:
    BEGIN
      DBMS_CLOUD.CREATE_CREDENTIAL(
        credential_name => 'ADB_OBJECTSTORE', 
        username => '<user-name>',
        password => '<token>'
      );
    END;
  4. Eseguire il seguente script nel database di origine per creare il job Esporta dati. Assicurarsi di sostituire di conseguenza <region>, <namespace> e <bucket-name> nell'URI dell'area di memorizzazione degli oggetti. SRC_OCIGGLL.dmp è un file che verrà creato quando viene eseguito questo script.
    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;

Task 4: creare un'istanza del database di destinazione utilizzando Oracle Data Pump (ImpDP)

Utilizzare Oracle Data Pump (ImpDP) per importare i dati nel database di destinazione dal database SRC_OCIGGLL.dmp esportato dal database di origine.

  1. Creare una credenziale nel database di destinazione per accedere all'area di memorizzazione degli oggetti Oracle (utilizzando le stesse informazioni nella sezione precedente).
    BEGIN
      DBMS_CLOUD.CREATE_CREDENTIAL( 
        credential_name => 'ADB_OBJECTSTORE',
        username => '<user-name>',
        password => '<token>'
      );
    END;
  2. Eseguire il seguente script nel database di destinazione per importare i dati dal file SRC_OCIGGLL.dmp. Assicurarsi di sostituire di conseguenza <region>, <namespace> e <bucket-name> nell'URI dell'area di memorizzazione degli oggetti:
    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;

Task 5: aggiungere ed eseguire un Replicat non integrato

  1. Aggiungere ed eseguire un Replicat.
    Nella schermata File dei parametri, sostituire MAP *.*, TARGET *.*; con il seguente script:
    -- 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.*;

    Nota

    DBOPTIONS ENABLE_INSTATIATION_FILTERING abilita il filtro CSN sulle tabelle importate utilizzando Oracle Data Pump. Per ulteriori informazioni, consulta il riferimento DBOPTIONS.
  2. Eseguire gli inserimenti nel database di origine:
    1. Tornare alla console di Oracle Cloud e utilizzare il menu di navigazione per tornare a Oracle Database, Autonomous Transaction Processing e quindi a SourceATP.
    2. Nella pagina Dettagli ATP di origine, fare clic su Strumenti, quindi su Azioni database.
    3. Utilizzare le credenziali del database ATP di origine nei dettagli del workshop per eseguire il login a Database Actions, quindi fare clic su SQL.
    4. Immettere i seguenti inserimenti, quindi fare clic su Esegui script:
      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);
    5. Nella console di distribuzione GoldenGate OCI, fare clic su Nome estrazione (UAEXT), quindi su Statistiche. Verificare che SRC_OCIGGLL.SRC_CITY sia elencato con 10 inserimenti.
    6. Tornare alla schermata Panoramica, fare clic su Nome Replicat (REP), quindi su Statistiche. Verificare che SRCMIRROR_OCIGGLL.SRC_CITY sia elencato con 10 inserimenti

Task 6: Monitorare e mantenere i processi

  1. Monitorare il processo di replica.
  2. Gestisci file trail.