SQL> select userenv('language') from dual;
USERENV('LANGUAGE')
----------------------------------------------------
AMERICAN_AMERICA.AL32UTF8
SQL>
--linux:
orapwd file=/oracle/app/oracle/product/12.1.0/dbhome_1/dbs/orapwtardb password=orcL#2016 entries=5 force=y;
scp 172.16.28.40:/oracle/app/oracle/product/12.1.0/dbhome_1/dbs/orapwtardb /home/oracle/app/oracle/product/12.1.0/db_1/dbs
shutdown immediate
startup mount
alter database archivelog;
alter database open;
archive log list;
启用自动归档
Alter system set log_archive_start=true scope=spfile
参看参数
SQL> show parameter cluster_database
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cluster_database boolean TRUE
cluster_database_instances integer 2
在一台主机上执行:
alter system set cluster_database=false scope=spfile sid='*';
在两台主机上执行:
shutdown immediate
在一台主机上执行:
startup mount(必需要等2台机器同时shutdown完毕即可)
alter database archivelog;
alter database open;
alter system set cluster_database=true scope=spfile sid='*';
shutdown immediate;
在两台主机上执行:
Startup
此时修改完毕即可启用归档,关闭归档方法类似。
vi initauxdb.ora
*.audit_file_dest='/home/oracle/app/oracle/admin/auxdb/adump'
*.audit_trail='db'
*.compatible='12.1.0.2.0'
*.control_files='/home/oracle/app/oracle/oradata/auxdb/control01.ctl','/home/oracle/app/oracle/oradata/auxdb/control02.ctl'
*.db_block_size=8192
*.db_name='auxdb'
db_file_name_convert=('+DATA','/home/oracle/app/oracle/oradata/','/oracle/app/oracle/oradata/oradb/','/home/oracle/app/oracle/oradata/oradb/')
log_file_name_convert=('+DATA','/home/oracle/app/oracle/fast_recovery_area/','+FLASH','/home/oracle/app/oracle/fast_recovery_area/')
mkdir -p auxdb/adump
mkdir -p auxdb/datafile
mkdir -p auxdb/tempfile
mkdir -p auxdb/tablespaces
mkdir -p auxdb/onlinelog
(SID_DESC =
(GLOBAL_DBNAME = auxdb)
(ORACLE_HOME = /home/oracle/app/oracle/product/12.1.0/db_1)
(SID_NAME = auxdb)
)
sqlplus / as sysdba
startup nomount pfile='/home/oracle/app/oracle/product/12.1.0/db_1/dbs/initauxdb.ora';
rman target sys/
[email protected]/tardb auxiliary sys/
[email protected]/auxdb
duplicate target database to auxdb from active database ;
duplicate target database to auxdb from active database nofilenamecheck;
ALTER system SET sga_max_size=8g scope=spfile;
ALTER system SET sga_target=5g scope=spfile;
alter system set shared_pool_size=2g scope=spfile;
alter system set open_cursors=1000 scope=both;
---------------------------------------------------------------------------------------------------
--ggs
---------------------------------------------------------------------------------------------------
-- source 、target 端执行
1.1 设置数据库为归档模式
数据库是否处于归档模式:
archive log list;
Select log_mode from v$database;
开启归档模式:
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
1.2 开启数据库附加日志
1) 检查附加日志情况
使用以下sql语句检查数据库附加日志的打开状况:
Select
SUPPLEMENTAL_LOG_DATA_MIN
,SUPPLEMENTAL_LOG_DATA_PK
,SUPPLEMENTAL_LOG_DATA_UI
,SUPPLEMENTAL_LOG_DATA_FK
,SUPPLEMENTAL_LOG_DATA_ALL from v$database;
2) 打开数据库附加日志
打开附加日志并切换日志(保证Online redo log和Archive log一致)
alter database add supplemental log data ;
alter database add supplemental log data (primary key, unique,foreign key) columns;
alter system switch logfile;
3) 确认附加日志情况
使用以下sql语句检查数据库附加日志的打开状况:
Select
SUPPLEMENTAL_LOG_DATA_MIN
,SUPPLEMENTAL_LOG_DATA_PK
,SUPPLEMENTAL_LOG_DATA_UI
,SUPPLEMENTAL_LOG_DATA_FK
,SUPPLEMENTAL_LOG_DATA_ALL from v$database;
注:确保最小附加日志,pk,uk,fk附加日志打开。而all columns的附加日志关闭;
如果all columns的附加日志打开的话,则需要使用以下语句予以关闭:
alter database drop supplemental log data (ALL) columns;
1.3 开启数据库强制日志模式
Alter database force logging;
注:该模式的打开需要和业务部门进行相关确认和讨论;如果数据库不能打开到force logging的模式下,则no logging的表无法进行同步;
1.4
alter system set enable_goldengate_replication=true;
1.5 创建运行GoldenGate的用户
1) 在源端采用ORACLE用户运行GoldenGate
2) 安装位置:/ogg
3) 创建GoldenGate数据库用户ggs
--create tablespace
create tablespace ggstab datafile '/oracle/app/oracle/oradata/oradb/goldengate02.dbf' size 1024M autoextend on;
create tablespace ggstab datafile '/home/oracle/app/oracle/oradata/oradb/goldengate02.dbf' size 1024M autoextend on;
-- Create the user
create user ggs identified by ggs default tablespace ggstab;
-- Grant role privileges
grant dba to ggs;
1.6 关闭数据库的recyclebin
查询当前recyclebin的参数值:
SQL> show parameter recyclebin
NAME TYPE VALUE
------------------------------------ ----------- -------------------
recyclebin string OFF
SQL>
如不是off,需要关闭recyclebin:
SQL>alter system set recyclebin=off scope=both;
SQL>alter system set recyclebin=off deferred scope=both;
1.7 建立OGG的DDL对象
sqlplus "/ as sysdba"
SQL> @marker_setup.sql
Enter GoldenGate schema name:ggs
SQL> @ddl_setup.sql
Enter GoldenGate schema name:ggs
SQL> @role_setup.sql
Grant this role to each user assigned to the Extract, Replicat, GGSCI, and Manager processes, by using the following SQL command:
GRANT GGS_GGSUSER_ROLE TO
where is the user assigned to the GoldenGate processes.
注意这里的提示:需要手工将这个GGS_GGSUSER_ROLE指定给extract所使用的数据库用户(即参数文件里面通过userid指定的用户),可以到sqlplus下执行类似的sql:
GRANT GGS_GGSUSER_ROLE TO ggs;
注:这里的goldengate是extract使用的用户。如果你有多个extract,使用不同的数据库用户,则需要重述以上过程全部赋予GGS_GGSUSER_ROLE权限。
安装sequence复制对象:
SQL> @sequence.sql
1.8 安装提升性能工具
本步骤为可选步骤,一般情况下建议运行该步骤。
为了提供OGG的DDL复制的性能,可以将ddl_pin脚本加入到数据库启动的脚本后面,该脚本需要带一个OGG的DDL用户(即安装DDL对象的用户,本例中是ggs)的参数:
SQL> @ddl_pin ggs
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- source
GGSCI >create subdirs
-- edit params ./GLOBALS
GGSCHEMA ggs
CHECKPOINTTABLE ggs.checkpoint
-- edit params mgr
PORT 7839
DYNAMICPORTLIST 7840-7914
USERID ggs, PASSWORD ggs
--AUTOSTART ER *
AUTORESTART EXTRACT *,RETRIES 5,WAITMINUTES 3
PURGEOLDEXTRACTS ./dirdat/*,usecheckpoints, minkeepdays 3
PURGEDDLHISTORY MINKEEPDAYS 7, MAXKEEPDAYS 10
PURGEMARKERHISTORY MINKEEPDAYS 7, MAXKEEPDAYS 10
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 4
--1 edit params extemr
EXTRACT extemr
setenv (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
--setenv (ORACLE_SID="tardb1")
USERID ggs@rac, PASSWORD ggs
tranlogoptions dblogreader
GETTRUNCATES
ddl include all
DDLOPTIONS NOCROSSRENAME REPORT
TRANLOGOPTIONS DBLOGREADER
TRANLOGOPTIONS INCLUDEREGIONID,EXCLUDEUSER ggs
ddloptions addtrandata, report
REPORTCOUNT EVERY 1 MINUTES, RATE
DISCARDFILE ./dirrpt/extemr.dsc,APPEND,MEGABYTES 1024
--THREADOPTIONS MAXCOMMITPROPAGATIONDELAY 60000 IOLATENS 60000
DBOPTIONS ALLOWUNUSEDCOLUMN
WARNLONGTRANS 2h,CHECKINTERVAL 300s
EXTTRAIL ./dirdat/em
FETCHOPTIONS NOUSESNAPSHOT
--TRANLOGOPTIONS CONVERTUCS2CLOBS
TABLE TEST.*;
--2 edit params dpemr
EXTRACT dpemr
PASSTHRU
RMTHOST 10.16.28.30, MGRPORT 7809, compress, PARAMS -w 30
RMTTRAIL ./dirdat/em
TABLE TEST.*;
--3 添加抽取/传输进程与队列文件
add ext extemr,tranlog ,begin 2016-10-01 15:30,THREADS 2
add exttrail ./dirdat/em,ext extemr,megabytes 200
add ext dpemr,exttrailsource ./dirdat/em
add rmttrail ./dirdat/em,ext dpemr,megabytes 200
添加OGG用户数据库检查点表:
dblogin userid ggs,password ggs
add checkpointtable ggs.checkpoint
--target
GGSCI >create subdirs
-- edit params ./GLOBALS
GGSCHEMA ggs
CHECKPOINTTABLE ggs.checkpoint
-- edit params mgr
PORT 7839
DYNAMICPORTLIST 7840-7914
USERID ggs, PASSWORD ggs
--AUTOSTART ER *
AUTORESTART EXTRACT *,RETRIES 5,WAITMINUTES 3
PURGEOLDEXTRACTS ./dirdat/*,usecheckpoints, minkeepdays 3
PURGEDDLHISTORY MINKEEPDAYS 7, MAXKEEPDAYS 10
PURGEMARKERHISTORY MINKEEPDAYS 7, MAXKEEPDAYS 10
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 4
--1 edit params repemr
REPLICAT repemr
setenv (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
setenv (ORACLE_SID="auxdb")
USERID ggs, PASSWORD ggs
DBOPTIONS NOSUPPRESSTRIGGERS
DDL include mapped
ddloptions report
REPORTCOUNT EVERY 30 MINUTES, RATE
--REPERROR DEFAULT, ABEND
REPERROR DEFAULT, DISCARD
--REPERROR (1, DISCARD)
--REPERROR (1403, DISCARD)
--HANDLECOLLISIONS
assumetargetdefs
DISCARDFILE ./dirrpt/repemr.dsc, APPEND, MEGABYTES 1024
GETTRUNCATES
ALLOWNOOPUPDATES
MAP HYEMR.*, TARGET HYEMR.*;
--2 添加OGG用户数据库检查点表:
dblogin userid ggs,password ggs
add checkpointtable ggs.checkpoint
添加replication进程:
add replicat repemr, exttrail ./dirdat/em
GGSCI > start mgr
GGSCI > start er *
GGSCI > info all
GGSCI > view report ext