1. 程式人生 > >Oracle Database 復制解決方案:Oracle GoldenGate

Oracle Database 復制解決方案:Oracle GoldenGate

scope class tab rest onf lur auto login erp

源端數據庫配置 [root@king01 ~]# su - oracle [oracle@king01 ~]$ sqlplus / as sysdba SQL> create tablespace goldengate datafile '/u01/app/oracle/oradata/king/ogg01.dbf' size 1024M; Tablespace created. SQL> create user ggs identified by ggs default tablespace goldengate; User created. SQL> grant dba to ggs; Grant succeeded. SQL> select log_mode from v$database; LOG_MODE ------------------------------------ ARCHIVELOG SQL> alter database force logging; Database altered. SQL> select force_logging from v$database; FORCE_LOGGING ------------------------------ YES SQL> alter database add supplemental log data; Database altered. SQL> col supplemental_log_data_min for a30 SQL> select supplemental_log_data_min from v$database; SUPPLEMENTAL_LOG_DATA_MIN ------------------------------ YES SQL> alter system set enable_goldengate_replication; SQL> alter system archive log current;


源端安裝OGG
[oracle@king01 ~]$ vi .bash_profile
export OGG_HOME=/u01/app/ogg
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export PATH=$OGG_HOME:$PATH
[oracle@king01 ~]$ source .bash_profile

[oracle@king01 ~]$ mkdir -p /u01/app/ogg
[oracle@king01 ~]$ unzip fbo_ggs_Linux_x64_shiphome.zip
[oracle@king01 ~]$ cd fbo_ggs_Linux_x64_shiphome/Disk1
[oracle@king01 Disk1]$ ./runInstaller


[oracle@king01 ~]$ cd /u01/app/ogg
[oracle@king01 ogg]$ ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 12.2.0.1.1 OGGCORE_12.2.0.1.0_PLATFORMS_151211.1401_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Dec 12 2015 00:54:38
Operating system character set identified as UTF-8.
Copyright (C) 1995, 2015, Oracle and/or its affiliates. All rights reserved.

GGSCI (king01) 1> create subdirs
Creating subdirectories under current directory /u01/app/ogg
Parameter files                /u01/app/ogg/dirprm: created
Report files                   /u01/app/ogg/dirrpt: created
Checkpoint files               /u01/app/ogg/dirchk: created
Process status files           /u01/app/ogg/dirpcs: created
SQL script files               /u01/app/ogg/dirsql: created
Database definitions files     /u01/app/ogg/dirdef: created
Extract data files             /u01/app/ogg/dirdat: created
Temporary files                /u01/app/ogg/dirtmp: created
Credential store files         /u01/app/ogg/dircrd: created
Masterkey wallet files         /u01/app/ogg/dirwlt: created
Dump files                     /u01/app/ogg/dirdmp: created

