Replicação de dados - GoldenGate
Autor: Mario Barduchi | Publicado: 2016-11-04T15:09:00-02:00


Olá pessoal, como &nbsp;estão?



Espero que todos estejam muito bem.



Eu já publiquei uma série de artigos de GoldenGate a algum tempo atrás -&nbsp;Parte 1,&nbsp;Parte 2,&nbsp;Parte 3&nbsp;e&nbsp;Parte 4.



Só que lá, confesso, o texto ficou um pouco grande e também muito pulverizado.&nbsp;



Outro ponto é que a instalação era feita via linha de comando, enfim, chegou o momento de fazer algo mais direto.



Não vou detalhar comando a comando, acho desnecessário.&nbsp;

Mas os nomes e processos são bem intuitivos, então basta dar uma olhada nos manuais&nbsp;aqui&nbsp;que você será feliz, tenho certeza.


Vamos começar.


====================================================================

-- Versões e downloads

====================================================================

- Sistema Operacional: Oracle Linux 6.5

- Bases de dados: GGPRD e GGCOPY
- Versão do Oracle: 11.2.0.4

- Versão do GG:&nbsp;12.2.0.1.1

- Usuário do GG: dbagate &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Senha: aaa123

- Usuário a ser replicado: SCOTT &nbsp; Senha: aaa123

- Download do GG:&nbsp;Aqui



Nosso instalador, ficará nesse local:&nbsp;/home/oracle/GoldenGate





====================================================================

-- Instalação do GG (SOURCE e TARGET)

====================================================================

1) Criar o GG_HOME.


&nbsp; &nbsp; mkdir -p /oracle/app/oracle/product/11.2.0/gghome



2) Descompactar o instalador e iniciar a instalação




&nbsp; &nbsp; cd /home/oracle/GoldenGate&nbsp;

&nbsp; &nbsp; unzip fbo_ggs_Linux_x64_shiphome.zip



&nbsp; &nbsp; cd /home/oracle/GoldenGate/fbo_ggs_Linux_x64_shiphome/Disk1

    ./runInstaller




Abaixo a sequência de telas da instalação:

















 



3) Adicionar o GG_HOME ao bash_profile



&nbsp; &nbsp; cd ~

&nbsp; &nbsp; vi .bash_profile

&nbsp; &nbsp; GG_HOME=/oracle/app/oracle/product/11.2.0/gghome&nbsp;



4) Agora é só testar a instalação

&nbsp; &nbsp; &nbsp;

&nbsp; &nbsp; cd $GG_HOME

&nbsp; &nbsp; ./ggsci



&nbsp; &nbsp;Oracle GoldenGate Command Interpreter for Oracle



&nbsp; &nbsp;Version 12.2.0.1.1 OGGCORE_12.2.0.1.0_PLATFORMS_151211.1401_FBO

&nbsp; &nbsp;Linux, x64, 64bit (optimized), Oracle 12c on Dec 12 2015 02:56:48

&nbsp; &nbsp;Operating system character set identified as UTF-8.

&nbsp; &nbsp;Copyright (C) 1995, 2015, Oracle and/or its affiliates. All&nbsp;
&nbsp; &nbsp;rights reserved.



&nbsp; &nbsp;GGSCI (rac12c1) 2&gt; info all

&nbsp; &nbsp;Program &nbsp; &nbsp;Status &nbsp; &nbsp; &nbsp;Group &nbsp; &nbsp; &nbsp; Lag at Chkpt &nbsp;Time Since Chkpt

&nbsp; &nbsp;MANAGER &nbsp; &nbsp;RUNNING

&nbsp; &nbsp; &nbsp;

5) Caso seja necessário, alterar a porta do manager



&nbsp; &nbsp; GGSCI (rac12c1) 3&gt;&nbsp;stop manager

&nbsp; &nbsp; edit params mgr

        PORT 7889

&nbsp; &nbsp; start manager



====================================================================

-- Preparação das bases (SOURCE e TARGET)

====================================================================



1) Pré-requisitos que devem ser configurados



&nbsp; &nbsp;ALTER DATABASE FORCE LOGGING;
&nbsp; &nbsp;ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;

