OGG RAC模式单向复制

1、创建spilfle 备份?

create pfile='pfile_20150416' from spfile;

2、配置归档格式

alter system set log_archive_format='%t_%s_%r.arc' scope=spfile;

3、开启归档
节点1

SQL> alter system set log_archive_dest_1='location=/eip_arch1' sid='cwmdb1';
SQL> alter system set log_archive_dest_1='location=/eip_arch2' sid='cwmdb2';

关闭两个节点

shutdown immediate

然后分别将两个节点开启到mount模式

SQL> startup mount

节点1

SQL> alter database archivelog;
SQL> alter database open;

节点2

SQL> alter database open;

4、切换归档测试

alter system switch logfile;

环境说明:
数据同步源端: 操作系统:linux x86 64位,数据库版本 ORACLE 11.2.0.4 ,OGG版本:12.2.0.1
数据同步目标端:
操作系统:linux x86 64位,
数据库版本 ORACLE 11.2.0.4 ,
OGG版本:12.2.0.1

需要同步的表名:
序号 源系统 源用户 源表 目的用户 目标系统 目的表 备注
1 资产 "LCAM_SC " DM_TPV_SUBSTATION GG_LCAM_SC 决策支持 DM_TPV_SUBSTATION
2、资源申请(现有可忽略)
2.1、操作系统
申请在10.150.145.xxx、10.150.145.xxx、10.150.145.xxx新建用户ggs,三个节点用户uid一致,并且加入oinstall用户组
2.2、存储
申请300G磁盘空间,挂载在10.150.145.xxx的 /eam_ggs 目录,目录权限ggs:oinstall 644
源端操作:
2.3、在源端数据库开启强制日志重启操作系统

	alter database force logging; --开启强制日志不需要重启								
	alter database add supplemental log data; --开启最小附加日志模式 ------								
	select log_mode,supplemental_log_data_min,force_logging from v$database; --验证是否开启数据库归档,附件日志,务必请先开数据库归档。								

3、部署golden gate 12c (如现有可忽略)

3.1、设置环境变量

设置PATH和LD_LIBRARY_PATH环境变量:
将goldengate的安装目录加入到PATH变量里,同时将该安装目录也加入到LD_LIBRARY_PATH变量中。
这里有一点需要注意,在编辑LD_LIBRARY_PATH环境变量之前,需要确保oracle数据库库文件目录已经存在于该环境变量中,如果没有则需要将该目录加上,如:

export PATH								
	export ORACLE_BASE=/u01/app/oracle								
	export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1								
	export ORA_GRID_HOME=/u01/app/grid_home/								
	export OGG_HOME=/eam_ggs/ggs								
	export ORACLE_OWNER=gzodb								
	export ORACLE_SID=eam								
	export NLS_LANG=american_america.zhs16gbk								
	export PATH=$PATH:$ORACLE_HOME/bin:$ORA_GRID_HOME/bin:/sbin:/usr/sbin:/bin:/usr/local/bin:$OGG_HOME								
	export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib:$ORACLE_HOME/lib32:/lib:/usr/lib:$ORACLE_HOME/rdbms/lib:$OGG_HOME								
	export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$ORACLE_HOME/network/jlib	

3.3、创建临时表,以便进行语句生成

create table GGS (owner varchar2(255),table_name varchar2(255));

3.4、将要同步的表 OWNER 及 TABLE NAME 插入 GGS 表

* 用上面生成的语句即可								

3.5、确定对象类型,是表而不是视图、同义词(注意替换 DB_LINK 名称)

select owner,object_name,object_type from dba_objects@sjzy1 where (owner,object_name) in (select owner,table_name from ggs);								
col owner for a30								
col table_name for a30								
col object_type for a30								
set line 300 pages 999								
select g.owner,g.table_name,o.object_type from ggs g left join dba_objects@sjzy1 o on o.owner=g.owner and o.object_name=g.table_name;						
序号	源系统	源用户	源表	目标系统	目的用户	目的表	历史删除记录表	备注
10								
17								
24								

3.6、表属性确认