源端MANAGER進程組
GGSCI (king01) 2> edit params mgr
PORT 7839
DYNAMICPORTLIST 7840-7939
AUTORESTART EXTRACT *,RETRIES 5,WAITMINUTES 3
PURGEOLDEXTRACTS ./dirdat/*,USECHECKPOINTS, MINKEEPDAYS 7

GGSCI (king01) 3> start mgr
Manager started.

GGSCI (king01) 4> info mgr
Manager is running (IP port king01.7839, Process ID 3243).


源端EXTRACT進程組
GGSCI (king01) 5> dblogin userid ggs,password ggs
Successfully logged into database.

GGSCI (king01 as ggs@king) 6> add schematrandata soe
2018-08-04 13:18:03  INFO    OGG-01788  SCHEMATRANDATA has been added on schema soe.
2018-08-04 13:18:03  INFO    OGG-01976  SCHEMATRANDATA for scheduling columns has been added on schema soe.

GGSCI (king01 as ggs@king) 7> add extract ext_soe, tranlog, begin now
EXTRACT added.

GGSCI (king01 as ggs@king) 8> add exttrail ./dirdat/st,extract ext_soe,megabytes 100
EXTTRAIL added.

GGSCI (king01 as ggs@king) 9> edit params ext_soe
EXTRACT ext_soe
dynamicresolution
USERID ggs,PASSWORD ggs
EXTTRAIL ./dirdat/st
TABLEEXCLUDE SOE.ORDERENTRY_METADATA
TABLE SOE.*;

GGSCI (king01 as ggs@king) 10> start ext_soe
Sending START request to MANAGER ...
EXTRACT EXT_SOE starting

GGSCI (king01 as ggs@king) 11> info ext_soe

EXTRACT    EXT_SOE   Last Started 2017-08-30 13:47   Status RUNNING
Checkpoint Lag       00:00:00 (updated 00:00:07 ago)
Process ID           4234
Log Read Checkpoint  Oracle Redo Logs
                     2017-08-30 16:58:33  Seqno 59, RBA 211786752
                     SCN 0.2361582 (2361582)
                     
源端PUMP進程組                     
GGSCI (king01 as ggs@king) 12> add extract pmp_soe, exttrailsource ./dirdat/st
EXTRACT added.

GGSCI (king01 as ggs@king) 13> add rmttrail ./dirdat/rt,EXTRACT pmp_soe,megabytes 100
RMTTRAIL added.

GGSCI (king01 as ggs@king) 14> edit params pmp_soe
EXTRACT pmp_soe
PASSTHRU
RMTHOST 192.168.1.202, MGRPORT 7839, COMPRESS
RMTTRAIL ./dirdat/rt
TABLE SOE.*;

GGSCI (king01 as ggs@king) 15> start pmp_soe
Sending START request to MANAGER ...
EXTRACT PMP_SOE starting

GGSCI (king01 as ggs@king) 16>  info pmp_soe
EXTRACT    PMP_SOE   Last Started 2017-08-30 15:22   Status RUNNING
Checkpoint Lag       00:00:00 (updated 00:00:08 ago)
Process ID           4844
Log Read Checkpoint  File ./dirdat/st000000000
                     2017-08-30 16:20:08.000000  RBA 47753236

GGSCI (king01 as ggs@king) 17> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING                                           
EXTRACT     RUNNING     EXT_SOE     00:00:00      00:00:01    
EXTRACT     RUNNING     PMP_SOE     00:00:00      00:00:06


源端備份數據庫
[oracle@king01 ~]$ mkdir /u01/app/oracle/backup
[oracle@king01 ~]$ rman target /
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/app/oracle/backup/%F';
RMAN> RUN {
BACKUP INCREMENTAL LEVEL=0 TAG 'FULL_BACKUP' DATABASE
FORMAT '/u01/app/oracle/backup//soe_full_incr_%s_%p_%T'
PLUS ARCHIVELOG
FORMAT '/u01/app/oracle/backup/soe_arch_%s_%p_%T' delete all input;
DELETE NOPROMPT OBSOLETE;
}

[oracle@king01 ~]$ sqlplus / as sysdba
SQL> select to_char(current_scn) from v$database;
TO_CHAR(CURRENT_SCN)
----------------------------------------
1032191

SQL> alter system archive log current ;
System altered.
SQL> alter system archive log current ;
System altered.
SQL> alter system archive log current ;
System altered.

[oracle@king01 ~]$ rman target /
RMAN> backup archivelog all FORMAT '/u01/app/oracle/backup/soe_arch_%s_%p_%T';
[oracle@king01 ~]$ cd /u01/oracle/backup
[oracle@king01 backup]$  scp * 192.168.1.202:/u01/oracle/backup/
[oracle@king01 ~]$ cd $ORACLE_HOME/dbs
[oracle@king01 dbs]$ scp orapwking 192.168.1.202:/u01/app/database/11.2.0.4/product/dbs


目標端恢復數據庫
[oracle@king02 ~]$ mkdir -p /u01/app/oracle/admin/king/adump
[oracle@king02 ~]$ mkdir -p /u01/app/oracle/oradata/king
[oracle@king02 ~]$ mkdir -p /u01/app/oracle/fast_recovery_area/king
[oracle@king02 ~]$ mkdir -p /u01/app/oracle/archive
[oracle@king02 ~]$ rman target /
RMAN> startup nomount
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/db_1/dbs/initking.ora'
starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started
Total System Global Area    1068937216 bytes
Fixed Size                     2260088 bytes
Variable Size                281019272 bytes
Database Buffers             780140544 bytes
Redo Buffers                   5517312 bytes

RMAN> set DBID=1085678857
RMAN> run{
 set CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/app/oracle/backup/%F';
 restore spfile from autobackup;
 }
 
RMAN> shutdown immediate
RMAN> startup nomount
Total System Global Area    1068937216 bytes
Fixed Size                     2260088 bytes
Variable Size                322962312 bytes
Database Buffers             687865856 bytes
Redo Buffers                  55848960 bytes

RMAN> set DBID=1085678857
executing command: SET DBID
RMAN> run{
2> set CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/app/oracle/backup/%F';
3> restore controlfile from autobackup;
4> }

RMAN> alter database mount;

RMAN> run{
 set until scn 1032191;
 restore database;
 recover database;
 }
 
RMAN> alter database open resetlogs;


目標端數據庫設置
SQL> select 'alter table '||owner||'.'||table_name||' disable constraint '||constraint_name||';'
 from dba_constraints
 where constraint_type in ('R') and
 owner in('SOE')
 order by status,owner;
'ALTERTABLE'||OWNER||'.'||TABLE_NAME||'DISABLECONSTRAINT'||CONSTRAINT_NAME||';'
--------------------------------------------------------------------------------
alter table SOE.ADDRESSES disable constraint ADD_CUST_FK;
alter table SOE.ORDERS disable constraint ORDERS_CUSTOMER_ID_FK;
alter table SOE.ORDER_ITEMS disable constraint ORDER_ITEMS_PRODUCT_ID_FK;
alter table SOE.INVENTORIES disable constraint INVENTORIES_PRODUCT_ID_FK;
alter table SOE.ORDER_ITEMS disable constraint ORDER_ITEMS_ORDER_ID_FK;
alter table SOE.INVENTORIES disable constraint INVENTORIES_WAREHOUSES_FK;
6 rows selected.

SQL> select 'alter trigger '||owner||'.'||trigger_name||' disable;'
 from dba_triggers
 where owner in('SOE')
 order by status,owner;
no rows selected

SQL>  alter system set job_queue_processes=0 scope=both;
System altered.

SQL> drop user ggs cascade;
User dropped.

SQL> create user ggt identified by ggt default tablespace goldengate;
User created.

SQL> grant dba to ggt;
Grant succeeded.


目標端安裝OGG
[oracle@king02 ~]$ vi .bash_profile
export OGG_HOME=/u01/app/ogg
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export PATH=$OGG_HOME:$PATH
[oracle@king02 ~]$ source .bash_profile

[oracle@king02 ~]$ mkdir -p /u01/app/ogg
[oracle@king02 ~]$ unzip fbo_ggs_Linux_x64_shiphome.zip
[oracle@king02 ~]$ cd fbo_ggs_Linux_x64_shiphome/Disk1
[oracle@king02 Disk1]$ ./runInstaller 


[oracle@king02 Disk1]$ cd /u01/app/ogg
[oracle@king02 ogg]$ ./ggsci
GGSCI (king02) 1> create subdirs

Creating subdirectories under current directory /u01/app/ogg

Parameter files                /u01/app/ogg/dirprm: created
Report files                   /u01/app/ogg/dirrpt: created
Checkpoint files               /u01/app/ogg/dirchk: created
Process status files           /u01/app/ogg/dirpcs: created
SQL script files               /u01/app/ogg/dirsql: created
Database definitions files     /u01/app/ogg/dirdef: created
Extract data files             /u01/app/ogg/dirdat: created
Temporary files                /u01/app/ogg/dirtmp: created
Credential store files         /u01/app/ogg/dircrd: created
Masterkey wallet files         /u01/app/ogg/dirwlt: created
Dump files                     /u01/app/ogg/dirdmp: created


目標端MANAGER進程組
GGSCI (king02) 1> edit params mgr
PORT 7839
DYNAMICPORTLIST 7840-7939
AUTORESTART EXTRACT *,RETRIES 5,WAITMINUTES 3
PURGEOLDEXTRACTS ./dirdat/*,USECHECKPOINTS, MINKEEPDAYS 7

GGSCI (king02) 2> start mgr
Manager started.

GGSCI (king02) 3> info mgr
Manager is running (IP port king02.7839, Process ID 13650).

目標端REPLICAT進程組
GGSCI (king02) 4> edit params ./GLOBALS
checkpointtable ggt.chkpt

GGSCI (king02) 5> dblogin userid ggt,password ggt
Successfully logged into database.

GGSCI (king02 as ggt@king) 6> add checkpointtable

No checkpoint table specified. Using GLOBALS specification (ggt.chkpt)...

Successfully created checkpoint table ggt.chkpt.

GGSCI (king02 as ggt@king) 7> add replicat rep_soe,exttrail ./dirdat/rt
REPLICAT added.

GGSCI (king02 as ggt@king) 8> edit param rep_soe 
REPLICAT rep_soe
USERID ggt, PASSWORD ggt
DISCARDFILE ./dirrpt/rep_soe.dsc,APPEND,MEGABYTES 1024
REPERROR DEFAULT, ABEND
ASSUMETARGETDEFS
ALLOWNOOPUPDATES
MAP SOE.*, TARGET SOE.*;

GGSCI (king02 as ggt@king) 9> start replicat rep_soe, aftercsn 1032191

Sending START request to MANAGER ...
REPLICAT REP_SOE starting

GGSCI (king02 as ggt@king) 10> info rep_soe

REPLICAT   REP_SOE   Last Started 2018-08-04 14:40   Status RUNNING
Checkpoint Lag       00:00:00 (updated 00:00:00 ago)
Process ID           13902
Log Read Checkpoint  File ./dirdat/rt000000000
                     2018-08-04 14:43:08.676383  RBA 42207


GGSCI (king02 as ggt@king) 11> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING                                           
REPLICAT    RUNNING     REP_SOE     00:00:00      00:00:04


Oracle Database 復制解決方案:Oracle GoldenGate