&nbsp; &nbsp;ALTER SYSTEM SET ENABLE_GOLDENGATE_REPLICATION=TRUE&nbsp;SCOPE=SPFILE;
&nbsp; &nbsp;ALTER SYSTEM SET RECYCLEBIN=OFF SCOPE=SPFILE;
&nbsp; &nbsp;ALTER SYSTEM SET STREAMS_POOL_SIZE=256M SCOPE=SPFILE;
&nbsp; &nbsp;SHUTDOWN IMMEDIATE;
&nbsp; &nbsp;STARTUP;




&nbsp; &nbsp;SELECT SUPPLEMENTAL_LOG_DATA_MIN,LOG_MODE FROM V$DATABASE;



Importante: as bases devem estar em modo Archive.

 


2) Criar user, tablespace para o GG e liberar os grant's


     -- GGPRD 
    CREATE TABLESPACE GGATE 
        datafile '/u01/oradata/ggprd/ggate01.dbf' 
 SIZE 1G AUTOEXTEND on NEXT 512M maxsize 8G;

    -- GGCOPY
    CREATE TABLESPACE GGATE 
 datafile '/u01/oradata/ggcopy/ggate01.dbf' 
 SIZE 1G AUTOEXTEND on NEXT 512M maxsize 8G;
 
    CREATE USER DBAGATE IDENTIFIED BY aaa123 DEFAULT TABLESPACE GGATE TEMPORARY TABLESPACE TEMP;
    GRANT CONNECT, RESOURCE, UNLIMITED TABLESPACE TO DBAGATE;
    GRANT EXECUTE ON UTL_FILE TO DBAGATE;
    GRANT DBA TO dbagate;
    GRANT SELECT ANY DICTIONARY TO dbagate;
    GRANT EXECUTE ON dbms_flashback TO dbagate;&nbsp;

 

3) Criar a estrutura interna do GG. Para isso, devemos estar&nbsp;no diretório do HOME_GATE


&nbsp; &nbsp; cd $GGHOME



&nbsp; &nbsp; @marker_setup.sql

        Enter Oracle GoldenGate schema name: dbagate



&nbsp; &nbsp; @ddl_setup.sql

        Enter Oracle GoldenGate schema name: dbagate



&nbsp; &nbsp; @role_setup.sql

        Enter GoldenGate schema name: dbagate



    Liberar o GRANT para o user do GG



        GRANT GGS_GGSUSER_ROLE TO dbagate



&nbsp; &nbsp; @ddl_enable.sql

4) Criar os diretórios
 
&nbsp; &nbsp; ./ggsci

&nbsp; &nbsp;&nbsp;GGSCI (rac12c1) 4&gt;&nbsp;create subdirs

5) Preparando a tabela de checkpoint e registrando as informações do schema a ser replicado 

&nbsp; &nbsp;&nbsp;GGSCI (rac12c1) 5&gt;&nbsp;EDIT PARAMS ./GLOBALS
&nbsp; &nbsp;&nbsp;GGSCI (rac12c1) 6&gt;&nbsp;GGSCHEMA DBAGATE
&nbsp; &nbsp;&nbsp;GGSCI (rac12c1) 7&gt;&nbsp;CHECKPOINTTABLE DBAGATE.checkpoint

&nbsp; &nbsp; -- Precisamos estar logados com o dbagate nesse ponto
&nbsp; &nbsp;&nbsp;GGSCI (rac12c1) 8&gt;&nbsp;DBLOGIN USERID dbagate, PASSWORD aaa123

&nbsp; &nbsp;&nbsp;GGSCI (rac12c1) 9&gt; &nbsp;ADD CHECKPOINTTABLE dbagate.checkpoint

&nbsp; &nbsp;&nbsp;GGSCI (rac12c1) 10&gt;&nbsp;ADD SCHEMATRANDATA scott ALLCOLS

============================================================
Somente no source
=============================================================



1) Configurar o extract. Ele é responsável pela extração dos dados que serão replicados e vai gerar os trailfiles localmente.



