源、执行-GoldenGate 单向DDL同步-by小雨

本篇文章笔者在北京喝咖啡的时候突然想到的...今天就有想写几篇关于源、执行-的文章,所以回家到之后就奋笔疾书的写出来发布了

       接着昨天的试验,这里用ogguser作为理管户用,用stat作为步同数据户用。

    
1. 源库和目标库ogguser户用都予赋dba角色和执行utl_file的权限:

     

       [oracle@dd1 ~]$ sqlplus / as sysdba
 
  SQL*Plus: Release 11.2.0.3.0 Production on Tue Apr 16 16:15:18 2013
 
  Copyright (c) 1982, 2011, Oracle.  All rights reserved.
 
 
  Connected to:
  Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
  With the Partitioning, OLAP, Data Mining and Real Application Testing options
 
  SQL> grant dba to ogguser;
 
  Grant succeeded.
 
  SQL> grant execute on utl_file to ogguser;
 
  Grant succeeded.

     

    2. 辑编源库全局参数件文
 
  [oracle@dd1 ogg11]$ cd $ORACLE_BASE/ogg11
  [oracle@dd1 ogg11]$ ggsci
 
  Oracle GoldenGate Command Interpreter for Oracle
  Version 11.1.1.1.2 OGGCORE_11.1.1.1.2_PLATFORMS_111004.2100
  Linux, x64, 64bit (optimized), Oracle 11g on Oct  4 2011 23:49:46
 
  Copyright (C) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
 
 
  GGSCI (dd1) 1> edit param ./GLOBALS
 
  ggschema ogguser
 