有主键表								
set colsep ','
col rownum for 9999								
select rownum,owner,table_name from GGS where (UPPER(TRIM(owner)) , UPPER(TRIM(table_name))) in (select owner,table_name from dba_constraints@sjzy1 where constraint_type in ('P','U')) or (UPPER(TRIM(owner)) , UPPER(TRIM(table_name))) in (select owner,table_name from dba_indexes@sjzy1 where UNIQUENESS ='UNIQUE');					
								
ROWNUM	OWNER		TABLE_NAME						
 1      LCAM_SC		DM_TPV_SUBSTATION						
 2								
 3								
								
无主键表								
"set colsep ','"								
col rownum 9999								
"select rownum,owner,table_name from GGS "								
"  where (UPPER(TRIM(owner)) , UPPER(TRIM(table_name))) not in (select owner,table_name from dba_constraints@sjzy1 where constraint_type in ('P','U'))"								
"     and (UPPER(TRIM(owner)) , UPPER(TRIM(table_name))) not in (select owner,table_name from dba_indexes@sjzy1 where UNIQUENESS ='UNIQUE');"								
								
ROWNUM	"OWNER			 "	TABLE_NAME						
"	 1"								

3.7、附加日志确认

未添加附加日志								
"select rownum,owner,table_name from GGS where (RTRIM(LTRIM(upper(owner),' '),' '),RTRIM(LTRIM(upper(table_name),' '),' ')) not in (select owner,table_name from dba_log_groups@sjzy1);"								
ROWNUM	"OWNER			 "	TABLE_NAME						
"	 1"	"LCAM_SC			"	DM_TPV_SUBSTATION						
"	 2"								
"	 3"								
"	 4"								

3.8、日志模式检查(确认 LOG_MODE 为归档模式,SUPPLEMENTAL_LOG_DATA_MIN、 FORCE_LOGGING 为 YES)

select log_mode,supplemental_log_data_min,force_logging from v$database;
LOG_MODE    	SUPPLEME	FOR						
ARCHIVELOG  	YES     	YES						
								


3.9、创建GoldenGate用户帐号(源端)		

					
--确认								
select username from dba_users where username='S_GG';								
USERNAME								
S_GG								
								
--创建								
create user s_gg identified by "sgg_123" ;								
grant connect,resource,create session, alter session to s_gg;
grant select any dictionary, select any table,create table to s_gg;
grant alter any table to s_gg;  								
grant ALTER SYSTEM to s_gg;								
grant execute on utl_file to s_gg;								
grant flashback any table to s_gg;								
grant execute on dbms_flashback to s_gg;								
grant select any transaction  to s_gg;								
exec DBMS_GOLDENGATE_AUTH.GRANT_ADMIN_PRIVILEGE ('S_GG'); 								
--如果同步ddl和序列需要授予DBA权限								

3.10、UNDO 设置(根据官方文档来)

UNDO_MANAGEMENT=AUTO								
UNDO_RETENTION=86400 --根据具体的需要进行评估								

3.11、使用集成模式抽取数据,需要设置STREAMS_POOL_SIZE大小。

ALTER SYSTEM SET streams_pool_size=1024m scope = both; 								

3.12、开启数据库参数,以支持Integrated Capture

ALTER SYSTEM SET ENABLE_GOLDENGATE_REPLICATION = TRUE SCOPE=BOTH;								

3.13、数据库账号口令加密

"GGSCI (mmgl-2 as s_gg@mmgl2) 25> encrypt password qwe1575!rty,ENCRYPTKEY default"								
Using Blowfish encryption with DEFAULT key.								
Encrypted password:  AACAAAAAAAAAAALAYHBBHIZIKBNBNCXAYHUEFJPDBEDJKDUB								
Algorithm used:  BLOWFISH								
								
登陆验证								
dblogin USERID s_gg password AACAAAAAAAAAAALAYHBBHIZIKBNBNCXAYHUEFJPDBEDJKDUB, encryptkey default
或者
dblogin USERID s_gg, password AACAAAAAAAAAAALAYHBBHIZIKBNBNCXAYHUEFJPDBEDJKDUB, encryptkey default