&nbsp; &nbsp;&nbsp;GGSCI (rac12c1) 1&gt;&nbsp;dblogin userid dbagate, password aaa123

&nbsp; &nbsp;&nbsp;

&nbsp; &nbsp;&nbsp;GGSCI (rac12c1) 2&gt;&nbsp;add extract extract1, tranlog, begin now



&nbsp; &nbsp;&nbsp;GGSCI (rac12c1) 3&gt;&nbsp;

&nbsp; &nbsp; add exttrail&nbsp;/oracle/app/oracle/product/11.2.0/gghome/dirdat/lt, extract&nbsp;extract1, megabytes 50



&nbsp; &nbsp;&nbsp;GGSCI (rac12c1) 4&gt;&nbsp;

&nbsp; &nbsp; add rmttrail&nbsp;/oracle/app/oracle/product/11.2.0/gghome/dirdat/rt, extract&nbsp;extract1, megabytes 50

&nbsp; &nbsp;&nbsp;

&nbsp; &nbsp;&nbsp;GGSCI (rac12c1) 5&gt;&nbsp;edit params extract1

&nbsp; &nbsp;&nbsp;extract extract1

&nbsp; &nbsp; userid dbagate@GGPRD, password aaa123

&nbsp; &nbsp; EXTTRAIL /oracle/app/oracle/product/11.2.0/gghome/dirdat/lt

&nbsp; &nbsp; TRANLOGOPTIONS EXCLUDEUSER DBAGATE

&nbsp; &nbsp; GETTRUNCATES

&nbsp; &nbsp; ddl include mapped objname scott.*;

&nbsp; &nbsp; table SCOTT.*;




&nbsp; &nbsp;&nbsp;GGSCI (rac12c1) 6&gt;&nbsp;info extract extract1, detail



2) Configurar o datapump. Ele é responsável pela envio dos trailfiles para o servidor remoto.

&nbsp; &nbsp;&nbsp;GGSCI (rac12c1) 7&gt;&nbsp;ADD EXTRACT dtpump1, EXTTRAILSOURCE /oracle/app/oracle/product/11.2.0/gghome/dirdat/lt, BEGIN now

&nbsp; &nbsp; GGSCI (rac12c1) 8&gt;&nbsp;
&nbsp; &nbsp; ADD RMTTRAIL /oracle/app/oracle/product/11.2.0/gghome/dirdat/rt, EXTRACT dtpump1, megabytes 50
 
&nbsp; &nbsp; GGSCI (rac12c1) 9&gt;&nbsp;edit params dtpump1
&nbsp; &nbsp; EXTRACT dtpump1
&nbsp; &nbsp; RMTHOST 192.168.1.32, mgrport 7809
&nbsp; &nbsp; RMTTRAIL /oracle/app/oracle/product/11.2.0/gghome/dirdat/rt
&nbsp; &nbsp; PASSTHRU
&nbsp; &nbsp; GETTRUNCATES
&nbsp; &nbsp; TABLE SCOTT.*;


&nbsp; &nbsp; GGSCI (rac12c1) 10&gt; info all

============================================================
Somente no target
=============================================================
1) Adicionar o replicat

&nbsp; &nbsp;&nbsp;./ggsci
&nbsp; &nbsp;&nbsp;
&nbsp; &nbsp;&nbsp;GGSCI (rac12c2) 1&gt;&nbsp;dblogin userid dbagate; password aaa123

&nbsp; &nbsp;&nbsp;GGSCI (rac12c2) 2&gt;&nbsp;add replicat replic1, exttrail /oracle/app/oracle/product/11.2.0/gghome/dirdat/rt, begin now, CHECKPOINTTABLE dbagate.checkpoint,&nbsp;

&nbsp; &nbsp;&nbsp;GGSCI (rac12c2) 3&gt;&nbsp;edit params replic1
&nbsp; &nbsp; REPLICAT replic1
&nbsp; &nbsp; ASSUMETARGETDEFS
&nbsp; &nbsp; GETTRUNCATES
&nbsp; &nbsp; HANDLECOLLISIONS
&nbsp; &nbsp; USERID dbagate, PASSWORD aaa123
&nbsp; &nbsp; discardfile /oracle/app/oracle/product/11.2.0/gghome/dircrd/replic1_discard.txt, append, megabytes 50
&nbsp; &nbsp; MAP SCOTT.*, TARGET SCOTT.*;
&nbsp; &nbsp; DDL INCLUDE ALL
&nbsp; &nbsp; DDLERROR DEFAULT IGNORE RETRYOP MAXRETRIES 10 RETRYDELAY 30&nbsp;
  