3. 启用DDL持支设置(只要在源库设置)
 
  [oracle@dd1 ogg11]$ sqlplus / as sysdba
 
  SQL*Plus: Release 11.2.0.3.0 Production on Tue Apr 16 16:21:35 2013
 
  Copyright (c) 1982, 2011, Oracle.  All rights reserved.
 
 
  Connected to:
  Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
  With the Partitioning, OLAP, Data Mining and Real Application Testing options
 
  执行脚本marker_setup.sql:
  SQL> @marker_setup.sql
 
  Marker setup script
 
  You will be prompted for the name of a schema for the GoldenGate database objects.
  NOTE: The schema must be created prior to running this script.
  NOTE: Stop all DDL replication before starting this installation.
 
  Enter GoldenGate schema name:ogguser  ##入输ogguser
 
 
  Marker setup table script complete, running verification script...
  Please enter the name of a schema for the GoldenGate database objects:
  Setting schema name to OGGUSER
 
  MARKER TABLE
  -------------------------------
  OK
 
  MARKER SEQUENCE
  -------------------------------
  OK
 
  Script complete.
 
  闭关回收站:
  SQL> show parameter recyclebin;
 
  NAME                                 TYPE        VALUE
  ------------------------------------ ----------- ------------------------------
  recyclebin                           string      on
 
  SQL> alter system set recyclebin=off;
  alter system set recyclebin=off
                                *
  ERROR at line 1:
  ORA-02096: specified initialization parameter is not modifiable with this
  option
 
 
  SQL> alter system set recyclebin=off scope=spfile; ##如果是10g,要需重启数据库,这里是11g,无需重启
 
  System altered.
 
  数据库开始强制日记:
  SQL> alter database force logging;
 
  Database altered.
 
  确认源库已处于归档模式,并启用附加日记和强制日记:
  SQL> select log_mode,supplemental_log_data_min,force_logging from v$database;
 
  LOG_MODE     SUPPLEME FOR
  ------------ -------- ---
  ARCHIVELOG   YES      YES
 
  执行脚本ddl_setup.sql:
  SQL> @ddl_setup.sql
 
  GoldenGate DDL Replication setup script
 
  Verifying that current user has privileges to install DDL Replication...
 
  You will be prompted for the name of a schema for the GoldenGate database objects.
  NOTE: For an Oracle 10g source, the system recycle bin must be disabled. For Oracle 11g and later, it can be enabled.
  NOTE: The schema must be created prior to running this script.
  NOTE: Stop all DDL replication before starting this installation.
 
  Enter GoldenGate schema name:ogguser ##入输ogguser
 
  You will be prompted for the mode of installation.
  To install or reinstall DDL replication, enter INITIALSETUP
  To upgrade DDL replication, enter NORMAL
  Enter mode of installation:INITIALSETUP
 
  Working, please wait ...
  Spooling to file ddl_setup_spool.txt
 
  Checking for sessions that are holding locks on Oracle Golden Gate metadata tables ...
 
  Check complete.
 
 
 
 
 
 
 
  Using OGGUSER as a GoldenGate schema name, INITIALSETUP as a mode of installation.
 
  Working, please wait ...
 
  DDL replication setup script complete, running verification script...
  Please enter the name of a schema for the GoldenGate database objects:
  Setting schema name to OGGUSER
 
  DDLORA_GETTABLESPACESIZE STATUS:
 
  Line/pos                                 Error
  ---------------------------------------- -----------------------------------------------------------------
  No errors                                No errors
 
  CLEAR_TRACE STATUS:
 
  Line/pos                                 Error
  ---------------------------------------- -----------------------------------------------------------------
  No errors                                No errors
 
  CREATE_TRACE STATUS:
 
  Line/pos                                 Error
  ---------------------------------------- -----------------------------------------------------------------
  No errors                                No errors
 
  TRACE_PUT_LINE STATUS:
 
  Line/pos                                 Error
  ---------------------------------------- -----------------------------------------------------------------
  No errors                                No errors
 
  INITIAL_SETUP STATUS:
 
  Line/pos                                 Error
  ---------------------------------------- -----------------------------------------------------------------
  No errors                                No errors
 
  DDLVERSIONSPECIFIC PACKAGE STATUS:
 
  Line/pos                                 Error
  ---------------------------------------- -----------------------------------------------------------------
  No errors                                No errors
 
  DDLREPLICATION PACKAGE STATUS:
 
  Line/pos                                 Error
  ---------------------------------------- -----------------------------------------------------------------
  No errors                                No errors
 
  DDLREPLICATION PACKAGE BODY STATUS:
 
  Line/pos                                 Error
  ---------------------------------------- -----------------------------------------------------------------
  No errors                                No errors
 
  DDL HISTORY TABLE
  -----------------------------------
  OK
 
  DDL HISTORY TABLE(1)
  -----------------------------------
  OK
 
  DDL DUMP TABLES
  -----------------------------------
  OK
 
  DDL DUMP COLUMNS
  -----------------------------------
  OK
 
  DDL DUMP LOG GROUPS
  -----------------------------------
  OK
 
  DDL DUMP PARTITIONS
  -----------------------------------
  OK
 
  DDL DUMP PRIMARY KEYS
  -----------------------------------
  OK
 
  DDL SEQUENCE
  -----------------------------------
  OK
 
  GGS_TEMP_COLS
  -----------------------------------
  OK
 
  GGS_TEMP_UK
  -----------------------------------
  OK
 
  DDL TRIGGER CODE STATUS:
 
  Line/pos                                 Error
  ---------------------------------------- -----------------------------------------------------------------
  No errors                                No errors
 
  DDL TRIGGER INSTALL STATUS
  -----------------------------------
  OK
 
  DDL TRIGGER RUNNING STATUS
  ------------------------------------------------------------------------------------------------------------------------
  ENABLED
 
  STAYMETADATA IN TRIGGER
  ------------------------------------------------------------------------------------------------------------------------
  OFF
 
  DDL TRIGGER SQL TRACING
  ------------------------------------------------------------------------------------------------------------------------
  0
 
  DDL TRIGGER TRACE LEVEL
  ------------------------------------------------------------------------------------------------------------------------
  0
 
  LOCATION OF DDL TRACE FILE
  ------------------------------------------------------------------------------------------------------------------------
  /data/oracle/diag/rdbms/test1/test1/trace/ggs_ddl_trace.log
 
  Analyzing installation status...
 
 
  STATUS OF DDL REPLICATION
  ------------------------------------------------------------------------------------------------------------------------
  SUCCESSFUL installation of DDL Replication software components
 
  Script complete.
 
  执行脚本role_setup.sql:
  SQL> @role_setup.sql
 
  GGS Role setup script
 
  This script will drop and recreate the role GGS_GGSUSER_ROLE
  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.)
 
  You will be prompted for the name of a schema for the GoldenGate database objects.
  NOTE: The schema must be created prior to running this script.
  NOTE: Stop all DDL replication before starting this installation.
 
  Enter GoldenGate schema name:ogguser
  Wrote file role_setup_set.txt
 
  PL/SQL procedure successfully completed.
 
 
  Role setup script complete
 
  Grant this role to each user assigned to the Extract, GGSCI, and Manager processes, by using the following SQL command:
 
  GRANT GGS_GGSUSER_ROLE TO <loggedUser>
 
  where <loggedUser> is the user assigned to the GoldenGate processes.
 
  根据提示对ogguser予赋ggs_ggsuser_role角色权限:
  SQL> grant ggs_ggsuser_role to ogguser;
 
  Grant succeeded.
 
  执行脚本ddl_enable.sql:
  SQL> @ddl_enable.sql
 
  Trigger altered
 
  执行dbmspool包将在数据库中创建DBMS_SHARED_POOL包,之后ddl_pin包要需用到:
  SQL> @?/rdbms/admin/dbmspool.sql
 
  Package created.
 
 
  Grant succeeded.
 
  执行ddl_pin.sql通过dbms_shared_pool.keep存储过程将DDLReplication相关对象keep在共享池中,以保证这些对象不要RELOAD,提升性能:
  SQL> @ddl_pin.sql ogguser
 
  PL/SQL procedure successfully completed.
 
 
  PL/SQL procedure successfully completed.
 
 
  PL/SQL procedure successfully completed.
 

    
