Oracle GoldenGate 12.3.0.1.4 in Oracle 12.2 之06(Initial Load)

1.disable 外键 和 check约束 在初始化数据前 (备库)

[oracle@xag131 ~]$ sql xag/123456@xag131:1521/pdb1

SQL> SET SQLFORMAT ansiconsole

SQL> set serveroutput on size 1000000 

--disable foreign key and check constraints before initial load 
 declare v_sql_stmt varchar2(4000);
 BEGIN 
 FOR c IN 
 (
   SELECT c.owner, c.table_name, c.constraint_name FROM user_constraints c, user_tables t WHERE t.table_name in ( upper('my_healt_check') ) 
   AND c.table_name = t.table_name AND c.constraint_type!='P' AND c.status = 'ENABLED' ORDER BY c.constraint_type DESC
  ) 
 LOOP 
 v_sql_stmt :='alter table "' || c.owner || '"."' || c.table_name || '" disable constraint ' || c.constraint_name;
 DBMS_OUTPUT.PUT_LINE(v_sql_stmt || ';'); 
 dbms_utility.exec_ddl_statement(v_sql_stmt); 
 END LOOP; 
 END; 
 /

alter table "XAG"."MY_HEALT_CHECK" disable constraint SYS_C007363;

2.truncate tables (备库)

set serveroutput on size 1000000 
 --spool truncate_wseprod_uat_20110914.log 
 BEGIN 
 FOR rec IN (select 'truncate '|| object_type || ' ' || object_name AS drop_sql FROM user_objects WHERE object_type IN ('TABLE') )
 LOOP 
 DBMS_OUTPUT.PUT_LINE(rec.drop_sql); 
 EXECUTE IMMEDIATE(rec.drop_sql); 
 END LOOP; 
 END; 
 /

truncate TABLE MY_HEALT_CHECK

3.创建dirtory

[oracle@xag130 ~]$ mkdir /home/oracle/mydir -p

[oracle@xag130 ~]$ sql sys/123456@xag130:1521/pdb1 as sysdba

#给用户xag赋予create any directory权限
SQL> grant create any directory to xag;

[oracle@xag130 ~]$ sql xag/123456@xag130:1521/pdb1

SQL> create or replace directory mydir as '/home/oracle/mydir';

SQL> SET SQLFORMAT ansiconsole

SQL> select my_healt_check_seq,host_address,host_name,db_name,to_char(create_time,'yyyy-mm-dd hh24:mi:ss') as create_time,to_char(update_time,'yyyy-mm-dd hh24:mi:ss') as update_time 
     from my_healt_check order by create_time desc;
MY_HEALT_CHECK_SEQ  HOST_ADDRESS    HOST_NAME  DB_NAME  CREATE_TIME          UPDATE_TIME  
100000000011        192.168.40.130  xag130     PDB1     2020-06-27 00:31:35               
100000000010        192.168.40.130  xag130     PDB1     2020-06-27 00:30:30               
100000000009        192.168.40.130  xag130     PDB1     2020-06-27 00:29:25               
100000000008        192.168.40.130  xag130     PDB1     2020-06-27 00:28:20               
100000000007        192.168.40.130  xag130     PDB1     2020-06-27 00:27:16               
100000000006        192.168.40.130  xag130     PDB1     2020-06-27 00:26:11               
100000000005        192.168.40.130  xag130     PDB1     2020-06-27 00:25:11               

7 rows selected. 

SQL> select current_scn from v$database;
CURRENT_SCN  
1488575      

#仅仅导出 my_healt_check 表的数据
[oracle@xag130 ~]$ expdp xag/123456@xag130:1521/pdb1 directory=mydir dumpfile=xag2.dmp logfile=xag2.log tables=xag.my_healt_check content=data_only flashback_scn=1488575;

4.数据导入

#同 xag130方法 在 xag131上 创建dirtory 

#导入dmp文件中的所有数据,例:
[oracle@xag131 ~]$ impdp xag/123456@xag131:1521/pdb1 directory=mydir dumpfile=xag2.dmp logfile=xag2.log full=yes

SQL> SET SQLFORMAT ansiconsole

SQL> select my_healt_check_seq,host_address,host_name,db_name,to_char(create_time,'yyyy-mm-dd hh24:mi:ss') as create_time,to_char(update_time,'yyyy-mm-dd hh24:mi:ss') as update_time 
     from my_healt_check order by create_time desc;
MY_HEALT_CHECK_SEQ  HOST_ADDRESS    HOST_NAME  DB_NAME  CREATE_TIME          UPDATE_TIME  
100000000011        192.168.40.130  xag130     PDB1     2020-06-27 00:31:35               
100000000010        192.168.40.130  xag130     PDB1     2020-06-27 00:30:30               
100000000009        192.168.40.130  xag130     PDB1     2020-06-27 00:29:25               
100000000008        192.168.40.130  xag130     PDB1     2020-06-27 00:28:20               
100000000007        192.168.40.130  xag130     PDB1     2020-06-27 00:27:16               
100000000006        192.168.40.130  xag130     PDB1     2020-06-27 00:26:11               
100000000005        192.168.40.130  xag130     PDB1     2020-06-27 00:25:11 

11.ENABLED 外键 和 check约束 (备库)

[oracle@xag131 ~]$ sql xag/123456@xag131:1521/pdb1

SQL> SET SQLFORMAT ansiconsole

SQL> set serveroutput on size 1000000 

--ENABLEDforeign key and check constraints before initial load 
 declare v_sql_stmt varchar2(4000);
 BEGIN 
 FOR c IN 
 (
   SELECT c.owner, c.table_name, c.constraint_name FROM user_constraints c, user_tables t WHERE t.table_name in ( upper('my_healt_check') ) 
   AND c.table_name = t.table_name AND c.constraint_type!='P' AND c.status = 'DISABLED' ORDER BY c.constraint_type DESC
  ) 
 LOOP 
 v_sql_stmt :='alter table "' || c.owner || '"."' || c.table_name || '" enable constraint ' || c.constraint_name;
 DBMS_OUTPUT.PUT_LINE(v_sql_stmt || ';'); 
 dbms_utility.exec_ddl_statement(v_sql_stmt); 
 END LOOP; 
 END; 
 /

alter table "XAG"."MY_HEALT_CHECK" enable constraint SYS_C007363;

你可能感兴趣的:(Oracle GoldenGate 12.3.0.1.4 in Oracle 12.2 之06(Initial Load))