&nbsp; &nbsp;&nbsp;GGSCI (rac12c2) 4&gt;&nbsp;info all

============================================================
Iniciar os serviços do SOURCE
=============================================================

&nbsp; &nbsp;&nbsp;./ggsci

&nbsp; &nbsp; GGSCI (rac12c1) 1&gt;&nbsp;dblogin userid dbagate; password aaa123




&nbsp; &nbsp; GGSCI (rac12c1) 2&gt;&nbsp;start er *

&nbsp; &nbsp; GGSCI (rac12c1) 3&gt;&nbsp;info all

&nbsp; &nbsp; GGSCI (rac12c1) 4&gt;&nbsp;info extract extract1, detail

&nbsp; &nbsp; GGSCI (rac12c1) 5&gt;&nbsp;info extract dtpump1, detail


&nbsp; &nbsp; GGSCI (rac12c1) 6&gt;&nbsp;stats extract extract1

============================================================
Migrar o schema do source para o target - INITIAL LOAD
=============================================================

Nesse ponto iremos executar a carga inicial (INITIAL LOAD) no target.&nbsp;

Essa etapa pode ser feita de várias formas. Poderíamos somente criar a estrutura de tabelas no target e fazer um INITIAL LOAD via GoldenGate mesmo. Ou fazer via EXPDP/IMPDP.

Eu prefiro sempre fazer via EXPDP/IMPDP. Então é essa forma que vamos utilizar.

1) Identificando o scn

&nbsp; &nbsp; SELECT TO_CHAR(CURRENT_SCN) FROM V$DATABASE; 
 
&nbsp; &nbsp; No nosso exemplo, o SCN sera esse:&nbsp;970349
 
2) Executar o EXPDP com FLASHBACK_SCN no source

&nbsp; &nbsp; expdp \"/ as sysdba\" directory=EXPDP_DIR DUMPFILE=SCOTT_%U.dmp LOGFILE=scott.log owner=scott filesize=8192m &nbsp;FLASHBACK_SCN=970349



3) Realizar o IMPDP no target
&nbsp; &nbsp; impdp \"/ as sysdba\" directory=EXPDP_DIR dumpfile=SCOTT_1.dmp logfile=impdp.log SCHEMAS='SCOTT'

============================================================
Somente no target
=============================================================
1) Iniciar o replicat. Esse processo é o responsável por ler e aplicar os trailfiles enviados pelo processo datapump do source.

&nbsp; &nbsp; ./ggsci

&nbsp; &nbsp; GGSCI (rac12c2) 1&gt;&nbsp;dblogin userid dbagate; password aaa123

&nbsp; &nbsp; GGSCI (rac12c2) 2&gt;&nbsp;start er *

&nbsp; &nbsp; Importante:
&nbsp; &nbsp; Caso queira iniciar a partir do SCN (eu acho mais seguro)

&nbsp; &nbsp;&nbsp;GGSCI (rac12c2) 2&gt;&nbsp;start replicat replic1, ATCSN 970349

&nbsp; &nbsp; GGSCI (rac12c2) 3&gt;&nbsp;info all

&nbsp; &nbsp; GGSCI (rac12c2) 4&gt;&nbsp;info replicat replic1, detail


&nbsp; &nbsp; GGSCI (rac12c2) 5&gt;&nbsp;stats REPLICAT replic1, total, hourly, reportrate min &nbsp; &nbsp;

Agora meus queridos, basta executar os testes na origem e ver a mágica acontecer no destino.

Lembre-se que esse é um cenário simples, porém um cenário maior acaba seguindo os mesmos passos. Consulte o manual, são opções diversas para replicação.

Espero que gostem.

Abraço
Mario