oracle 11g goldengate structures (a)

After the beginner ogg, ogg to understand the basic principles and architecture, build on the progress to build a simple learning environment, in order to achieve the goal: the two tables sourcedb database: sourceuser.test01 and sourceuser.dept by ogg are synchronized to the database targetuser.test01 targetdb and targetuser.dept tables required to achieve DML (insert, update, delete) synchronization.

Basic environment

  Source End goal  
Operating system version redhat 6.7 redhat 6.7
Database Version  11.2.0.4 11.2.0.4
ogg version  Oracle GoldenGate 11.2.1.0.3 for Oracle 11g on Linux x86-64 Oracle GoldenGate 11.2.1.0.3 for Oracle 11g on Linux x86-64
Database / instance name  sourcedb/sourcedb targetdb/targetdb    

 

(A) decompression software (source and target-side execution)

[oracle@source-node ogg]$ unzip -q V34339-01.zip
[oracle@source-node ogg]$ ls
fbo_ggs_Linux_x64_ora11g_64bit.tar       Oracle GoldenGate_11.2.1.0.3_README.txt
OGG_WinUnix_Rel_Notes_11.2.1.0.3.pdf     V34339-01.zip
Oracle_GoldenGate_11.2.1.0.3_README.doc

[oracle@source-node ogg]$ tar -xvf fbo_ggs_Linux_x64_ora11g_64bit.tar

(B) configure the environment variables
[Source-Node Oracle @ ~] $ Vim .bash_profile

export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH:$GG_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export GG_HOME=/u01/app/ogg

alias  ggsci='cd $GG_HOME;ggsci'

(C) the source database configuration
(3.1) to open the archive
to see whether to open an archive
SQL> Archive log List
Database log the MODE No Archive Mode
Automatic Archival Disabled
Archive Where do you want USE_DB_RECOVERY_FILE_DEST
Oldest Online log Sequence 4
Current log Sequence 6

SQL> alter system set log_archive_dest_1='LOCATION=/archlog';

System altered.

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

System altered.


SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  534462464 bytes
Fixed Size            2254952 bytes
Variable Size          390072216 bytes
Database Buffers      134217728 bytes
Redo Buffers            7917568 bytes
Database mounted.
SQL> alter database archivelog;

Database altered.


SQL> alter database open ;

Database altered.

 

(3.2) to open the force generated log
SQL> select force_logging from v $ database ;

FOR
---
NO

SQL> alter database force logging;

Database altered.

SQL>  select force_logging from v$database;

FOR
---
YES


(3.3) opens an additional log
SQL> select SUPPLEMENTAL_LOG_DATA_MIN from v $ database ;

SUPPLEME
--------
NO

SQL>
SQL>
SQL> alter database add supplemental log data;

Database altered.

SQL> select SUPPLEMENTAL_LOG_DATA_MIN from v$database;

SUPPLEME
--------
YES

 

(3.4) modify goldengate parameters
SQL> show parameter golden

NAME                     TYPE     VALUE
------------------------------------ ----------- ------------------------------
enable_goldengate_replication         boolean     FALSE
SQL> alter system set enable_goldengate_replication=true;

System altered.

SQL> show parameter golden

NAME                     TYPE     VALUE
------------------------------------ ----------- ------------------------------
enable_goldengate_replication         boolean     TRUE

 

(3.5) to create goldengat user
to create exclusive table space:
the Create TABLESPACE tbs_ogg datafile '/u01/app/oracle/product/11.2.0/db_1/dbs/sourcedb/tbs_ogg01.dbf' size 10m 100m AUTOEXTEND the Next ON MAXSIZE 30g;

Create a user:
the Create the User OGG OGG IDENTIFIED by default TABLESPACE tbs_ogg;

授予权限:
grant resource to ogg;
grant create session,alter session to ogg;
grant select any dictionary to ogg;
grant flashback any table to ogg;
grant alter any table to ogg;
grant select any table to ogg;
grant execute on dbms_flashback to ogg;
 
(3.6)创建测试用户及数据
create user sourceuser identified by sourceuser;
grant connect,resource to sourceuser;

conn sourceuser/sourceuser

- Create Table
Create Table Test01 (Number ID, name VARCHAR2 (20 is));
- to increase the master key
ALTER Test01 the Add Table Primary Key (ID);
- inserting the test data
INSERT INTO Test01 values (. 1, 'lijiaman');
INSERT Test01 values INTO (2, 'Xiaoming');
INSERT INTO Test01 values (. 3, 'xiaohua');