4. 清除上一次试验环境

     

      源库:
  GGSCI (dd1) 38> delete extract einikk
 
  GGSCI (dd1) 38> delete extract eorakk
  2013-04-16 17:30:46  WARNING OGG-01753  Cannot unregister EXTRACT EORAKK from database because no database login was provided. You can manually unregister this group later with the UNREGISTER EXTRACT <GROUP NAME> LOGRETENTION command. Issue DBLOGIN first.
  Deleted EXTRACT EORAKK.
 
  GGSCI (dd1) 2> stop manager
  Manager process is required by other GGS processes.
  Are you sure you want to stop it (y/n)? y
 
  Sending STOP request to MANAGER ...
  Request processed.
  Manager stopped.
 
  目标库:
  GGSCI (kf2.calvin) 10> delete replicat rinikk
  Deleted REPLICAT RINIKK.
  GGSCI (kf2.calvin) 17> dblogin userid system ,password calvin
  Successfully logged into database.
 
  GGSCI (kf2.calvin) 18> delete CHECKPOINTTABLE SYSTEM.GGCHKPTABLE
  This checkpoint table may be required for other installations.  Are you sure you want to delete this checkpoint table? y
 
  Successfully deleted checkpoint table SYSTEM.GGCHKPTABLE.
 
  GGSCI (kf2.calvin) 19> delete replicat rorakk
  Deleted REPLICAT RORAKK.
 
  GGSCI (kf2.calvin) 1> stop manager
  Manager process is required by other GGS processes.
  Are you sure you want to stop it (y/n)? y
 
  Sending STOP request to MANAGER ...
  Request processed.
  Manager stopped.、

    
