一、环境描述
操作系统版本: CentOS-6.5-x86_64
系统分区:
sda:40G
sda1:500M /boot EXT4
sda2: 39.5G /为LVM,包括:lv_swap 4G,lv_root 35.6G
源端[A]系统数据库 IP: 192.168.81.211
目标端[B]系统数据库 IP: 192.168.81.212
Vip:192.168.81.210(规划中,暂未使用)
数据库版本: oracle_112030_Linux-x86-64
Oracle Base:/u01/app/oracle
Software location: /u01/app/oracle/11.2.0/dbhome
Inventory directory:/u01/app/oraInventory
Clobal database name: orcl
SID:ogg1
sys/system/sysman/dbsnmp:123456
数据文件存放路径:/u01/oradata/
OGG 版本: ogg112101_fbo_ggs_Linux_x64_ora11g_64bit
说明:
# 提示符表示用户root环境下, $提示符表示用户oracle环境下。
源服务器=通俗的主服务器、目标服务器=通俗的备用服务器
建议:
系统、数据库软件在一组物理盘,存储的数据在另一组物理盘。
二、AB Linux安装
【A、B端】Linux安装:
Disc Found -> Skip -> next -> next -> next
Basic storage devices -> next -> yes,discard any data -> next
time zone: Chongqing -> next
password: 123456 -> next -> Use Anyway
Replace existing Linux system -> next -> Write changes to disk
选 Database server 点 Customize now -> next
Databases: 勾掉 2 Mysql 和 2 PostgreSQL
development:除了eclipse外全选
desktops:desktop
HA
Languages:chinese support
Load Balancer
-> next
reboot
create user: NO
三、AB DB安装
【A、B端】DB安装:
root登陆系统
启动网卡:[用光标、TAB键切换选择项、回车键确认]以A为例,B只要修改为192.168.81.212,其他一样:
#setup->network configuration->Run Tool->Device configuration->eth0 (eth0) -...->
│ Name eth0________________ │
│ Device eth0________________ │
│ Use DHCP [ ] │ <- 去掉“*”
│ Static IP 192.168.81.211______ │ <- IP
│ Netmask 255.255.255.0_______ │ <- 掩码
│ Default gateway IP 192.168.81.1________ │ <- 默认网关
->ok->save->save&Quit->Quit
#ifdown eth0
#ifup eth0
#ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:94:5A:29
inet addr:192.168.81.211 Bcast:192.168.81.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe94:5a29/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:270 errors:0 dropped:0 overruns:0 frame:0
TX packets:203 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:32463 (31.7 KiB) TX bytes:65227 (63.6 KiB)
..............
拷贝ORACLE环境设置ORACLE环境脚本到各服务器【此为linux笔记本】:
$scp ./go1.sh ./McTestInit [email protected]:/root
$scp ./go2.sh ./McTestInit [email protected]:/root
go1/2.sh: #!/bin/bash #CentOS 6.5 64bit #Oracle 11g2r ogg #Libin 2016-3-15 chengdu if [ $USER != "root" ] then echo "Not ROOT ! Please login as root !"; else bash ./McTestInit 1 ogg1 |tee -a /home/SetEnvLog_`date +%Y-%m-%d`.log fi McTestInit: #!/bin/bash #CentOS 6.5 64bit #Oracle 11g2r ogg #Libin 2016-3-15 chengdu d=`date +%Y-%m-%d`; date iptest="^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$" if [[ -z ${1} || -z ${2} ]]; then echo "Use: McTestInit 1/2 SID1/SID2" echo " SID must Uppercase !" exit fi #init env #stop iptables service iptables stop chkconfig iptables off #disable selinux cp /etc/selinux/config /etc/selinux/config_`date +%Y-%m-%d`.bak echo '# This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: ' > /etc/selinux/config echo '# enforcing - SELinux security policy is enforced.' >> /etc/selinux/config echo '# permissive - SELinux prints warnings instead of enforcing.' >> /etc/selinux/config echo '# disabled - No SELinux policy is loaded.' >> /etc/selinux/config echo 'SELINUX=disabled' >> /etc/selinux/config echo '# SELINUXTYPE= can take one of these two values:' >> /etc/selinux/config echo '# targeted - Targeted processes are protected,' >> /etc/selinux/config echo '# mls - Multi Level Security protection.' >> /etc/selinux/config echo 'SELINUXTYPE=targeted' >> /etc/selinux/config #modify name cp /etc/sysconfig/network /etc/sysconfig/network_`date +%Y-%m-%d`.bak echo 'NETWORKING=yes' > /etc/sysconfig/network echo "HOSTNAME=HTogg${1}" >> /etc/sysconfig/network echo 'NOZEROCONF=yes' >> /etc/sysconfig/network #modify hosts cp /etc/hosts /etc/hosts_`date +%Y-%m-%d`.bak while [[ ! $rac1 =~ $iptest ]]; do read -p "Enter HTogg1 IP : " rac1;done while [[ ! $rac2 =~ $iptest ]]; do read -p "Enter HTogg2 IP : " rac2;done while [[ ! $NetMask =~ $iptest ]]; do read -p "Enter NETMASK IP : " NetMask;done while [[ ! $GateWay =~ $iptest ]]; do read -p "Enter GATEWAY IP : " GateWay;done nmip[1]=$rac1 nmip[2]=$rac2 echo '127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4' > /etc/hosts echo '::1 localhost localhost.localdomain localhost6 localhost6.localdomain6' >> /etc/hosts echo "$rac1 HTogg1" >> /etc/hosts echo "$rac2 HTogg2" >> /etc/hosts #modify net ifcfg-eth0 cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0_`date +%Y-%m-%d`.bak echo "DEVICE=eth0" > /etc/sysconfig/network-scripts/ifcfg-eth0 echo "TYPE=Ethernet" >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo "NM_CONTROLLED=yes" >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo "BOOTPROTO=none" >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo "IPADDR="${nmip[${1}]}"" >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo "NETMASK=$NetMask" >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo "GATEWAY=$GateWay" >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo "IPV6INIT=no" >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo "USERCTL=no" >> /etc/sysconfig/network-scripts/ifcfg-eth0 #modify sysctrl cp /etc/sysctl.conf /etc/sysctl.conf_`date +%Y-%m-%d`.bak echo "kernel.shmmax = 1073741823" >> /etc/sysctl.conf echo "kernel.shmmni = 4096" >> /etc/sysctl.conf echo "kernel.shmall = 4194304" >> /etc/sysctl.conf echo "kernel.sem = 250 32000 100 128" >> /etc/sysctl.conf echo "fs.file-max = 65536" >> /etc/sysctl.conf echo "fs.aio-max-nr = 1048576" >> /etc/sysctl.conf echo "net.ipv4.ip_local_port_range = 9000 65500" >> /etc/sysctl.conf echo "net.core.rmem_default = 4194304" >> /etc/sysctl.conf echo "net.core.rmem_max = 4194304" >> /etc/sysctl.conf echo "net.core.wmem_default = 262144" >> /etc/sysctl.conf echo "net.core.wmem_max = 262144" >> /etc/sysctl.conf echo "kernel.panic = 60" >> /etc/sysctl.conf sysctl -p groupadd -g 54321 oinstall groupadd -g 54322 dba userdel oracle rm -rf /home/oracle/ useradd -m -u 1101 -g oinstall -G dba -d /home/oracle -s /bin/bash oracle echo "enter oracle password: " passwd oracle #mkdir mkdir -p /u01 chown -R oracle:oinstall /u01 chmod -R 775 /u01 #modify limits cp /etc/security/limits.conf /etc/security/limits.conf_`date +%Y-%m-%d`.bak echo "oracle soft nproc 2047" >> /etc/security/limits.conf echo "oracle hard nproc 16384" >> /etc/security/limits.conf echo "oracle soft nofile 1024" >> /etc/security/limits.conf echo "oracle hard nofile 65536" >> /etc/security/limits.conf #modify login cp /etc/pam.d/login /etc/pam.d/login_`date +%Y-%m-%d`.bak echo "session required pam_limits.so" >>/etc/pam.d/login #modify profile cp /etc/profile /etc/profile_`date +%Y-%m-%d`.bak echo 'if [ /$USER = "oracle" ]; then' >>/etc/profile echo ' if [ /$SHELL = "/bin/ksh" ]; then' >>/etc/profile echo ' ulimit -p 16384' >>/etc/profile echo ' ulimit -n 65536' >>/etc/profile echo ' else' >>/etc/profile echo ' ulimit -u 16384 -n 65536' >>/etc/profile echo ' fi' >>/etc/profile echo ' umask 022' >>/etc/profile echo 'fi' >>/etc/profile #modify oracle.bash_profile 1.2. cp /home/oracle/.bash_profile /home/oracle/.bash_profile_`date +%Y-%m-%d`.bak echo "ORACLE_SID=${2}; export ORACLE_SID" >>/home/oracle/.bash_profile echo 'ORACLE_UNQNAME=prod; export ORACLE_UNQNAME' >>/home/oracle/.bash_profile echo 'JAVA_HOME=/usr/local/java; export JAVA_HOME' >>/home/oracle/.bash_profile echo 'ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE' >>/home/oracle/.bash_profile echo 'ORACLE_HOME=$ORACLE_BASE/11.2.0/dbhome; export ORACLE_HOME' >>/home/oracle/.bash_profile echo 'ORACLE_TERM=xterm; export ORACLE_TERM' >>/home/oracle/.bash_profile echo 'NLS_DATE_FORMAT="YYYY:MM:DD HH24:MI:SS"; export NLS_DATE_FORMAT' >>/home/oracle/.bash_profile echo 'NLS_LANG=american_america.ZHS16GBK; export NLS_LANG' >>/home/oracle/.bash_profile echo 'TNS_ADMIN=$ORACLE_HOME/network/admin; export TNS_ADMIN' >>/home/oracle/.bash_profile echo 'ORA_NLS11=$ORACLE_HOME/nls/data; export ORA_NLS11' >>/home/oracle/.bash_profile echo 'PATH=.:${JAVA_HOME}/bin:${PATH}:$HOME/bin:$ORACLE_HOME/bin:$ORA_CRS_HOME' >>/home/oracle/.bash_profile/bin echo 'PATH=${PATH}:/usr/bin:/bin:/usr/bin/X11:/usr/local/bin' >>/home/oracle/.bash_profile echo 'export PATH' >>/home/oracle/.bash_profile echo 'LD_LIBRARY_PATH=$ORACLE_HOME/lib' >>/home/oracle/.bash_profile echo 'LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ORACLE_HOME/oracm/lib' >>/home/oracle/.bash_profile echo 'LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib' >>/home/oracle/.bash_profile echo 'export LD_LIBRARY_PATH' >>/home/oracle/.bash_profile echo 'CLASSPATH=$ORACLE_HOME/JRE' >>/home/oracle/.bash_profile echo 'CLASSPATH=${CLASSPATH}:$ORACLE_HOME/jlib' >>/home/oracle/.bash_profile echo 'CLASSPATH=${CLASSPATH}:$ORACLE_HOME/rdbms/jlib' >>/home/oracle/.bash_profile echo 'CLASSPATH=${CLASSPATH}:$ORACLE_HOME/network/jlib' >>/home/oracle/.bash_profile echo 'export CLASSPATH' >>/home/oracle/.bash_profile echo 'THREADS_FLAG=native; export THREADS_FLAG' >>/home/oracle/.bash_profile echo 'export TEMP=/tmp' >>/home/oracle/.bash_profile echo 'export TMPDIR=/tmp' >>/home/oracle/.bash_profile echo '# ---------------------------------------------------' >>/home/oracle/.bash_profile echo '# UMASK ' >>/home/oracle/.bash_profile echo '# ---------------------------------------------------' >>/home/oracle/.bash_profile echo '# Set the default file mode creation mask ' >>/home/oracle/.bash_profile echo '# (umask) to 022 to ensure that the user performing # the Oracle software installation creates files ' >>/home/oracle/.bash_profile echo '# with 644 permissions. ' >>/home/oracle/.bash_profile echo '# ---------------------------------------------------' >>/home/oracle/.bash_profile echo 'umask 022' >>/home/oracle/.bash_profile #del NTP if read -p "Enter Your NTP IP or press return: " ntpIP; then if [ ! -z $ntpIP ]; then if [[ $ntpIP =~ $iptest ]]; then ntpdate $ntpIP hwclock -w fi fi fi service ntpd stop service ntpd status chkconfig ntpd off chkconfig ntpd --list /etc/init.d/libvirtd stop chkconfig libvirtd off echo "set env finished." date
A:
#bash ./go1.sh
B:
#bash ./go2.sh
【如果用非原版db.iso则必须对database目录
#chown -R oracle.oinstall ./database
#chmod 755 -R ./database
】
在安装目录下执行./runinstaller,如果出现安装提示must be configured to display at least 256 colors Failed,就执行如下
root 下先执行
#xhost +
#export DISPLAY=:0.0
#su - oracle
#./runinstaller -> y
勾掉:i wish to receive security updates... next -> yes
勾:Skip software updates -> next
Create and configure a database -> next
server class ->
Single istance database installation ->
Advanced install -> next -> next
Enterprise edtion(4.5GB) -> next
Oracle Base:/u01/app/oracle
Software location: /u01/app/oracle/11.2.0/dbhome
Inventory directory:/u01/app/oraInventory -> next
General Purpose / Transaction Processing -> next
Clobal database name: orcl
SID:ogg1 -> next
Memory(sga,pga) 勾:Enable Automatic Memory Management
Character sets:Traditional Chinese ZHT32EUC -> next -> next
Specify database file localtion: /u01/app/oracle/oradata -> next
Do not enable automated backups -> next
Use the same password all accounts:123456 -> next -> yes
Database operator group:oinstall -> next
换centOS6.5光盘:
#cd /media/cdrom/Pa...
#rpm -ivh libaio-devel-0.3.107-10.el6.x86_64.rpm
#rpm -ivh compat-libstdc++-33-3.2.3-69.el6.x86_64.rpm
checks: pdksh-5.2.14 -> ignore all -> next -> yes -> install
Global Database Name:orcl
System Identifier(SID):ogg1
Parameter filename:/u01/app/oracle/11.2.0/dbhome/dbs/spfileogg1.ora
Enterprise Manager database Control URL:
https://HTogg1:1158/em
https://HTogg2:1158/em
#/u01/app/oraInventory/orainstRoot.sh
#u01/app/oracle/11.2.0/dbhome/root.sh 回2次车
-> ok -> close
install session at:
/u01/app/oraInventory/logs/installActions2016-...
本地 设置ORACLE为自动随系统启动关闭:
$scp ./oracle ./dbSet.sh [email protected]/212:/root
dbSet.sh: #!/bin/bash #CentOS 6.5 64bit #Oracle 11g2r ogg #Libin 2016-3-15 chengdu d=`date +%Y-%m-%d`; if [ $USER != "root" ] then echo "Not ROOT ! Please login as root !"; else cp /etc/oratab /etc/oratab_`date +%Y-%m-%d`.bak echo 'ogg1:/u01/app/oracle/11.2.0/dbhome:Y' >/etc/oratab cp ./oracle /etc/init.d/ chmod 755 /etc/init.d/oracle chkconfig --level 35 oracle on ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle fi oracle: #!/bin/sh # chkconfig: 35 80 10 # description: Oracle auto start-stop script. # # Set ORACLE_HOME to be equivalent to the $ORACLE_HOME # from which you wish to execute dbstart and dbshut; # # Set ORA_OWNER to the user id of the owner of the # Oracle database in ORACLE_HOME. ORACLE_HOME=/u01/app/oracle/11.2.0/dbhome ORA_OWNER=oracle case "$1" in 'start') # Start the Oracle databases: echo "Starting Oracle Databases ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORACLE_HOME/bin/dbstart" >>/var/log/oracle echo "Done" # Start the Listener: echo "Starting Oracle Listeners ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl start" >>/var/log/oracle echo "Done." echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Finished." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle touch /var/lock/subsys/oracle ;; 'stop') # Stop the Oracle Listener: echo "Stoping Oracle Listeners ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl stop" >>/var/log/oracle echo "Done." rm -f /var/lock/subsys/oracle # Stop the Oracle Database: echo "Stoping Oracle Databases ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORACLE_HOME/bin/dbshut" >>/var/log/oracle echo "Done." echo "" echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Finished." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle ;; 'restart') $0 stop $0 start ;; *) $0 start ;; esac
A/B:
#bash ./dbSet.sh
【A、B端】测试DB:
$cd $ORACLE_HOME/bin/
$./lsnrctl status
$./sqlplus /nolog
SQL>conn / as sysdba;
SQL>startup;
SQL>desc tab;
SQL>
with a as
(select 101 - rownum n from dual connect by rownum <102),
max_one as
(select max(n) max1 from a),
max_two as
(select /*+leading(p2,p1) use_nl(p1) */ p2.n max2,p1.n max1
from a p1,a p2
where p1.n+p2.n=100
and p1.n=(select max1 from max_one)
and rownum=1)
select * from max_two;
MAX2 MAX1
------ -----
0 100
SQL>quit
四、DML单向复制
【DML单向A->B复制】参考资料“手把手教你安装和配置OGG,并实现单向DML复制技术.html完全OK”
唯一,重新启动系统后,要手动启动ggsci中的各服务start mgr、start *
A:
sql:
create tablespace goldengate datafile ‘/u01/ogg/goldengate01.dbf‘ size 100m autoextend on;
create user goldengate identified by goldengate default tablespace goldengate temporary tablespace temp;
grant connect to goldengate;
grant alter any table to goldengate;
grant alter session to goldengate;
grant create session to goldengate;
grant flashback any table to goldengate;
grant select any dictionary to goldengate;
grant select any table to goldengate;
grant resource to goldengate;
grant select any transaction to goldengate;
archive log list
select supplemental_log_data_min from v$database;
alter system switch logfile;
其实以上grant 可以简洁为1句:GRANT CONNECT,RESOURCE,DBA TO goldengate;
ggsci:
create subdirs
edit params mgr
port 7839
DYNAMICPORTLIST 7840-7850
AUTOSTART EXTRACT *
AUTORESTART EXTRACT *
PURGEOLDEXTRACTS ./dirdat/*,usecheckpoints, minkeepdays 7
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 45
start mgr
info all
GGSCI (HTogg1) 5> info mgr
Manager is running (IP port HTogg1.7839).
A:
select owner||‘.‘||table_name table_name,logging from dba_tables where owner=‘ITS‘;
TABLE_NAME
--------------------------------------------------------------------------------
LOGGIN
------
ITS.BBB
YES
ITS.AAA
YES
ggsci:
dblogin userid goldengate, password goldengate
info trandata its.*
add trandata hr.*
add extract ext_01, tranlog, begin now, threads 1
add EXTTRAIL ./dirdat/r1, extract ext_01,megabytes 100
edit param ext_01
EXTRACT ext_01
setenv (ORACLE_SID=ogg1)
setenv (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK)
userid goldengate,password goldengate
REPORTCOUNT EVERY 1 MINUTES, RATE
numfiles 5000
DISCARDFILE ./dirrpt/ext_01.dsc,APPEND,MEGABYTES 1000
DISCARDROLLOVER AT 3:00
exttrail ./dirdat/r1,megabytes 100
dynamicresolution
TRANLOGOPTIONS EXCLUDEUSER goldengate
TRANLOGOPTIONS convertucs2clobs
TABLE ITS.*;
start ext_01
add extract dpe_01, exttrailsource ./dirdat/r1
add rmttrail ./dirdat/t1,EXTRACT dpe_01,MEGABYTES 100
edit param dpe_01
extract dpe_01
dynamicresolution
passthru
rmthost 192.168.81.212, mgrport 7839, compress
rmttrail ./dirdat/t1
numfiles 5000
TABLE ITS.*;
start dpe_01
B:
sql:
create tablespace goldengate datafile ‘/u01/ogg/goldengate01.dbf‘ size 100m autoextend on;
create user goldengate identified by goldengate default tablespace goldengate temporary tablespace temp;
grant connect to goldengate;
grant alter any table to goldengate;
grant alter session to goldengate;
grant create session to goldengate;
grant flashback any table to goldengate;
grant select any dictionary to goldengate;
grant select any table to goldengate;
grant resource to goldengate;
grant insert any table to goldengate;
grant update any table to goldengate;
grant delete any table to goldengate;
grant create any index to goldengate;
grant select any transaction to goldengate;
其实以上grant 可以简洁为1句:GRANT CONNECT,RESOURCE,DBA TO
goldengate;
B:
[[email protected] ogg]$ ./ggsci
GGSCI (HTogg2) 2> create subdirs
GGSCI (HTogg2) 3> edit params mgr
port 7839
DYNAMICPORTLIST 7840-7850
AUTOSTART EXTRACT *
AUTORESTART EXTRACT *
PURGEOLDEXTRACTS ./dirdat/*,usecheckpoints, minkeepdays 7
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 45
start mgr
info all
info mgr
Manager is running (IP port HTogg2.7839).
dblogin userid goldengate,password goldengate
add checkpointtable goldengate.rep_01_ckpt
add replicat rep_01,exttrail ./dirdat/t1,checkpointtable goldengate.rep_01_ckpt
edit param rep_01
REPLICAT rep_01
SETENV (ORACLE_SID=ogg1)
SETENV (NLS_LANG = "AMERICAN_AMERICA.ZHS16GBK")
USERID goldengate,PASSWORD goldengate
REPORTCOUNT EVERY 30 MINUTES, RATE
REPERROR DEFAULT, ABEND
numfiles 5000
--HANDLECOLLISIONS
assumetargetdefs
DISCARDFILE ./dirrpt/rep_01.dsc, APPEND, MEGABYTES 1000
ALLOWNOOPUPDATES
MAP ITS.*, TARGET ITS.*;
start rep_01
测试:insert delete update OK!!
小心由于AB数据不一致,导致ogg B replicat 进程 abended
所以,最好先停业务、停OGG服务,导A数据到B,然后再启动Bogg、Aogg、业务
五、DDL单向复制
【DDL单向A->B复制】参考“为已经运行的GoldenGate开启DDL选项”
1. 源端支持DDL复制运行脚本
2. 修改源端extract进程的params文件
3. 修改目标端replicat进程的params文件
4. 测试
1.分别停止source、target端的OGG进程
stop *
stop mgr
2.source端抽取进程参数添加DDL选项
GGSCI (node3) 43> edit params ext_01
...
DDL INCLUDE ALL
DDLOPTIONS ADDTRANDATA, REPORT
...
3.target端复制进程添加DDL选项
GGSCI (single) 19> edit params rep_01
...
DDL INCLUDE MAPPED
DDLOPTIONS REPORT
...
4. 为OGG用户显示添加权限
grant dba to goldengate;--可省
grant create table,create sequence to goldengate;--可省
@role_setup.sql
GRANT GGS_GGSUSER_ROLE TO goldengate;
@marker_setup.sql
name:goldengate
@ddl_setup.sql
name:goldengate
@ddl_enable.sql
[email protected]_disable.sql
[email protected]_remove.sql
[email protected]_remove.sql
分别开启source、target端各个进程
start mgr
start *
测试:
source
create table tt as select * from aaa;
target
desc tt;
source
ALTER TABLE tt ADD cc varchar2(4) default ‘zz‘;
target
desc tt;
source
ALTER TABLE aaa ADD cc varchar2(4) default ‘zz‘;
target
select * from aaa;
OK!!
??alter system set recyclebin=off; 10G?
ERROR at line 1:
ORA-02096: specified initialization parameter is not modifiable with this
option
??target
edit params rt1
ddlerror default ignore retryop maxretries 3 retrydelay 5
[email protected]_pin.sql
[email protected]/rdbms/admin/dbmspool.sql
测试权限:GRANT CONNECT,RESOURCE,DBA TO OGG;
revoke
B:
sql:
revoke alter any table from goldengate;
revoke alter session from goldengate;
revoke create session from goldengate;
revoke flashback any table from goldengate;
revoke select any dictionary from goldengate;
revoke select any table from goldengate;
revoke insert any table from goldengate;
revoke update any table from goldengate;
revoke delete any table from goldengate;
revoke create any index from goldengate;
revoke select any transaction from goldengate;
revoke create table,create sequence from goldengate;
grant connect to goldengate;
grant resource to goldengate;
grant dba to goldengate;
A:
sql:
revoke alter any table from goldengate;
revoke alter session from goldengate;
revoke create session from goldengate;
revoke flashback any table from goldengate;
revoke select any dictionary from goldengate;
revoke select any table from goldengate;
revoke select any transaction from goldengate;
revoke create table,create sequence from goldengate;
grant connect to goldengate;
grant resource to goldengate;
grant dba to goldengate;
source
create table tt2 as select * from aaa;
insert into tt2 values(‘t2‘,‘t2‘,‘t2‘);
target
desc tt2;
ok!!
source
create table tt3 as select * from aaa;
insert into tt3 values(‘t3‘,‘t3‘,‘t3‘);
commit;
target
desc tt2;
select * from tt3;
source
delete from tt3 where cc=‘t3‘;
commit;
update tt3 set cc=‘c3‘;
commit;
alter table tt3 add xx varchar2(2) default ‘x4‘;
alter table tt3 rename column xx to dd;
alter table tt3 modify dd varchar2(4) default ‘x4‘;
target
select * from tt3;
ok!!
六、问题场景描述
源服务器A出问题[如系统崩溃、数据库崩溃、磁盘坏等]切换操作:
把问题服务器A修复后,设置为目标服务器B,把之前的目标服务器B设置为源服务器A。AB的IP等系统设置不变。
目标服务器B出问题,直接按照新装目标服务器搭建即可。
假设A服务器192.168.81.211崩溃的恢复【恢复后当目标机B用】步骤:
1.恢复A.211后当目标B.211机用
2.设置原来的目标B.212机为现在的源端A.212机用
3.依据SCN从212导数据到211,或者直接从A完全导数据到B
4.启动211、212的OGG服务
注意:
A、B数据不同,容易导致OGG服务挂起!!!
在212数据导出之前,必须关闭数据对外服务,待数据导出开始后,启动源端OGG的各服务后,才能启动源端数据的对外服务;在目的端211,必须等数据导入后,才能启动OGG各服务。否则会因为中间产生无法同步的数据,导致生产中OGG
DOWN机各服务挂起。
或者:断掉数据服务,导数据A->B,开A、B的OGG各个服务,提供数据服务。
七、恢复A为目标服务器
192.168.81.211原来的源端A.211机设置为目标【B.211】端:
1、按“myDB20160417”文档安装系统、数据库【IP、SID等不变,还为A.211的】
$scp ./oracle ./dbSet.sh [email protected]:/root
#bash ./dbSet.sh
具体脚本:
dbSet.sh: #!/bin/bash #CentOS 6.5 64bit #Oracle 11g2r ogg #Libin 2016-3-15 chengdu d=`date +%Y-%m-%d`; if [ $USER != "root" ] then echo "Not ROOT ! Please login as root !"; else cp /etc/oratab /etc/oratab_`date +%Y-%m-%d`.bak echo ‘ogg1:/u01/app/oracle/11.2.0/dbhome:Y‘ >/etc/oratab cp ./oracle /etc/init.d/ chmod 755 /etc/init.d/oracle chkconfig --level 35 oracle on ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle fi oracle: #!/bin/sh # chkconfig: 35 80 10 # description: Oracle auto start-stop script. # # Set ORACLE_HOME to be equivalent to the $ORACLE_HOME # from which you wish to execute dbstart and dbshut; # # Set ORA_OWNER to the user id of the owner of the # Oracle database in ORACLE_HOME. ORACLE_HOME=/u01/app/oracle/11.2.0/dbhome ORA_OWNER=oracle case "$1" in ‘start‘) # Start the Oracle databases: echo "Starting Oracle Databases ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORACLE_HOME/bin/dbstart" >>/var/log/oracle echo "Done" # Start the Listener: echo "Starting Oracle Listeners ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl start" >>/var/log/oracle echo "Done." echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Finished." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle touch /var/lock/subsys/oracle ;; ‘stop‘) # Stop the Oracle Listener: echo "Stoping Oracle Listeners ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl stop" >>/var/log/oracle echo "Done." rm -f /var/lock/subsys/oracle # Stop the Oracle Database: echo "Stoping Oracle Databases ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORACLE_HOME/bin/dbshut" >>/var/log/oracle echo "Done." echo "" echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Finished." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle ;; ‘restart‘) $0 stop $0 start ;; *) $0 start ;; esac |
2、ogg安装:
$scp -r ./ogg* [email protected]:/u01
#cd /u01
#bash oggSet.sh
具体脚本:
oggSet.sh: #!/bin/bash #CentOS 6.5 64bit #Oracle 11g2r ogg #Libin 2016-3-15 chengdu oh="/u01/app/oracle/11.2.0/dbhome" oup="sys/123456" oggup="ogg/ogg" cdn="orcl" #d="/home/oracle/ogg"; d2="/u01/ogg"; d3="/u01/archivelog"; d4="/u01/oradata"; if [ $USER != "root" ] then echo "Not ROOT ! Please login as root !"; else mkdir $d2 $d3 $d4 # $d tar zxvf ./ogg112101_fbo_ggs_Linux_x64_ora11g_64bit.tar.gz -C $d2 chown -R oracle:oinstall $d2 $d3 $d4 /home/oracle #$d chmod -R 775 $d2 su - oracle -c "$oh/bin/sqlplus $oup as sysdba @$(pwd)/oggAchiveSet.sql" su - oracle -c "$oh/bin/sqlplus $oggup @$(pwd)/oggchk.sql" fi oggAchiveSet.sql: --archivelog shutdown immediate startup mount; --alter system set recyclebin=off scope=both; alter system set db_recovery_file_dest=‘‘ scope=both; alter system set log_archive_dest_1=‘location=/u01/archivelog‘ scope = both; alter database archivelog; alter database open; shutdown immediate startup --log alter database force logging; alter database add supplemental log data; alter database add supplemental log data (primary key,unique index,foreign key) columns; --ogg set CREATE TABLESPACE OGG_ITS DATAFILE ‘/u01/oradata/ogg_its01.dbf‘ SIZE 100M AUTOEXTEND ON NEXT 10M MAXSIZE 32767M; CREATE USER ogg IDENTIFIED BY ogg DEFAULT TABLESPACE OGG_ITS TEMPORARY TABLESPACE TEMP ACCOUNT UNLOCK; GRANT CONNECT,RESOURCE,DBA TO OGG; quit oggchk.sql: @@/u01/ogg/chkpt_ora_create.sql quit |
目标【B】端 OGG配置:
$ cd /u01/ogg
$ ./ggsci
步骤:
GGSCI (HTogg1) 1> create subdirs
GGSCI (HTogg1) 2> edit param mgr <-具体参数见下面
GGSCI (HTogg1) 3> edit param GLOBALS <-具体参数见下面
GGSCI (HTogg1) 4> add replicat repl01,checkpointtable ogg.ggs_checkpoint,exttrail ./dirdat/ht
GGSCI (HTogg1) 5>edit param repl01 <-具体参数见下面
具体的:【
GGSCI (HTogg1) 1> create subdirs
Creating subdirectories under current directory /u01/ogg
Parameter files /u01/ogg/dirprm: already exists
Report files /u01/ogg/dirrpt:created
Checkpoint files /u01/ogg/dirchk: created
Process status files /u01/ogg/dirpcs: created
SQL script files /u01/ogg/dirsql: created
Database definitions files /u01/ogg/dirdef: created
Extract data files /u01/ogg/dirdat: created
Temporary files /u01/ogg/dirtmp: created
Stdout files /u01/ogg/dirout: created
GGSCI (HTogg1) 2>edit param mgr
PORT 7909
DYNAMICPORTLIST 7940-7950
AUTOSTART REPLICAT *
AUTORESTART REPLICAT *, RETRIES 5, WAITMINUTES 7
PURGEOLDEXTRACTS ./dirdat/*, USECHECKPOINTS, MINKEEPDAYS 7
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 45
GGSCI (HTogg1) 3>edit param GLOBALS
GGSCHEMA ogg
CHECKPOINTTABLE ogg.ggs_checkpoint
GGSCI (HTogg1) 4> add replicat repl01,checkpointtable ogg.ggs_checkpoint,exttrail ./dirdat/ht
REPLICAT added.
GGSCI (HTogg1) 5>edit param repl01
REPLICAT repl01
SETENV (NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8")
USERID ogg,PASSWORD ogg
REPORT AT 01:50
REPORTCOUNT EVERY 30 MINUTES, RATE
REPORTROLLOVER AT 02:00
REPERROR DEFAULT, ABEND
NUMFILES 1000
GROUPTRANSOPS 3000
ASSUMETARGETDEFS
DISCARDFILE ./dirrpt/repl01.dsc, APPEND, MEGABYTES 200
DISCARDROLLOVER AT 02:00
GETTRUNCATES
ALLOWNOOPUPDATES
DDL INCLUDE ALL
DDLERROR DEFAULT IGNORE RETRYOP MAXRETRIES 3 RETRYDELAY 5
DDLOPTIONS REPORT
MAPEXCLUDE ITS.BAYMONRECSTAT
MAP ITS.*,TARGET ITS.*;
GGSCI (HTogg1) 6> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER STOPPED
REPLICAT STOPPED REPL01 00:00:00 00:01:01 】
八、设置B为源服务器
192.168.81.212原来的目标B.212机设置为现在的源端A.212机【A】端:
1、删除REPLICAT配置参数
2、重新设置源端A.212机
$ cd /u01/ogg
$ ./ggsci
GGSCI () 1> dblogin userid ogg,password ogg
GGSCI () 2> delete replicat repl01
【
GGSCI (HTogg2) 3> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER STOPPED
REPLICAT ABENDED REPL01 00:00:00 170:45:41
GGSCI (HTogg2) 5> dblogin userid ogg,password ogg
Successfully logged into database.
GGSCI (HTogg2) 6> delete replicat repl01
Deleted REPLICAT REPL01.
GGSCI (HTogg2) 7> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER STOPPED
】
$ cd /u01/ogg
$rm ./dir开头的目录下的除了jar外的所有文件
$rm *.dmp
$rm *.txt
$rm *.log
$ cd /u01/ogg
$ $ORACLE_HOME/bin/sqlplus / as sysdba
SQL> @marker_setup.sql
出现Enter Oracle GoldenGate schema name:输入ogg
SQL> @ddl_setup.sql
出现Enter Oracle GoldenGate schema name:输入ogg
SQL> @role_setup.sql
出现Enter GoldenGate schema name:输入ogg
SQL> GRANT GGS_GGSUSER_ROLE TO ogg;
SQL> @ddl_enable.sql
SQL> quit
$ cd /u01/ogg
$ ./ggsci
GGSCI (HTogg2) 1> create subdirs
GGSCI (HTogg2) 2> edit param mgr
GGSCI (HTogg2) 3> edit param GLOBALS
GGSCI (HTogg2) 4> edit param extr01
GGSCI (HTogg2) 5> edit param pump01
GGSCI (HTogg2) 6> add extract extr01,tranlog,begin now
GGSCI (HTogg2) 7> add exttrail ./dirdat/ht,extract extr01,megabytes 50
GGSCI (HTogg2) 8> add extract pump01,exttrailsource ./dirdat/ht
GGSCI (HTogg2) 9> add rmttrail ./dirdat/ht,extract pump01,megabytes 50
GGSCI (HTogg2) 10> dblogin userid ogg, password ogg
GGSCI (HTogg2) 11> add trandata its.*
GGSCI (HTogg2) 12> info all
【具体配置:
GGSCI (HTogg2) 1> create subdirs
Creating subdirectories under current directory /u01/ogg
Parameter files /u01/ogg/dirprm: already exists
Report files /u01/ogg/dirrpt: already exists
Checkpoint files /u01/ogg/dirchk: already exists
Process status files /u01/ogg/dirpcs: already exists
SQL script files /u01/ogg/dirsql: already exists
Database definitions files /u01/ogg/dirdef: already exists
Extract data files /u01/ogg/dirdat: already exists
Temporary files /u01/ogg/dirtmp: already exists
Stdout files /u01/ogg/dirout: already exists
GGSCI (HTogg2) 2> edit param mgr
PORT 7909
DYNAMICPORTLIST 7940-7950
AUTOSTART ER *
AUTORESTART EXTRACT *, RETRIES 5, WAITMINUTES 7
PURGEOLDEXTRACTS ./dirdat/*, USECHECKPOINTS, MINKEEPDAYS 7
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 45
GGSCI (HTogg2) 3> edit param GLOBALS
GGSCHEMA ogg
CHECKPOINTTABLE ogg.ggs_checkpoint
GGSCI (HTogg2) 4> edit param extr01
EXTRACT extr01
SETENV (NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8")
USERID ogg, PASSWORD ogg
GETTRUNCATES
REPORTCOUNT EVERY 30 MINUTES, RATE
NUMFILES 1000
DISCARDFILE ./dirrpt/extr01.dsc, APPEND, MEGABYTES 200
DISCARDROLLOVER AT 3:00
WARNLONGTRANS 2h, CHECKINTERVAL 3m
EXTTRAIL ./dirdat/ht, MEGABYTES 200
DYNAMICRESOLUTION
DDL INCLUDE ALL
TRANLOGOPTIONS EXCLUDEUSER ogg
TABLE its.*;
GGSCI (HTogg2) 5> edit param pump01
EXTRACT pump01
RMTHOST 192.168.81.211, MGRPORT 7909
PASSTHRU
NUMFILES 1000
RMTTRAIL ./dirdat/ht
DYNAMICRESOLUTION
TABLE its.*;
GGSCI (HTogg2) 6> add extract extr01,tranlog,begin now
EXTRACT added.
GGSCI (HTogg2) 7> add exttrail ./dirdat/ht,extract extr01,megabytes 50
EXTTRAIL added.
GGSCI (HTogg2) 8> add extract pump01,exttrailsource ./dirdat/ht
EXTRACT added.
GGSCI (HTogg2) 9> add rmttrail ./dirdat/ht,extract pump01,megabytes 50
RMTTRAIL added.
GGSCI (HTogg2) 10> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER STOPPED
EXTRACT STOPPED EXTR01 00:00:00 00:00:29
EXTRACT STOPPED PUMP01 00:00:00 00:00:11
GGSCI (HTogg2) 11> dblogin userid ogg, password ogg
Successfully logged into database.
GGSCI (HTogg2) 12> add trandata its.*
2016-04-26 08:30:59 WARNING OGG-00869 No unique key is defined for table ‘AAA‘. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key.
Logging of supplemental redo data enabled for table ITS.AAA.
Logging of supplemental redo data enabled for table ITS.BBB.
】
九、导数据
依据SCN从212导数据到211:
建议先停业务,停2服务器数据对外服务,防止数据不同!然后停止OGG服务stop
* stop mgr...
A211生产数据环境:
$ $ORACLE_HOME/bin/sqlplus / as sysdba
SQL>CREATE TABLESPACE ITS DATAFILE ‘/u01/oradata/its01.dbf‘ SIZE 100M AUTOEXTEND ON NEXT 10M MAXSIZE 32767M;
SQL>CREATE USER its IDENTIFIED BY its DEFAULT TABLESPACE ITS TEMPORARY TABLESPACE TEMP ACCOUNT UNLOCK;
SQL>GRANT CONNECT,RESOURCE,DBA TO its;
A212、B211设置导数据环境:
$ $ORACLE_HOME/bin/sqlplus / as sysdba
SQL>create directory dump_dir as ‘/home/oracle‘;
SQL>Grant read,write on directory dump_dir to its;
A212:
SQL>select current_scn from v$database;
CURRENT_SCN
-----------
1168863
$ $ORACLE_HOME/bin/expdp its/[email protected] schemas=its dumpfile=db01.dmp logfile=bakBegin.log flashback_scn=1168863 DIRECTORY=dump_dir
【[[email protected] ~]$ $ORACLE_HOME/bin/expdp its/[email protected] schemas=its dumpfile=db01.dmp logfile=bakBegin.log flashback_scn=1168863 DIRECTORY=dump_dir
Export: Release 11.2.0.3.0 - Production on Tue Apr 26 09:42:37 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. 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
FLASHBACK automatically enabled to preserve database integrity.
Starting "ITS"."SYS_EXPORT_SCHEMA_01":
its/********@orcl schemas=its dumpfile=db01.dmp logfile=bakBegin.log flashback_scn=1168863 DIRECTORY=dump_dir
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 256 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
. . exported "ITS"."AAA" 5.789 KB 1 rows
. . exported "ITS"."BB2" 5.414 KB 3 rows
. . exported "ITS"."BBB" 5.828 KB 4 rows
. . exported "ITS"."CCC" 5.398 KB 1 rows
Master table "ITS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for ITS.SYS_EXPORT_SCHEMA_01 is:
/home/oracle/db01.dmp
Job "ITS"."SYS_EXPORT_SCHEMA_01" successfully completed at 09:43:20
】
[[email protected] ogg]$ scp /home/oracle/db01.dmp [email protected]:/home/oracle/db01.dmp
The authenticity of host ‘192.168.81.211 (192.168.81.211)‘ can‘t be established.
RSA key fingerprint is 65:5f:f6:63:03:cb:02:21:93:35:7c:77:5c:d6:32:75.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.81.211‘ (RSA) to the list of known hosts.
[email protected]‘s password:
db01.dmp
100% 208KB 208.0KB/s 00:00
B211:
$ $ORACLE_HOME/bin/impdp its/[email protected] schemas=its DIRECTORY=dump_dir dumpfile=db01.dmp
[本地如果监听没有起来,则:$ $ORACLE_HOME/bin/lsnrctl start]
【$ORACLE_HOME/bin/impdp its/[email protected] schemas=its DIRECTORY=dump_dir dumpfile=db01.dmp
Import: Release 11.2.0.3.0 - Production on Wed Apr 27 01:04:44 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. 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
Master table "ITS"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded
Starting "ITS"."SYS_IMPORT_SCHEMA_01":
its/********@orcl schemas=its DIRECTORY=dump_dir dumpfile=db01.dmp
Processing object type SCHEMA_EXPORT/USER
ORA-31684: Object type USER:"ITS" already exists
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "ITS"."AAA" 5.789 KB 1 rows
. . imported "ITS"."BB2" 5.414 KB 3 rows
. . imported "ITS"."BBB" 5.828 KB 4 rows
. . imported "ITS"."CCC" 5.398 KB 1 rows
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Job "ITS"."SYS_IMPORT_SCHEMA_01" completed with 1 error(s) at 01:04:52
】
十、启动AB的OGG
启动211、212的OGG服务:
211.B:
$ cd /u01/ogg
[[email protected] ogg]$ ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Apr 23 2012 08:32:14
Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
GGSCI (HTogg1) 1> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER STOPPED
REPLICAT STOPPED REPL01 00:00:00 01:28:38
GGSCI (HTogg1) 2> start mgr
Manager started.
GGSCI (HTogg1) 3> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
REPLICAT RUNNING REPL01 00:00:00 00:00:01
212.A:
$ cd /u01/ogg
[[email protected] ogg]$ ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Apr 23 2012 08:32:14
Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
GGSCI (HTogg2) 1> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER STOPPED
EXTRACT STOPPED EXTR01 00:00:00 00:42:14
EXTRACT STOPPED PUMP01 00:00:00 00:41:57
GGSCI (HTogg2) 2> start mgr
Manager started.
GGSCI (HTogg2) 3> info all
Program Status Group Lag at Chkpt TimeSince Chkpt
MANAGER RUNNING
EXTRACT RUNNING EXTR01 00:42:25 00:00:01
EXTRACT RUNNING PUMP01 00:00:00 00:42:09
十一、测试
测试导入数据:
211:
$ $ORACLE_HOME/bin/sqlplus its/its
select count(*) from aaa;
select count(*) from bbb;
212:
$ $ORACLE_HOME/bin/sqlplus its/its
select count(*) from aaa;
select count(*) from bbb;
比较一样OK
在测试环境以下测试都通过,生产环境请忽略以下测试!!:
A212:
create table ccc(a varchar(2),n varchar(2));
insert into ccc values(‘aa‘,‘bb‘);
create table bb2(a varchar(2),n varchar(2), PRIMARY KEY ( a ));
insert into bb2 values(‘aa‘,‘bb‘);
insert into bb2 values(‘a1‘,‘b1‘);
insert into bb2 values(‘a2‘,‘b2‘);
insert into bb2 values(‘a3‘,‘b3‘);
insert into bb2 values(‘a4‘,‘b4‘);
commit;
ALTER TABLE aaa ADD cc varchar2(4) default ‘zz‘;
ALTER TABLE bbb ADD cc varchar2(4) default ‘zz‘;
alter table aaa rename column cc to dd;
alter table bbb modify cc varchar2(3) default ‘x4‘;
insert into bbb values(‘aa‘,‘bb‘,‘xx‘);
commit;
delete from bbb where cc=‘zz‘;
commit;
update bbb set a=‘az‘;
commit;
insert into bbb values(‘a1‘,‘bb‘,‘xx‘);
insert into bbb values(‘a2‘,‘bb‘,‘xx‘);
insert into bbb values(‘a3‘,‘bb‘,‘xx‘);
commit;
truncate table bbb;
insert into bbb values(‘a1‘,‘bb‘,‘xx‘);
insert into bbb values(‘a2‘,‘bb‘,‘xx‘);
commit;
drop table bbb;
create table bbb(a varchar(2),n varchar(2),cc varchar2(3), PRIMARY KEY ( a ));
insert into bbb values(‘a1‘,‘bb‘,‘xx‘);
insert into bbb values(‘a2‘,‘bb‘,‘xx‘);
commit;
CREATE INDEX nIndex ON bbb (n,cc desc);
drop index nIndex;
select INDEX_NAME, TABLE_NAME from user_indexes;