--创建表
create table dept (deptno number,dname varchar2(14),loc varchar2(13));
--增加主键
alter table dept add primary key(deptno);
--插入测试数据
insert into dept values(10,'ACCOUNTING','NEW YORK');
insert into dept values(20,'RESEARCH','DALLAS');
insert into dept values(30,'SALES','CHICAGO');
insert into dept values(40,'OPERATIONS','BOSTON');

 

(3.7) deriving data (Data Pump)
Step1: create a path
$ [/ Home / Oracle] mkdir DataPump
$ [/ Home / Oracle] sqlplus SYS / the passwd AS SYSDBA
SQL> Create or Replace DIRECTORY exp_dir AS '/ Home / Oracle / datapump '

step2: authorize users to export data
the SQL> the GRANT the READ, the WRITE exp_dir the TO DIRECTORY the ON sourceuser;
the SQL> sourceuser the GRANT DATAPUMP_EXP_FULL_DATABASE the TO;

step3:执行数据导出
$[/home/oracle/datapump]expdp sourceuser/sourceuser directory = exp_dir dumpfile = sourcedb_table.dmp logfile = sourcedb_table.log tables = sourceuser.test01,sourceuser.dept;


(Iv) target-side database configuration
(4.1) to create goldengat user
to create exclusive table space:
the Create TABLESPACE tbs_ogg datafile '/u01/app/oracle/product/11.2.0/db_1/dbs/targetdb/tbs_ogg01.dbf' size 100m AUTOEXTEND ON next 10m maxsize 30g;

Create a user:
the Create the User OGG OGG IDENTIFIED by default TABLESPACE tbs_ogg;

授予权限:
grant resource to ogg;
grant create session,alter session to ogg;
grant select any dictionary to ogg;
grant flashback any table to ogg;
grant alter any table to ogg;
grant select any table to ogg;
grant execute on dbms_flashback to ogg;
grant insert any table to ogg;
grant update any table to ogg;
grant delete any table to ogg;

(4.2) to create a test user
the Create the User targetuser IDENTIFIED by targetuser;
Grant Connect, Resource to targetuser;

(4.3) into the source has been derived data (initialization data)
Step1: create a path
$ [/ Home / Oracle] mkdir DataPump
$ [/ Home / Oracle] sqlplus SYS / the passwd AS SYSDBA
SQL> Create or Replace DIRECTORY imp_dir AS '/ home / oracle / datapump ';

(2) authorized users to import data,
the SQL> the GRANT the READ, the WRITE imp_dir the TO DIRECTORY the ON targetuser;
the SQL> targetuser the GRANT DATAPUMP_IMP_FULL_DATABASE the TO;

(3) the copied files (performed at the source end)
CD / Home / Oracle / DataPump
SCP sourcedb_table.dmp [email protected]: / Home / Oracle / DataPump

(4)执行导入
$[/home/oracle/datapump]impdp targetuser/targetuser directory=imp_dir dumpfile =sourcedb_table.dmp  remap_schema=sourceuser:targetuser;

 

(E) source ogg configuration
(5.1) to create the relevant directory ogg
[Source-Node Oracle @ ~] $ CD $ GG_HOME
[Oracle @ Source-Node ogg] $ GGSCI

Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.3 14400833 OGGCORE_11.2.1.0.3_PLATFORMS_120823.1258_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Aug 23 2012 20:20:21

Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.

 

GGSCI (source-node) 1> create subdirs

Creating subdirectories under current directory /u01/app/ogg

Parameter files                /u01/app/ogg/dirprm: already exists
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
Stdout files                   /u01/app/ogg/dirout: created

(5.2) to configure and start the process mgr
GGSCI (Source-the Node) 2> Edit param mgr
Port 7809
dynamicportlist 7840-7845

GGSCI (source-node) 3> start mgr
Manager started.

GGSCI (source-node) 4> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING                                          

(5.3) to be synchronized start an extra log table
GGSCI (Source-Node). 6> OGG dblogin to the userid, password OGG
Successfully logged INTO Database.

GGSCI (source-node) 7> add trandata sourceuser.test01
Logging of supplemental redo data enabled for table SOURCEUSER.TEST01.