3.14、添加附加日志

"从ggsci登陆,可从配置文件中使用加密过的 key 登录"								
"dblogin USERID s_gg password AACAAAAAAAAAAALAGDQCEGSIEHIJPCMBQHEHEGRGZFZBFBZA, encryptkey default"								
dblogin USERID s_gg password qwe1575!rty								
添加附加日志								
col ADD_TRANDDATA_STATEMENT_FORGGS for a150								
"select 'add trandata '||owner||'.'||table_name as ADD_TRANDDATA_STATEMENT_FORGGS from GGS where (RTRIM(LTRIM(upper(owner),' '),' '),RTRIM(LTRIM(upper(table_name),' '),' ')) not in (select owner,table_name from dba_log_groups);"								
								
ADD_TRANDDATA_STATEMENT_FORGGS								
------------------------------------------------------------------------------------------------------------------------------------------------------								
add trandata LCAM_SC.DM_TPV_SUBSTATION ALLCOLS								
								
								
* 添加后按照 3.7 再次确认是否已经正常添加表级别附加日志								

3.15、生成文件(抽取进程、投递进程同步清单)

set pages 9999 linesize 30000 long 50000 longc 99999								
set echo off feedback off heading on termout off trimout off								
set markup html on spool on pre off entmap off								
spool table_column_list.html								
"select 'TABLE  '||b.owner||'.'||b.TABLE_NAME||', COLS ('||WMSYS.wm_concat(b.column_name)||');' as MAP_TABLE_COLUMN_FOR_GGS from GGS a, dba_tab_columns@sjzy1 b "								
"where  RTRIM(LTRIM(upper(a.owner),' '),' ')=b.owner and RTRIM(LTRIM(upper(a.table_name),' '),' ')=b.table_name group by b.owner,b.table_name;"								
spool off								
MAP_TABLE_COLUMN_FOR_GGS								
								
【如需按表字段同步,如无此需要,请忽略】								
"TABLE LCAM_SC.DM_TPV_SUBSTATION, COLS (ID,PROVINCE_CODE,DATA_FROM,UPDATE_TIME,OPTIMISTIC_LOCK_VERSION,SITE_DESIGN,FLOOD_HIGHEDT,FLOOD_HUNDRED_YEAR,ICE_CLASSIFICATION,THUNDER_RISK_GRADE,CLOUD_TO_GROUND_FALSH,WIND_SPPED_FIFTY_YEAR,WIND_SPPED_THIRTY_YEAR,ALTERNATE_LINE,POWER_LINE,CONTACT_PHONE,CONTACT_PERSO,IS_RING,RUNMANAGE_DEP_ID,MAINNET_ID,MAINNET_CODE,INTERVAL_NUMS,BUS_SECTION,MARKETING_NUMBER,CAPACITY_CONSTITUTE,SEISMIC_INTENSITY,COASTAL_ALTITUDE,COMMUNICATIONS_OVERLAY,REACTOR_RC,CAPACITOR_COMPENSATE_CAPACITY,OUTLET_COUNT_10KV,OUTLET_COUNT_20KV,OUTLET_COUNT_35KV,OUTLET_COUNT_110KV,OUTLET_COUNT_220KV,OUTLET_COUNT_500KV,CONNECTION_MODE,ELECTRICAL_INSTAL_COMPANY,DUTY_TYPE,CONTROL_CENTER,OWNER_AREA,CONTROL_TYPE,DIRTINESS_AREA_LEVEL,PROPRIETOR_COMPANY_OID,PROPRIETOR_COMPANY_ONAME,BUILDER_COMPANY,DESIGNED_COMPANY,ADDRESS,CENTER_SUBSTATION_NAME,CENTER_SUBSTATION_ID,SUB_TYPE,TYPE,TRANSFORMER_NUMBER,TRANSFORMER_CAPACITY,INPUT_COUNT,OUTPUT_COUNT,BUREAU_CODE); "								
								
