2、为ogg创建目录
mkdir /home/oracle/ogg
unzip p22575475_1121032_Linux-x86-64.zip
mv fbo_ggs_Linux_x64_ora11g_64bit.tar /home/oracle/ogg/
cd /home/oracle/ogg
tar -xvf fbo_ggs_Linux_x64_ora11g_64bit.tar
3、创建子目录--注意存储规划
cd /home/oracle/ogg
./ggsci
GGSCI (test) 1> create subdirs
Creating subdirectories under current directory /home/oracle/ogg
Parameter files /home/oracle/ogg/dirprm: already exists
Report files /home/oracle/ogg/dirrpt: created --存放report文件
Checkpoint files /home/oracle/ogg/dirchk: created --存放checkpoint 文件
Process status files /home/oracle/ogg/dirpcs: created
SQL script files /home/oracle/ogg/dirsql: created
Database definitions files /home/oracle/ogg/dirdef: created
Extract data files /home/oracle/ogg/dirdat: created --存放trc文件,占用空间最大
Temporary files /home/oracle/ogg/dirtmp: created
Stdout files /home/oracle/ogg/dirout: created
二、ogg 准备阶段
1、配置数据库用户--两端都做
create tablespace tbs_ogg datafile '/home/oracle/oradata/ora11g/tbs_ogg01.dbf' size 100m autoextend on;
create user ogg identified by ogg default tablespace tbs_ogg;
grant dba,connect to ogg;
2、配置数据库日志模式--只在源端
alter database force logging;
alter database add supplemental log data;
select supplemental_log_data_min from v$database;
3、关闭数据库回收站--源端(10g版本必须关闭,11g+建议)
purge dba_recyclebin;
alter system set recyclebin=off scope=spfile;
4、修改ogg参数--远端和目标端
alter system set enable_goldengate_replication=true ;
5、配置DDL复制--源端
vi $OGG_HOME/GLOBALS
--新增
GGSCHEMA OGG
--需要在$OGG_HOME目录下执行
--以下脚本会在OGG用户下面创建一些基础表
cd $OGG_HOME
sqlplus / as SYSDBA
@marker_setup
--Enter GoldenGate schema name :ogg
@ddl_setup
@role_setup.sql
grant ggs_ggsuser_role to ogg;
@ddl_enable.sql
--1> 获取并记录源生产库当前的 SCN 号
sqlplus / as sysdba
col CURRENT_SCN for 99999999999999
select current_scn as SCN1 from v$database;
--1024284
--2>当前系统是否存在长事务?
col START_SCN for 99999999999999
col SCHEMANAME for a20
col MACHINE for a20
select
p.INST_ID,p.SPID,s.sid,s.SERIAL#,p.username,s.SCHEMANAME,s.sql_id,t.start_scn,t.START_TIME,t.status,MACHINE
from gv$transaction t,gv$process p,gv$session s
where s.taddr=t.addr and p.addr=s.paddr and t.start_scn <= &SCN1;
--通用方式
set serveroutput on;
BEGIN
FOR i IN ( SELECT priv_user,job FROM dba_jobs where priv_user in('SCOTT'))
LOOP
dbms_job.broken(i.job,true);
END LOOP;
END;
/
BEGIN
FOR i IN ( SELECT table_owner,trigger_name,status FROM dba_triggers where table_owner in('SCOTT'))
LOOP
EXECUTE IMMEDIATE 'alter trigger ' ||i.table_owner||'.'|| i.trigger_name || ' disable';
END LOOP;
END;
/
BEGIN
FOR i IN ( SELECT owner,table_name,constraint_name,status,validated FROM dba_constraints WHERE owner IN ('SCOTT')
and constraint_type = 'R')
LOOP
EXECUTE IMMEDIATE 'alter table ' ||i.owner||'.'|| i.table_name || ' disable constraint ' || i.constraint_name;
END LOOP;
END;
/
create table scott.test_tmp2(
id number(12),
name varchar2(30),
age varchar2(10))
partition by range(age)
(partition p1 values less than (20),
partition p2 values less than (40),
partition p3 values less than (60),
partition p_other values less than (maxvalue))
enable row movement;
select * from scott.test_tmp2;
--2>DML 测试:
----INSERT测试
----源端
insert into scott.test_tmp values(1,'test1');
insert into scott.test_tmp values(2,'test2');
commit;
select * from scott.test_tmp;
--目标端
select * from scott.test_tmp;
--分区表
insert into scott.test_tmp2 values(01,'test01',18);
insert into scott.test_tmp2 values(02,'test02',28);
insert into scott.test_tmp2 values(03,'test03',58);
insert into scott.test_tmp2 values(04,'test04',68);
commit;
select * from scott.test_tmp2;
select * from scott.test_tmp2 partition(p1);
select * from scott.test_tmp2 partition(p2);
select * from scott.test_tmp2 partition(p3);
select * from scott.test_tmp2 partition(p_other);
----update测试
-----源端--普通表
update scott.test_tmp set name='test1111' where id =1;
update scott.test_tmp set name='test2222' where id =2;
commit;
select * from scott.test_tmp;
-----目标端
select * from scott.test_tmp;
-----源端---分区表
update scott.test_tmp2 set name='test100' where id=01;
update scott.test_tmp2 set age=19 where id=04;
commit;
----目标端查看
select * from scott.test_tmp2;
select * from scott.test_tmp2 partition(p1);
select * from scott.test_tmp2 partition(p2);
select * from scott.test_tmp2 partition(p3);
select * from scott.test_tmp2 partition(p_other);
----delete测试
---源端
delete from scott.test_tmp;
commit;
select * from scott.test_tmp;
--目标
select * from scott.test_tmp;
----分区表
delete scott.test_tmp2 where id=01;
commit;
select * from scott.test_tmp2;
select * from scott.test_tmp2 partition(p1);
select * from scott.test_tmp2 partition(p2);
select * from scott.test_tmp2 partition(p3);
select * from scott.test_tmp2 partition(p_other);
----DDL drop 测试:
--源端
drop table scott.test_tmp;
select * from scott.test_tmp;
--目标端
select * from scott.test_tmp;
=》分区表
drop table scott.test_tmp2;
select * from scott.test_tmp2;
----目标端如果遇到问题就会报错暂停同步:
GGSCI (orcl2) 1> info all
Program Status Group Lag at Chkpt Time Since Chkpt