5. 源库和目标库建立测试户用,并授予权限

     

      SQL> create user stat identified by stat default tablespace testdata quota unlimited on testdata;
 
  User created.
 
  SQL> grant connect,resource,dba to stat;
 
  Grant succeeded.

     

    6. 对源库和目标库进行配置

     

      源库和目标库配置理管进程:
  GGSCI (dd1) 3> info all
 
  Program     Status      Group       Lag           Time Since Chkpt
 
  MANAGER     STOPPED
 
 
  GGSCI (dd1) 5> view params mgr
 
  -- this is configuration of this manager process
  PORT 7809
 
  GGSCI (dd1) 6> start manager
 
  Manager started.
 
 
  源库设置:
  GGSCI (dd1) 2> dblogin userid
ogguser@test1,password ogguser
  Successfully logged into database.
 
  GGSCI (dd1) 3> add extract test1,tranlog,begin now  ##添加extract进程
  EXTRACT added.
 
 
  GGSCI (dd1) 4> add exttrail /data/oracle/ogg11/dirdat/lt,extract test1 ##添加extrail
  EXTTRAIL added.
 
  GGSCI (dd1) 5> edit params test1       ##辑编参数
  extract test1
  userid
ogguser@test1, password ogguser
  rmthost 192.168.130.171, mgrport 7809
  rmttrail /data/oracle/ogg11/dirdat/lt
  ddl include mapped objname stat.*;
  table stat.*;
 
 
  GGSCI (dd1) 6> info all
 
  Program     Status      Group       Lag           Time Since Chkpt
 
  MANAGER     RUNNING                                          
  EXTRACT     STOPPED     TEST1       00:00:00      00:03:56
 
 
  目标库设置:
  GGSCI (kf2.calvin) 5> edit params ./GLOBALS  ##辑编全局参数件文
  GGSCHEMA ogguser
  CHECKPOINTTABLE ogguser.checkpoint
 
  GGSCI (kf2.calvin) 1> dblogin userid
ogguser@test2,password ogguser
  Successfully logged into database.
 
  GGSCI (kf2.calvin) 3> add checkpointtable ogguser.checkpoint ##添加checkpoint表
 
  Successfully created checkpoint table OGGUSER.CHECKPOINT.
 
 
  GGSCI (kf2.calvin) 4> add replicat test2,exttrail /data/oracle/ogg11/dirdat/lt,checkpointtable ogguser.checkpoint ##添加replicat进程
  REPLICAT added.
 
 
  GGSCI (kf2.calvin) 5> edit params test2   ##设置参数
  replicat test2
  ASSUMETARGETDEFS
  userid
ogguser@test2,password ogguser
  discardfile /data/oracle/ogg11/dirdat/test2_discard.txt,append, megabytes 10
  DDL INCLUDE MAPPED
  DDLERROR DEFAULT IGNORE RETRYOP
  map stat.*, target stat.*;
 
 
 
  源库开启extract进程,并检查info和report是否正常:
  GGSCI (dd1) 1> start extract test1
 
  Sending START request to MANAGER ...
  EXTRACT TEST1 starting
 
 
  GGSCI (dd1) 2> info all
 
  Program     Status      Group       Lag           Time Since Chkpt
 
  MANAGER     RUNNING                                          
  EXTRACT     RUNNING     TEST1       00:00:00      15:44:19 
 
 
  GGSCI (dd1) 4> view report test1
 
  ***********************************************************************
                   Oracle GoldenGate Capture for Oracle
       Version 11.1.1.1.2 OGGCORE_11.1.1.1.2_PLATFORMS_111004.2100
     Linux, x64, 64bit (optimized), Oracle 11g on Oct  7 2011 05:37:17
  
  Copyright (C) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
 
 
                      Starting at 2013-04-17 13:13:45
  ***********************************************************************
 
  Operating System Version:
  Linux
  Version #1 SMP Tue May 10 15:42:40 EDT 2011, Release 2.6.32-131.0.15.el6.x86_64
  Node: dd1
  Machine: x86_64
                           soft limit   hard limit
  Address Space Size   :    unlimited    unlimited
  Heap Size            :    unlimited    unlimited
  File Size            :    unlimited    unlimited
  CPU Time             :    unlimited    unlimited
 
  Process id: 15908
 
  Description:
 
  ***********************************************************************
  **            Running with the following parameters                  **
  ***********************************************************************
  extract test1
  userid