【按表同步】		
vi  /zc_ggs/ggs/dirprm/e_eam.obey
=====================================
TABLE LCAM_SC.DM_TPV_SUBSTATION;											
								
将上面的 TABLE 及 CLOUMN 添加到 obey 文件中								

3.16、配置MGR进程

edit params mgr								
								
PORT 7810								
DYNAMICPORTLIST 7810-7820								
AUTORESTART ER *,RETRIES 3, WAITMINUTES 5, RESETMINUTES 30							
LAGREPORTMINUTES 10								
LAGCRITICALMINUTES 10								
PURGEOLDEXTRACTS /zc_ggs/ggs/dirdat/*, USECHECKPOINTS, MINKEEPHOURS 48
USERID s_gg password AACAAAAAAAAAAALAGDQCEGSIEHIJPCMBQHEHEGRGZFZBFBZA, encryptkey default

3.17、配置抽取进程

edit params e_eam								
								
添加配置								
extract e_eam								
USERID s_gg password AACAAAAAAAAAAALAGDQCEGSIEHIJPCMBQHEHEGRGZFZBFBZA, encryptkey default
								
gettruncates								
nocompressdeletes								
								
discardfile G:\eam_ggs\dirrpt\e_eam.dsc, append, megabytes 1000
discardrollover at 3:00								
								
								
fetchoptions nousesnapshot								
								
--tranlogoptions rawdeviceoffset 0								
tranlogoptions dblogreader								
CACHEMGR CACHESIZE 1024MB								
exttrail G:\eam_ggs\dirdat\ea								
								
numfiles 4000								
dynamicresolution								
								
OBEY  G:\eam_ggs\dirprm\e_eam.obey								
BR BRINTERVAL 30M																

3.18、添加抽取进程(RAC)

ADD EXTRACT e_eam, tranlog, threads 2,BEGIN NOW

3.18、添加抽取进程(not RAC)

ADD EXTRACT e_eam, tranlog,BEGIN NOW

3.19、创建本地trail文件(从官方解释来看,这一步其实是声明,从哪个队列文件开始)

add exttrail G:\eam_ggs\dirdat\ea, extract e_eam

3.20、抽取进程注册

REGISTER EXTRACT e_eam DATABASE 								

3.21、配置投递进程

有主键								
edit params  d_eam								
								
配置文件								
extract d_eam								
USERID s_gg password AACAAAAAAAAAAALAGDQCEGSIEHIJPCMBQHEHEGRGZFZBFBZA, encryptkey default							
rmthost 10.124.250.75, mgrport 7809
rmttrail /usr/lib/ogg12.3_bigdata/dirdat/EVS/ea								
								
nopassthru								
--passthru								
dynamicresolution								
								
OBEY  G:\eam_ggs\e_eam.obey								

3.22、添加投递进程

add extract d_eam,exttrailsource G:\eam_ggs\dirdat\ea

3.23、创建远程trail文件

add rmttrail  /usr/lib/ogg12.3_bigdata/dirdat/EVS/ea,EXTRACT d_eam, megabytes 100

3.23、启动进程

./ggsci								
start e_eam								
alter d_eam begin now								
start d_eam								
								
								
目标端配置:					

3.24、如果ogg抽不到归档日志会报OGG-00446错误,可以设置重新抽取。

alter extract e_eam,begin now
	3.24、生成数据表定义文件		
	a. 生成DEF文件		
	vi /yx_ggs/ggs/dirprm/xcjk_def.prm		
	DEFSFILE /yx_ggs/ggs/dirdef/xcjk.def		
	USERID s_gg password AACAAAAAAAAAAALAYHBBHIZIKBNBNCXAYHUEFJPDBEDJKDUB, encryptkey default		
	obey /yx_ggs/ggs/dirdef/xcjk_def.obey		
			
			
	b. 编辑 def所要使用obey		
	select 'table '||owner||'.'||table_name||';' from ggs;		
			
	vi /yx_ggs/ggs/dirdef/xcjk_def.obey		
			
	table LCAM_SC.DM_TPV_SUBSTATION;		
			
			
			
	b. GGHOME用defgen生成定义文件		
			
	mv /dump/yxyj_ggs/ggs12_1/dirdef/bos4gz.def /dump/yxyj_ggs/ggs12_1/dirdef/bos4gz.def.20180907		
	./defgen paramfile /dump/yxyj_ggs/ggs12_1/dirdef/bos4gz_def.prm NOEXTATTR 		
	--NOEXTATTR 由于目标端是GG 11.2,所以才要加这个兼容性的参数		

3.25、把生成dirdef文件copy到目标端复制进程的dirdef目录下

	scp /dump/yxyj_ggs/ggs12_1/dirdef/bos4gz.def [email protected]:/dw_ggt/ggt12/dirdef/bos4gz.def		

3.26、复制进程配置

	edit params r_xcjk.prm		
			
	正常同步		
	REPLICAT r_xcjk		
			
	SETENV (ORACLE_HOME = "/oracle/app/oracle/product/11.2.0/db" )		
	SETENV (ORACLE_SID = "gzdw1")		
	--SETENV (NLS_LANG = "AMERICAN_AMERICA.ZHS16GBK")		
			
	USERID t_gg, password AACAAAAAAAAAAALAYHBBHIZIKBNBNCXAYHUEFJPDBEDJKDUB, encryptkey default		
			
	gettruncates		
			
	SQLEXEC "ALTER SESSION SET COMMIT_WRITE = NOWAIT"		
	SQLEXEC "ALTER SESSION SET CONSTRAINTS = DEFERRED"		
			
	checksequencevalue		
			
	report at 05:59		
	reportrollover at 06:00		
	--reperror default,discard		
	--reperror 01653, abend		
	--reperror 01654, abend		
			
			
	discardfile /dw_ggt/ggt/dirrpt/r_xcjk.dsc, append, megabytes 1000		
	discardrollover at 6:00		
			
	numfiles 4000		
	sourcedefs /dw_ggt/ggt/dirdef/xcjk.def		
	dynamicresolution		
	allownoopupdates		
	grouptransops 1000		
			
	--batchsql batchesperqueue 100, opsperbatch 8000		
	HANDLECOLLISIONS		
	OBEY  /dw_ggt/ggt/dirprm/r_xcjk.obey		
			
			
	edit params  r_xcjk_de.prm		
	保存delete的记录		
			
	REPLICAT r_xcjk_de		
			
	SETENV (ORACLE_HOME = "/oracle/app/oracle/product/11.2.0/db" )		
	SETENV (ORACLE_SID = "gzdw1")		
	--SETENV (NLS_LANG = "AMERICAN_AMERICA.ZHS16GBK")		
			
	USERID t_gg, password AACAAAAAAAAAAALAYHBBHIZIKBNBNCXAYHUEFJPDBEDJKDUB, encryptkey default		
			
	gettruncates		
	ignoreupdates		
	ignoreinserts		
	insertdeletes		
			
	SQLEXEC "ALTER SESSION SET COMMIT_WRITE = NOWAIT"		
	SQLEXEC "ALTER SESSION SET CONSTRAINTS = DEFERRED"		
			
	checksequencevalue		
			
	report at 05:59		
	reportrollover at 06:00		
	--reperror default,discard		
	--reperror 01653, abend		
	--reperror 01654, abend		
			
			
	discardfile /dw_ggt/ggt/dirrpt/r_xcjk_de.dsc, append, megabytes 1000		
	discardrollover at 6:00		
			
	numfiles 4000		
	sourcedefs /dw_ggt/ggt/dirdef/xcjk.def		
	dynamicresolution		
	allownoopupdates		
	grouptransops 1000		
			
	--batchsql batchesperqueue 100, opsperbatch 8000		
	OBEY  /dw_ggt/ggt/dirprm/r_xcjk_de.obey		
			
			
			
	3.27、复制进程obey生成语句(如果无主键或者唯一索引,需要使用keycols);另外,在新增部分表的同步需求且这部分的表使用 DataPump 同步时,需要在后面添加“,filter (@GETENV ("TRANSACTION", "CSN")>15096755995148);” 做复制,CSN 为使用 DataPump 导出时源库的 SCN		
	vi /dw_ggt/ggt/dirprm/r_xcjk.obey		
	有主键		
	set pages 9999 linesize 30000 long 50000 longc 99999		
	set echo off feedback off heading on termout off trimout off		
	set markup html on spool on pre off entmap off		
	spool pk_table_column_list.html		
	select 'MAP  '||owner||'.'||table_name||',  TARGET GG_'||owner||'.'||table_name||', COLMAP ( usedefaults , ods_op_type = @GETENV ("GGHEADER", "OPTYPE") , ods_s_date =  @GETENV ( "GGHEADER" , "COMMITTIMESTAMP" ),ods_t_date = @DATENOW()),filter (@GETENV ("TRANSACTION", "CSN")>99999999999999);' 		
	  from GGS 		
	where (UPPER(TRIM(owner)) , UPPER(TRIM(table_name))) in (select owner,table_name from dba_constraints@sjzy1 where constraint_type in ('U','P'))		
	   or (UPPER(TRIM(owner)) , UPPER(TRIM(table_name))) in (select owner,table_name from dba_indexes@sjzy1 where UNIQUENESS ='UNIQUE');		
	spool off;		
			
			
			
	MAP LCAM_SC.DM_TPV_SUBSTATION, TARGET GG_LCAM_SC.DM_TPV_SUBSTATION, COLMAP ( usedefaults , ods_op_type = @GETENV ("GGHEADER", "OPTYPE") , ods_s_date = @GETENV ( "GGHEADER" , "COMMITTIMESTAMP" ),ods_t_date = @DATENOW()),filter (@GETENV ("TRANSACTION", "CSN")>15168604884253);		
			
			
			
			
	firefox pk_table_column_list.html		
	rm pk_table_column_list.html		
			
	无主键		
	set pages 9999 linesize 30000 long 50000 longc 99999		
	set echo off feedback off heading on termout off trimout off		
	set markup html on spool on pre off entmap off		
	spool nopk_table_column_list.html		
	select  'MAP  '||b.owner||'.'||b.table_name||',  TARGET  GG_'||b.owner||'.'||b.table_name||', COLMAP ( usedefaults , ods_op_type = @GETENV ("GGHEADER", "OPTYPE") , ods_s_date =  @GETENV ( "GGHEADER" , "COMMITTIMESTAMP" ),ods_t_date = @DATENOW()), KEYCOLS ('||WMSYS.wm_concat(b.column_name)||'),filter (@GETENV ("TRANSACTION", "CSN")>99999999999999);' 		
	  from GGS a, dba_tab_columns@sjzy1 b 		
	where UPPER(TRIM(a.owner))=b.owner 		
	  and UPPER(TRIM(a.table_name))=b.table_name 		
	  and ((b.owner , b.table_name) not in (select owner,table_name from dba_constraints@sjzy1 where constraint_type in ('U','P'))		
	   and (b.owner,b.table_name) not in (select owner,table_name from dba_indexes@sjzy1 where UNIQUENESS ='UNIQUE'))		
	  group by b.owner,b.table_name;		
	spool off;		
			
			
			
			
			
	firefox nopk_table_column_list.html		
	rm nopk_table_column_list.html		
			
	vi /dw_ggt/ggt/dirprm/r_xcjk_de.obey		
	有主键		
	set pages 9999 linesize 30000 long 50000 longc 99999		
	set echo off feedback off heading on termout off trimout off		
	set markup html on spool on pre off entmap off		
	spool pk_table_del_column_list.html		
	select 'MAP  '||owner||'.'||table_name||',  TARGET  GG_'||owner||'.'||substr(table_name,1,26)||'_DEL, COLMAP ( usedefaults , ods_op_type = @GETENV ("GGHEADER", "OPTYPE") , ods_s_date =  @GETENV ( "GGHEADER" , "COMMITTIMESTAMP" ),ods_t_date = @DATENOW()),filter (@GETENV ("TRANSACTION", "CSN")>99999999999999);' from GGS 		
	where (UPPER(TRIM(owner)) , UPPER(TRIM(table_name))) in (select owner,table_name from dba_constraints@sjzy1 where constraint_type in ('U','P'))		
	   or (UPPER(TRIM(owner)) , UPPER(TRIM(table_name))) in (select owner,table_name from dba_indexes@sjzy1 where UNIQUENESS ='UNIQUE');		
	spool off;		
			
			
			
			
	MAP LCAM_SC.DM_TPV_SUBSTATION, TARGET GG_LCAM_SC.DM_TPV_SUBSTATION_DEL, COLMAP ( usedefaults , ods_op_type = @GETENV ("GGHEADER", "OPTYPE") , ods_s_date = @GETENV ( "GGHEADER" , "COMMITTIMESTAMP" ),ods_t_date = @DATENOW()),filter (@GETENV ("TRANSACTION", "CSN")>15168604884253);		
			
			
			
			
			
	firefox pk_table_del_column_list.html		
	rm pk_table_del_column_list.html		
			
			
	无主键		
	set pages 9999 linesize 30000 long 50000 longc 99999		
	set echo off feedback off heading on termout off trimout off		
	set markup html on spool on pre off entmap off		
	spool nopk_table_del_column_list.html		
	select  'MAP  '||b.owner||'.'||b.table_name||',  TARGET  GG_'||b.owner||'.'||substr(b.table_name,1,26)||'_DEL, COLMAP ( usedefaults , ods_op_type = @GETENV ("GGHEADER", "OPTYPE") , ods_s_date =  @GETENV ( "GGHEADER" , "COMMITTIMESTAMP" ),ods_t_date = @DATENOW()), KEYCOLS ('||WMSYS.wm_concat(b.column_name)||'),filter (@GETENV ("TRANSACTION", "CSN")>99999999999999);' from GGS a, dba_tab_columns@sjzy1 b 		
	where UPPER(TRIM(a.owner))=b.owner 		
	  and UPPER(TRIM(a.table_name))=b.table_name 		
	  and ((b.owner , b.table_name) not in (select owner,table_name from dba_constraints@sjzy1 where constraint_type in ('U','P'))		
	   and (b.owner,b.table_name) not in (select owner,table_name from dba_indexes@sjzy1 where UNIQUENESS ='UNIQUE'))		
	  group by b.owner,b.table_name;		
	spool off;		
			
			
			
			
			
			
			
	firefox nopk_table_del_column_list.html		
	rm nopk_table_del_column_list.html		

3.28、添加复制进程

	add replicat r_cw,exttrail /dw_ggt/ggt/dirdat/cw/cw		
	add replicat r_cw_d,exttrail /dw_ggt/ggt/dirdat/cw/cw		

3.29、创建目标端存放数据用户

	create user GG_IT_MEET identified by "GG_IT_MEET#123" default tablespace TS_GG_ODS_OT;		
	grant  connect,resource to GG_IT_MEET;		

3.30、创建DBLINK

	create public database link to_cw connect to s_gg identified by "qwe1575!rty" using '(DESCRIPTION = (ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 10.150.145.xxx)(PORT = 1621)))(CONNECT_DATA =(SERVICE_NAME = CWPLUS)))';		

3.31、导出初始数据

	此时源端的scn		
	col CURRENT_SCN for 99999999999999		
	select current_scn from v$database;		
	    CURRENT_SCN		
	---------------		
	15168604884253		
			
	 导数脚本(数据量较小,使用DBLNK进行远程导数)		
	--查询对象所在表空间做 REMAP		
	select s.tablespace_name,sum(s.bytes)/1024/1024/1024 GB from ggs g left join dba_segments@sjzy1 s on g.owner=s.owner and g.table_name=s.segment_name group by s.tablespace_name;		
	select s.tablespace_name,sum(s.bytes)/1024/1024/1024 GB from  		
	 (select s.owner,s.tablespace_name,s.INDEX_NAME from dba_indexes s,ggs g where g.owner=s.owner(+) and g.table_name=s.table_name(+)) i		
	 left join dba_segments s on s.owner=i.owner and i.index_name=s.segment_name		
	group by s.tablespace_name;		
			
	TABLESPACE_NAME	"		"	GB
	------------------------------	----------	
			
	"LCAM_SC_DATA		"	0.059265137	
	"LCAM_ZC_DATA			"	0.33996582	
			
	-- 查询所要用的 DB_LINK 名字		
	set line 300 pages 99		
	col db_link for a30		
	col host for a100		
	select db_link,host from dba_db_links where db_link like '%TO%';		
			
	Directory_Name=DAOSHU DIRECTORY_PATH=/dw_ggt/daoshu		
			
	impdp \'\/ as sysdba\'  parfile=/dw_ggt/daoshu/impdp_zc_20161108.par		
			
	vi /dw_ggt/daoshu/impdp_zc_20161108.par		
			
	tables=(		
	LCAM_SC.DM_TPV_SUBSTATION		
	)		
	REMAP_SCHEMA=LCAM_ZC:GG_LCAM_ZC,LCAM_SC:GG_LCAM_SC		
	REMAP_TABLESPACE=(		
	LCAM_SC_DATA:TS_GG_ODS_LCAM,LCAM_ZC_DATA:TS_GG_ODS_LCAM		
	)		
	network_link=OGG_TO_xcjk		
	EXCLUDE=statistics,trigger,GRANT		
	directory=DAOSHU		
	FLASHBACK_SCN=15168604884253		
	logfile=impdp_zc_20161108.log		

3.32、禁用外键(如果存在)

	select 'alter table GG_'|| t.owner||'.'|| t.table_name||' disable constraint '||t.constraint_name||';'  from dba_constraints@sjzy1 t,ggs s where t.constraint_type = 'R' and t.owner=s.owner and t.table_name=s.table_name;		
			
			
			
	3.33、增加字段		
	set pagesize 5000		
	set line 200		
	select 'alter table GG_'||owner||'.'||table_name||' add ods_op_type varchar2(50);'||chr(10)||'alter table GG_'||owner||'.'||table_name||' add ods_s_date timestamp;'||chr(10)||'alter table GG_'||owner||'.'||table_name||' add ods_t_date timestamp;' from ggs;		
			
	alter table GG_LCAM_SC.DM_TPV_SUBSTATION add ods_op_type varchar2(50);		
	alter table GG_LCAM_SC.DM_TPV_SUBSTATION add ods_s_date timestamp;		
	alter table GG_LCAM_SC.DM_TPV_SUBSTATION add ods_t_date timestamp;		
			
			
			
			
	-- 检查是否增加完毕		
	select table_name,count(1) from dba_tab_columns where owner in ('GG_LCAM_ZC','GG_LCAM_SC') and column_name in ('ODS_OP_TYPE','ODS_S_DATE','ODS_T_DATE') having count(1) < 3 group by table_name;		

3.34、创建存放delete数据的表

	set line 200		
	select 'create table GG_'||owner||'.'||substr(table_name,1,26)||'_DEL as select * from GG_'||owner||'.'||table_name||' where 1=2;'   from ggs ;		
			
	create table GG_LCAM_SC.DM_TPV_SUBSTATION_DEL as select * from GG_LCAM_SC.DM_TPV_SUBSTATION where 1=2;		
			
			
	--检查		
	select count(1) from dba_objects where owner in ('GG_LCAM_ZC','GG_LCAM_SC') and object_type='TABLE' and object_name like '%_DEL' and created >= to_date('20160922','yyyymmdd');		

3.35、启动复制进程

	stop replicat r_xcjk		
	stop replicat r_xcjk_de		
			
	start replicat r_xcjk		
	start replicat r_xcjk_de		
			
			
	使用 info all 查看进程状态,为 ABENDED 代表有问题		
	使用 stats r_xcjk 及 stats r_xcjk_de 查看进程复制记录数		

你可能感兴趣的:(oracle,ogg安装,oracle,三朝看客)