天天看點

GoldenGate單向複制配置(支援DDL複制)

在上一篇檔案中的OGG單向複制配置不支援DLL的同步,隻支援DML,因而本文在之前的基礎上增加對DDL語句的複制,下面是簡要配置過程記錄!

一:驗證之前的配置不支援DDL複制,這裡在source端,建立一張表,發現無法複制到target端!target端也建立相同的表後,DML操作可以成功複制

  1. [root@db1 ~]# su - oracle  
  2. [oracle@db1 ~]$ sqlplus hr/hr  
  3. SQL> create table t2 (id number primary key,name varchar2(20));  
  4. Table created.  
  5. SQL> conn hr/hr@db2  
  6. Connected.  
  7. SQL> select tname from tab where tname='T2';  
  8. no rows selected  
  9. SQL> create table t2 (id number primary key,name varchar2(20));  
  10. Table created.  
  11. SQL> conn hr/hr  
  12. Connected.  
  13. SQL> insert into t2 values (1,'one');  
  14. 1 row created.  
  15. SQL> commit;  
  16. Commit complete.  
  17. SQL> conn hr/hr@db2  
  18. Connected.  
  19. SQL> select * from t2;  
  20.         ID NAME  
  21. ---------- --------------------  
  22.          1 one 

二:開始配置OGG支援DDL複制(在source端操作)

1:賦予ogg使用者相應的權限,修改全局配置檔案添加ggschema參數

  1. SQL> conn /as sysdba  
  2. Connected.  
  3. SQL> grant execute on utl_file to ogg;  
  4. Grant succeeded.  
  5. [oracle@db1 ~]$ cd $GGATE   
  6. [oracle@db1 ogg]$ ggsci  
  7. GGSCI (db1) 1> edit param ./GLOBALS  
  8. GGSCI (db1) 2> view param ./GLOBALS  
  9. ggschema ogg 

2:運作相關的sql腳本

  1. [oracle@db1 ~]$ cd $GGATE   
  2. [oracle@db1 ogg]$ sqlplus /nolog  
  3. SQL> conn /as sysdba  
  4. Connected.  
  5. SQL> @marker_setup.sql  
  6. Marker setup script  
  7. You will be prompted for the name of a schema for the Oracle GoldenGate database objects.  
  8. NOTE: The schema must be created prior to running this script.  
  9. NOTE: Stop all DDL replication before starting this installation.  
  10. Enter Oracle GoldenGate schema name:ogg  
  11. Marker setup table script complete, running verification script...  
  12. Please enter the name of a schema for the GoldenGate database objects:  
  13. Setting schema name to OGG  
  14. MARKER TABLE  
  15. -------------------------------  
  16. OK  
  17. MARKER SEQUENCE  
  18. -------------------------------  
  19. OK  
  20. Script complete.  
  21. SQL> show parameter recyclebin;  
  22. NAME                                 TYPE        VALUE  
  23. ------------------------------------ ----------- ------------------------------  
  24. recyclebin                           string      on  
  25. SQL> alter system set recyclebin=off;  
  26. System altered.  
  27. SQL> show parameter recyclebin;  
  28. NAME                                 TYPE        VALUE  
  29. ------------------------------------ ----------- ------------------------------  
  30. recyclebin                           string      OFF  
  31. SQL> @ddl_setup.sql  
  32. Oracle GoldenGate DDL Replication setup script  
  33. Verifying that current user has privileges to install DDL Replication...  
  34. You will be prompted for the name of a schema for the Oracle GoldenGate database objects.  
  35. NOTE: For an Oracle 10g source, the system recycle bin must be disabled. For Oracle 11g and later, it can be enabled.  
  36. NOTE: The schema must be created prior to running this script.  
  37. NOTE: Stop all DDL replication before starting this installation.  
  38. Enter Oracle GoldenGate schema name:ogg  
  39. Working, please wait ...  
  40. Spooling to file ddl_setup_spool.txt  
  41. Checking for sessions that are holding locks on Oracle Golden Gate metadata tables ...  
  42. Check complete.  
  43. Using OGG as a Oracle GoldenGate schema name.  
  44. Working, please wait ...  
  45. RECYCLEBIN must be empty.  
  46. This installation will purge RECYCLEBIN for all users.  
  47. To proceed, enter yes. To stop installation, enter no.  
  48. Enter yes or no:yes  
  49. ————————其他輸出省略————————  
  50. STATUS OF DDL REPLICATION  
  51. ---------------------------------------------------------------------------------------  
  52. SUCCESSFUL installation of DDL Replication software components  
  53. Script complete.  
  54. SQL> @role_setup.sql  
  55. GGS Role setup script  
  56. This script will drop and recreate the role GGS_GGSUSER_ROLE  
  57. To use a different role name, quit this script and then edit the params.sql script to change the gg_role parameter to the preferred name. (Do not run the script.)  
  58. You will be prompted for the name of a schema for the GoldenGate database objects.  
  59. NOTE: The schema must be created prior to running this script.  
  60. NOTE: Stop all DDL replication before starting this installation.  
  61. Enter GoldenGate schema name:ogg  
  62. Wrote file role_setup_set.txt  
  63. PL/SQL procedure successfully completed.  
  64. Role setup script complete  
  65. Grant this role to each user assigned to the Extract, GGSCI, and Manager processes, by using the following SQL command:  
  66. GRANT GGS_GGSUSER_ROLE TO <loggedUser> 
  67. where <loggedUser> is the user assigned to the GoldenGate processes.  
  68. SQL> grant ggs_ggsuser_role to ogg;  
  69. Grant succeeded.  
  70. SQL> @ddl_enable.sql  
  71. Trigger altered.  
  72. SQL> @?/rdbms/admin/dbmspool.sql   
  73. Package created.  
  74. Grant succeeded.  
  75. View created.  
  76. Package body created.  
  77. SQL> @ddl_pin.sql ogg  
  78. PL/SQL procedure successfully completed.  
  79. PL/SQL procedure successfully completed.  
  80. PL/SQL procedure successfully completed. 

