Configura la replica bidirezionale tra due database cloud nella stessa area

Dopo aver impostato la replica unidirezionale, sono disponibili solo alcuni passaggi aggiuntivi per replicare i dati nella direzione opposta. Questo esempio di avvio rapido utilizza Autonomous Transaction Processing e Autonomous Data Warehouse come due database cloud.

Informazioni preliminari

Per procedere con questo avvio rapido, è necessario disporre di due database esistenti nella stessa tenancy e nella stessa area. Se sono necessari dati di esempio, scaricare Archive.zip, quindi seguire le istruzioni riportate in Lab 1, Task 3: Carica lo schema ATP.

Panoramica

I passi riportati di seguito illustrano come creare un'istanza di un database di destinazione utilizzando Oracle Data Pump e impostare la replica bidirezionale (a due vie) tra due database nella stessa area.

Descrizione di bidirectional.png:
Descrizione dell'immagine bidirectional.png

Task 1: Impostare l'ambiente

  1. Creare una distribuzione.
  2. Creare le connessioni ai database.
  3. Assegnare le connessioni alla distribuzione.
  4. Abilita il log supplementare:
    ALTER DATABASE ADD SUPPLEMENTAL LOG DATA
  5. Eseguire la query seguente per assicurarsi che support_mode=FULL per tutte le tabelle nel database di origine:
    
    select * from DBA_GOLDENGATE_SUPPORT_MODE where owner = 'SRC_OCIGGLL';
  6. Eseguire la query seguente sul database B per assicurarsi che support_mode=FULL per tutte le tabelle del database:
    select * from DBA_GOLDENGATE_SUPPORT_MODE where owner = 'SRCMIRROR_OCIGGLL';

Task 2: aggiungere informazioni sulle transazioni e una tabella di checkpoint per entrambi i database

Nella console di distribuzione GoldenGate OCI, andare alla schermata Configurazione del servizio di amministrazione, quindi completare le operazioni riportate di seguito.

  1. Aggiungere le informazioni sulle transazioni nei database A e B:
    1. Per il database A, immettere SRC_OCIGGLL per il nome dello schema.
    2. Per il database B, immettere SRCMIRROR_OCIGGLL per il nome dello schema.
    Nota

    I nomi degli schemi devono essere univoci e corrispondere ai nomi degli schemi di database se si utilizza un set di dati diverso da questo esempio.
  2. Creare una tabella di checkpoint per il database A e B:
    1. Per il database A, immettere "SRC_OCIGGLL"."ATP_CHECKTABLE" per la tabella di checkpoint.
    2. Per il database B, immettere "SRCMIRROR_OCIGGLL"."CHECKTABLE"per la tabella di checkpoint.

Task 3: 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. Aggiungere ed eseguire un'estrazione integrata.
    Nota

    Per ulteriori informazioni sui parametri che è possibile utilizzare per specificare le tabelle di origine, vedere Opzioni aggiuntive dei parametri di estrazione.
    1. Nella pagina Parametri estrazione aggiungere le righe seguenti in EXTTRAIL <extract-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.*;
      
      -- Exclude changes made by GGADMIN
      tranlogoptions excludeuser ggadmin
    Nota

    tranlogoptions excludeuser ggadmin evita il recupero delle transazioni applicate da ggadmin negli scenari di replica bidirezionale.
  3. Controlla transazioni a esecuzione lunga:
    1. 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 4: 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 5: 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 da 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 6: aggiungere ed eseguire un Replicat non integrato

  1. Aggiungere ed eseguire un Replicat.
    1. Nella schermata File dei parametri, sostituire MAP *.*, TARGET *.*; con lo script seguente:
      -- 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 mediante Oracle Data Pump. Per ulteriori informazioni, consulta il riferimento DBOPTIONS.
  2. Eseguire alcune modifiche sul database A per visualizzarle replicate nel database B.

Task 7: configurare la replica dal database B al database A

I task da 1 a 6 hanno stabilito la replica dal database A al database B. I passi riportati di seguito consentono di impostare la replica dal database B al database A.

  1. Aggiungere ed eseguire un'estrazione sul database B. Nella pagina dei parametri di estrazione dopo EXTRAIL <extract-name>, assicurarsi di includere:
    -- Table list for capture
    table SRCMIRROR_OCIGGLL.*;
    
    -- Exclude changes made by GGADMIN
    tranlogoptions excludeuser ggadmin
  2. Aggiungere ed eseguire un Replicat al database A. Nella pagina Parametri, sostituire MAP *.*, TARGET *.*; con:
    MAP SRCMIRROR_OCIGGLL.*, TARGET SRC_OCIGGLL.*;
  3. Eseguire alcune modifiche sul database B per visualizzarle replicate nel database A.

Task 8: Monitorare e gestire i processi