GGSCI (source-node) 10> add trandata sourceuser.dept
Logging of supplemental redo data enabled for table SOURCEUSER.DEPT.

(5.4) Configuration extraction process EXTA
GGSCI (Source-the Node) 11> the Add Extract EXTA, tranlog, the begin now
the EXTRACT added.

GGSCI (source-node) 12> info all
Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING                                          
EXTRACT     STOPPED     EXTA        00:00:00      00:00:05   

GGSCI (source-node) 13> add exttrail ./dirdat/ra,extract exta
EXTTRAIL added.

GGSCI (source-node) 14> edit param exta
extract exta
userid ogg,password ogg
setenv (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
exttrail ./dirdat/ra
dynamicresolution
gettruncates
table sourceuser.test01;
table sourceuser.dept;                                          

GGSCI (source-node) 16> start exta

Sending START request to MANAGER ...
EXTRACT EXTA starting

GGSCI (source-node) 17> info all
Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING                                          
EXTRACT     RUNNING     EXTA        00:07:51      00:00:05   

(5.5) Configuration delivery process

GGSCI (source-node) 21> add extract dpa,exttrailsource ./dirdat/ra
EXTRACT added.

GGSCI (source-node) 22> edit param dpa

extract dpa
userid ogg,password ogg
setenv (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
passthru
rmthost 192.168.10.12,mgrport 7809
rmttrail ./dirdat/ra
table sourceuser.test01;
table sourceuser.dept;  


GGSCI (source-node) 23> add rmttrail ./dirdat/ra,extract dpa
RMTTRAIL added.


GGSCI (source-node) 26> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING                                          
EXTRACT     RUNNING     DPA         00:00:00      00:03:46   
EXTRACT     RUNNING     EXTA        00:00:00      00:00:05 

 

(Vi) the destination end ogg configuration
(6.1) ogg create the relevant directory
[the Node-target the Oracle @ ~] $ cd $ GG_HOME

[oracle@target-node ogg]$ ggsci

Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.3 14400833 OGGCORE_11.2.1.0.3_PLATFORMS_120823.1258_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Aug 23 2012 20:20:21

Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.

GGSCI (target-node) 1> create subdirs

Creating subdirectories under current directory /u01/app/ogg

Parameter files                /u01/app/ogg/dirprm: already exists
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
Stdout files                   /u01/app/ogg/dirout: created

(6.2) to configure and start the process mgr
GGSCI (target-the Node) 2> Edit param mgr
Port 7809
dynamicportlist 7840-7845

GGSCI (target-node) 3> start mgr
Manager started.

GGSCI (target-node) 4> info all
Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING                                          

(6.3) Configuration ogg checkpoint
GGSCI (target-Node). 5> Edit param ./globals
checkpointtable ogg.checkpoint


GGSCI (target-node) 6> dblogin userid ogg,password ogg
Successfully logged into database.

GGSCI (target-node) 7> add checkpointtable ogg.checkpoint

Successfully created checkpoint table ogg.checkpoint.

(6.4) Configuration replication process
GGSCI (target-Node) 14> the Add Replicat rEPA, EXTTRAIL ./dirdat/ra,checkpointtable ogg.checkpoint
Replicat added.

GGSCI (target-node) 36> edit param repa

replicat repa
setenv (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
userid ogg,password ogg
numfiles 500
grouptransops 10000
handlecollisions
assumetargetdefs
allownoopupdates
dynamicresolution
discardfile ./dirrpt/repa_discard.txt,append,megabytes 10
map sourceuser.*,target targetuser.*;


GGSCI (target-node) 17> start repa
Sending START request to MANAGER ...
REPLICAT REPA starting


GGSCI (target-node) 18> info all
Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING                                          
REPLICAT    RUNNING     REPA        00:00:00      00:00:02   

(Vii) test ogg replication
1. Insert sourceuser.test01 data in the table, there is new data found targetuser.test01 enter;
2. Execute delete from test01 at the source and submit the data in the target end targetuser.test01 are all delete;
3. the source table primary key column update operation: update dept set loc = 'sichuanthe target terminal is automatically updated;
4. the source table primary key column update operation: update dept set deptno = deptno +1, automatically updating the target terminal;

 

【Finish】

Guess you like

Origin www.cnblogs.com/lijiaman/p/11432261.html