3:source端修改extract程序的params檔案,添加"ddl include all"參數,重新開機extract程序

  1. GGSCI (db1) 1> view params eora_t1  
  2. extract eora_t1  
  3. setenv (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)  
  4. ddl include all  
  5. userid ogg,password ogg  
  6. exttrail ./dirdat/aa  
  7. table hr.*;  
  8. GGSCI (db1) 2> stop extract eora_t1  
  9. Sending STOP request to EXTRACT EORA_T1 ...  
  10. Request processed.  
  11. GGSCI (db1) 3> start extract eora_t1  
  12. Sending START request to MANAGER ...  
  13. EXTRACT EORA_T1 starting  
  14. GGSCI (db1) 4> info extract eora_t1  
  15. EXTRACT    EORA_T1   Last Started 2012-06-20 15:42   Status RUNNING  
  16. Checkpoint Lag       00:00:00 (updated 00:00:10 ago)  
  17. Log Read Checkpoint  Oracle Redo Logs  
  18.                      2012-06-20 15:42:58  Seqno 3, RBA 50044416  
  19.                      SCN 0.567478 (567478) 
  1. [root@db2 ~]# su - oracle  
  2. [oracle@db2 ~]$ cd $GGATE   
  3. [oracle@db2 ogg]$ ggsci  
  4. GGSCI (db2) 1> edit params rora_t1  
  5. GGSCI (db2) 2> view params rora_t1  
  6. replicat rora_t1  
  7. setenv (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)  
  8. ddl include all  
  9. ddlerror default ignore retryop maxretries 3 retrydelay 5  
  10. userid ogg,password ogg  
  11. handlecollisions  
  12. assumetargetdefs  
  13. discardfile ./dirrpt/rora_t1.dsc,purge  
  14. map hr.* ,target hr.*;  
  15. GGSCI (db2) 3> stop replicat rora_t1  
  16. Sending STOP request to REPLICAT RORA_T1 ...  
  17. Request processed.  
  18. GGSCI (db2) 4> start replicat rora_t1  
  19. Sending START request to MANAGER ...  
  20. REPLICAT RORA_T1 starting  
  21. GGSCI (db2) 5> info replicat rora_t1  
  22. REPLICAT   RORA_T1   Last Started 2012-06-20 15:50   Status RUNNING  
  23. Checkpoint Lag       00:00:00 (updated 00:00:00 ago)  
  24. Log Read Checkpoint  File ./dirdat/pa000000  
  25.                      First Record  RBA 4780973 
  1. [oracle@db1 ogg]$ sqlplus hr/hr  
  2. SQL> alter table t2 add location varchar2(200);  
  3. Table altered.  
  4. SQL> conn hr/hr@db2  
  5. Connected.  
  6. SQL> desc t2  
  7.  Name                                      Null?    Type  
  8.  ----------------------------------------- -------- ----------------------------  
  9.  ID                                        NOT NULL NUMBER  
  10.  NAME                                               VARCHAR2(20)  
  11.  LOCATION                                           VARCHAR2(200)  
  12. SQL> conn hr/hr  
  13. Connected.  
  14. SQL> create table t3 as select object_id,object_name from dba_objects;  
  15. Table created.  
  16. SQL> conn hr/hr@db2  
  17. Connected.  
  18. SQL> select tname from tab where tname='T3';  
  19. TNAME  
  20. ------------------------------  
  21. T3  
  22. SQL> desc t3;  
  23.  Name                                      Null?    Type  
  24.  ----------------------------------------- -------- ----------------------------  
  25.  OBJECT_ID                                          NUMBER  
  26.  OBJECT_NAME                                        VARCHAR2(128)