ogguser@test1, password *******
  rmthost 192.168.130.171, mgrport 7809
  rmttrail /data/oracle/ogg11/dirdat/lt
  ddl include mapped objname stat.*;
  table stat.*;
 
 
 
  Bounded Recovery Parameter:
  BRINTERVAL = 4HOURS
  BRDIR      = /data/oracle/ogg11
 
  CACHEMGR virtual memory values (may have been adjusted)
  CACHEBUFFERSIZE:                         64K
  CACHESIZE:                                8G
  CACHEBUFFERSIZE (soft max):               4M
  CACHEPAGEOUTSIZE (normal):                4M
  PROCESS VM AVAIL FROM OS (min):          16G
  CACHESIZEMAX (strict force to disk):  13.99G
 
  Database Version:
  Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
  PL/SQL Release 11.2.0.3.0 - Production
  CORE    11.2.0.3.0      Production
  TNS for Linux: Version 11.2.0.3.0 - Production
  NLSRTL Version 11.2.0.3.0 - Production
 
  Database Language and Character Set:
  NLS_LANG environment variable specified has invalid format, default value will be used.
  NLS_LANG environment variable not set, using default value AMERICAN_AMERICA.US7ASCII.
  NLS_LANGUAGE     = "AMERICAN"
  NLS_TERRITORY    = "AMERICA"
  NLS_CHARACTERSET = "AL32UTF8"
 
  Warning: your NLS_LANG setting does not match database server language setting.
  Please refer to user manual for more information.
 
  2013-04-17 13:13:46  INFO    OGG-01513  Positioning to Sequence 14, RBA 31137296.
 
  2013-04-17 13:13:46  INFO    OGG-01516  Positioned to Sequence 14, RBA 31137296, Apr 17, 2013 1:13:17 PM.
 
  2013-04-17 13:13:51  INFO    OGG-01226  Socket buffer size set to 27985 (flush size 27985).
 
  2013-04-17 13:13:51  INFO    OGG-01055  Recovery initialization completed for target file /data/oracle/ogg11/dirdat/lt000004, at RBA 1046.
 
  2013-04-17 13:13:51  INFO    OGG-01478  Output file /data/oracle/ogg11/dirdat/lt is using format RELEASE 10.4/11.1.
 
  2013-04-17 13:13:51  INFO    OGG-01026  Rolling over remote file /data/oracle/ogg11/dirdat/lt000005.
 
  2013-04-17 13:13:51  INFO    OGG-01053  Recovery completed for target file /data/oracle/ogg11/dirdat/lt000005, at RBA 986.
 
  2013-04-17 13:13:51  INFO    OGG-01057  Recovery completed for all targets.
 
  ***********************************************************************
  **                     Run Time Messages                             **
  ***********************************************************************
 
 
  2013-04-17 13:13:51  INFO    OGG-01517  Position of first record processed Sequence 14, RBA 31137296, SCN 0.1216816, Apr 17, 2013 1:13:17 PM.
 
 
  目标库开启replicat进程,并检查info和report是否正常:
  GGSCI (kf2.calvin) 14> start replicat test2
 
  Sending START request to MANAGER ...
  REPLICAT TEST2 starting
 
 
  GGSCI (kf2.calvin) 15> info all
 
  Program     Status      Group       Lag           Time Since Chkpt
 
  MANAGER     RUNNING                                          
  REPLICAT    RUNNING     TEST2       00:00:00      00:00:05   
 
 
  GGSCI (kf2.calvin) 16> view report test2
 
 
  ***********************************************************************
                   Oracle GoldenGate Delivery for Oracle
       Version 11.1.1.1.2 OGGCORE_11.1.1.1.2_PLATFORMS_111004.2100
     Linux, x64, 64bit (optimized), Oracle 11g on Oct  7 2011 05:44:59
  
  Copyright (C) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
 
 
                      Starting at 2013-04-17 13:19:20
  ***********************************************************************
 
  Operating System Version:
  Linux
  Version #1 SMP Tue May 10 15:42:40 EDT 2011, Release 2.6.32-131.0.15.el6.x86_64
  Node: kf2.calvin
  Machine: x86_64
                           soft limit   hard limit
  Address Space Size   :    unlimited    unlimited
  Heap Size            :    unlimited    unlimited
  File Size            :    unlimited    unlimited
  CPU Time             :    unlimited    unlimited
 
  Process id: 5858
 
  Description:
 
  ***********************************************************************
  **            Running with the following parameters                  **
  ***********************************************************************
  replicat test2
  ASSUMETARGETDEFS
  userid
ogguser@test2,password *******
  discardfile /data/oracle/ogg11/dirdat/test2_discard.txt,append, megabytes 10
  DDL INCLUDE MAPPED
  DDLERROR DEFAULT IGNORE RETRYOP
  map stat.*, target stat.*;
 
 
 
  CACHEMGR virtual memory values (may have been adjusted)
  CACHEBUFFERSIZE:                         64K
  CACHESIZE:                              512M
  CACHEBUFFERSIZE (soft max):               4M
  CACHEPAGEOUTSIZE (normal):                4M
  PROCESS VM AVAIL FROM OS (min):           1G
  CACHESIZEMAX (strict force to disk):    881M
 
  Database Version:
  Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
  PL/SQL Release 11.2.0.3.0 - Production
  CORE    11.2.0.3.0      Production
  TNS for Linux: Version 11.2.0.3.0 - Production
  NLSRTL Version 11.2.0.3.0 - Production
 
  Database Language and Character Set:
  NLS_LANG environment variable specified has invalid format, default value will be used.
  NLS_LANG environment variable not set, using default value AMERICAN_AMERICA.US7ASCII.
  NLS_LANGUAGE     = "AMERICAN"
  NLS_TERRITORY    = "AMERICA"
  NLS_CHARACTERSET = "AL32UTF8"
 
  Warning: your NLS_LANG setting does not match database server language setting.
  Please refer to user manual for more information.
 
  ***********************************************************************
  **                     Run Time Messages                             **
  ***********************************************************************
 
  Opened trail file /data/oracle/ogg11/dirdat/lt000004 at 2013-04-17 13:19:20
 
  Switching to next trail file /data/oracle/ogg11/dirdat/lt000005 at 2013-04-17 13:19:20 due to EOF, with current RBA 1046
  Opened trail file /data/oracle/ogg11/dirdat/lt000005 at 2013-04-17 13:19:20
 
  Processed extract process graceful restart record at seq 5, rba 986.

     

    7. 步同测试
 
  源库登录stat户用,创建表并插入数据:
  SQL> conn stat/stat
  Connected.
 
  SQL> create table tp_test(act varchar2(10),dt date default sysdate);
 
  Table created.
 
  SQL> insert into tp_test(act) values('ins');
 
  1 row created.
 
  SQL> commit;
 
  Commit complete.
 
  SQL> select * from tp_test;
 
  ACT        DT
  ---------- ---------
  ins        17-APR-13
 
  目标库登录stat户用,查看数据是否步同:
  SQL> conn stat/stat
  Connected.
  SQL> select * from tp_test;
 
  ACT        DT
  ---------- ---------
  ins        17-APR-13

文章结束给大家分享下程序员的一些笑话语录: 这年头的互联网真是娱乐了中国,网民们从各种各样的“门”里钻来钻去,又有好多“哥”好多“帝”,值得大家品味不已……网络经典语录,关于IT与互联网,经典与您分享!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值