Vous êtes sur la page 1sur 11

GoldenGate Installation (Oracle 11g on Linux)

Oracle GoldenGate enables the exchange and manipulation of data at the transaction
level among multiple, heterogeneous platforms across the enterprise. It moves
committed transactions with transaction integrity and minimal overhead on your
existing infrastructure. Its modular architecture gives you the flexibility to extract and
replicate selected data records, transactional changes, and changes to DDL (data
definition language) across a variety of topologies.
In this blog I am writing about oracle to oracle DB replication by using GoldenGate. Aim
of this demonstration if replicate all changes in one particular schema (include DDL)
from one oracle DB to another Oracle DB. For this purpose I have created two oracle DB
on same host from different users.

1. First of all, install Golden Gate software on each Oracle DB. Step1
process is same for both the database.
[oratest@localhost
[oratest@localhost
[oratest@localhost
[oratest@localhost

oratest]$ mkdir ggate


oratest]$ cd ggate
ggate]$ unzip V34339-01.zip
ggate]$ tar -xvf fbo_ggs_Linux_x64_ora11g_64bit.tar

export PATH=$PATH:/u01/app/oratest/ggate
export
LD_LIBRARY_PATH=/u01/app/oratest/product/11.2.0/dbhome_1/lib:/u01/app/orate
st/ggate
[oratest@localhost ggate]$ 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 (localhost.localdomain) 1> CREATE SUBDIRS
Creating subdirectories under current directory /u01/app/oratest/ggate
Parameter files
Report files
Checkpoint files
Process status files
SQL script files

/u01/app/oratest/ggate/dirprm: already exists


/u01/app/oratest/ggate/dirrpt: created
/u01/app/oratest/ggate/dirchk: created
/u01/app/oratest/ggate/dirpcs: created
/u01/app/oratest/ggate/dirsql: created

Database definitions files


/u01/app/oratest/ggate/dirdef: created
Extract data files
/u01/app/oratest/ggate/dirdat: created
Temporary files
/u01/app/oratest/ggate/dirtmp: created
Stdout files
/u01/app/oratest/ggate/dirout: created

GGSCI (localhost.localdomain) 2>


2. Now We are going to prepare the source database (ora1103 - Database)
for replication.:
We then need to create a database user which will be used by the GoldenGate Manager,
Extract and Replicat processes. We can create individual users for each process or
configure just a common user in our case we will create the one user GGS_OWNER
and grant it the required privileges.

2.1) Switch the database to archivelog mode


SQL> archive log list;
Database log mode
Archive Mode
Automatic archival
Enabled
Archive destination
/u01/app/ora1103/archive_1103
Oldest online log sequence
3
Next log sequence to archive 5
Current log sequence
5
SQL> select log_mode from v$database;
LOG_MODE
-----------ARCHIVELOG
2.2)
Enable minimal supplemental logging:
SQL> alter database add supplemental log data;
Database altered.
Prepare the database for DDL replication. Turn off the recyclebin feature and be
sure that it is empty.
SQL> alter system set recyclebin=off scope=spfile;
System altered.
SQL> purge DBA_RECYCLEBIN;
DBA Recyclebin purged.
2.3) create a schema that will contain the Oracle GoldenGate DDL objects.

SQL> create tablespace gg_tbls datafile


'/u01/app/ora1103/oradata/ora1103/gg_tbls.dbf' size 100m reuse autoextend on;
Tablespace created.
SQL> create user ggate identified by oracle default tablespace gg_tbls quota
unlimited on gg_tbls;
User created.
SQL> grant create session, connect, resource to ggate;
Grant succeeded.
SQL> grant dba to ggate;
Grant succeeded.
SQL> grant execute on utl_file to ggate;
Grant succeeded.

2.4) Change the directory on Golden Gate home directory and run scripts
for creating all necessary objects for support ddl replication.
[ora1103@localhost ggate]$ cd /u01/app/ora1103/ggate
[ora1103@localhost ggate]$ sqlplus "/as sysdba"
SQL>
SQL>
SQL>
SQL>
SQL>

@marker_setup.sql
@ddl_setup.sql
@role_setup.sql
grant GGS_GGSUSER_ROLE to ggate;
@ddl_enable.sql

2.5) after that, add information about your Oracle GoldenGate DDL scheme
into file GLOBALS. You should input this row into the file "GGSCHEMA
ggate".
[ora1103@localhost ggate]$ 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 (localhost.localdomain) 1> EDIT PARAMS ./GLOBALS
GGSCHEMA ggate
GGSCI (localhost.localdomain) 2>
3. Create the schemes for replication on both hosts (ora1103 (db1), dup
(db2)).

3.1. Source database (db1):


SQL> create user source identified by oracle default tablespace users temporary
tablespace temp;
User created.
SQL> grant connect,resource,unlimited tablespace to source;
Grant succeeded.
3.2. Target database (db2):
SQL> create user target identified by oracle default tablespace users temporary
tablespace temp;
User created.
SQL> grant connect,resource,unlimited tablespace to target;
Grant succeeded.
SQL> grant dba to target; -- OR any particular grants
Grant succeeded.

4. Create the directory for trail files on both hosts and create directory for
discard file on db2 host only.
[oracle@db ~] mkdir /u01/app/oracle/product/gg/dirdat/tr

[oracle@db2 ~] mkdir /u01/app/oracle/product/gg/dirdat/tr


[oracle@db2 ~] mkdir /u01/app/oracle/product/gg/discard

5. Here I am showing a standard reporting configuration as depict in


picture:

5.1. Configure extracts on source database (ora1103).

5.1a) Run ggcsi and configure the manager process.


Source:
[ora1103@localhost ggate]$ ./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 (localhost.localdomain) 1> edit params mgr
PORT 7809
GGSCI (localhost.localdomain) 2> start manager
Manager started.
GGSCI (localhost.localdomain) 3> info all
Program
Status
Group
Lag at Chkpt Time Since Chkpt
MANAGER
RUNNING
GGSCI (localhost.localdomain) 4>
5.1b) Login into database and add additional information about primary
keys into log files.
GGSCI (localhost.localdomain) 1> dblogin userid ggate
Password:
Successfully logged into database.
GGSCI (localhost.localdomain) 2> ADD SCHEMATRANDATA source
2016-11-14 14:29:00 INFO OGG-01788 SCHEMATRANDATA has been added on
schema source.
GGSCI (localhost.localdomain) 3>
NOTE: This is a very important step, because if you don't do it you will not be able
to replicate Update statements. You will get errors like the following:
OCI Error ORA-01403: no data found, SQL
As you know, when you write the update statement you usually don't change the
primary key, so Oracle log files contain information about changing column values
and don't contain information about primary key. For avoiding this situation you
should add this information into log files using ADD SCHEMATRANDATA or ADD
TRANDATA commands. Add extracts (regular and data pump).
5.1c)
[ora1103@localhost ggate]$ 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 (localhost.localdomain) 1> add extract ext1, tranlog, begin now
EXTRACT added.
GGSCI (localhost.localdomain) 2> add exttrail /u01/app/ora1103/ggate/dirdat/tr,
extract ext1
EXTTRAIL added.
GGSCI (localhost.localdomain) 3> edit params ext1
extract ext1
userid ggate, password oracle
exttrail /u01/app/ora1103/ggate/dirdat/tr
ddl include mapped objname source.*;
table source.*;
GGSCI (localhost.localdomain) 4> info all
Program
Status
Group
Lag at Chkpt Time Since Chkpt
MANAGER
RUNNING
EXTRACT
STOPPED
EXT1
00:00:00
00:00:43
GGSCI (localhost.localdomain) 5>
5.1d)
GGSCI (localhost.localdomain) 5> add extract pump1, exttrailsource
/u01/app/ora1103/ggate/dirdat/tr , begin now
EXTRACT added.
GGSCI (localhost.localdomain) 6> add rmttrail /u01/app/oratest/ggate/dirdat/tr,
extract pump1
RMTTRAIL added.
GGSCI (localhost.localdomain) 7> edit params pump1
EXTRACT pump1
USERID ggate, PASSWORD oracle
RMTHOST localhost.localdomain, MGRPORT 7810
RMTTRAIL /u01/app/oratest/ggate/dirdat/tr
PASSTHRU
table source.*;
GGSCI (localhost.localdomain) 8> info all
Program
Status
Group
Lag at Chkpt Time Since Chkpt
MANAGER
RUNNING
EXTRACT
STOPPED
EXT1
00:00:00
00:04:43

EXTRACT
STOPPED
PUMP1
GGSCI (localhost.localdomain) 9>

00:00:00

00:00:38

5.2. Configure the target database (dup).


Target:
5.2a) [oratest@localhost ggate]$ ./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 (localhost.localdomain) 1> edit params mgr
PORT 7810
GGSCI (localhost.localdomain) 2> start manager
Manager started.
GGSCI (localhost.localdomain) 3> info all
Program
Status
Group
Lag at Chkpt Time Since Chkpt
MANAGER
RUNNING
GGSCI (localhost.localdomain) 4>
5.2b)
Create the checkpoint table and change the GLOBAL file.
[oratest@localhost ggate]$ 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 (localhost.localdomain) 1> EDIT PARAMS ./GLOBALS
CHECKPOINTTABLE target.checkpoint
GGSCI (localhost.localdomain) 2> dblogin userid target
Password:
Successfully logged into database.
GGSCI (localhost.localdomain) 3> add checkpointtable target.checkpoint
Successfully created checkpoint table target.checkpoint.
GGSCI (localhost.localdomain) 4>
5.2c) Add replicat.
[oratest@localhost ggate]$ 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 (localhost.localdomain) 1> add replicat rep1, exttrail
/u01/app/oratest/ggate/dirdat/tr, begin now
REPLICAT added.
GGSCI (localhost.localdomain) 2> edit params rep1
REPLICAT rep1
ASSUMETARGETDEFS
USERID target, PASSWORD oracle
discardfile /u01/app/oratest/ggate/discard/rep1_discard.txt, append, megabytes 10
DDL
map source.*, target target.*;
GGSCI (localhost.localdomain) 3> info all
Program
Status
Group
Lag at Chkpt Time Since Chkpt
MANAGER
RUNNING
REPLICAT STOPPED
REP1
00:00:00
00:00:33
GGSCI (localhost.localdomain) 4>
5.3. Start extracts and replicat processes.
5.3a) [ora1103@localhost ggate]$ 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 (localhost.localdomain) 3> start extract ext1
Sending START request to MANAGER ...
EXTRACT EXT1 starting
GGSCI (localhost.localdomain) 4> start extract PUMP1
Sending START request to MANAGER ...
EXTRACT PUMP1 starting
GGSCI (localhost.localdomain) 5> info all
Program
Status
Group
Lag at Chkpt Time Since Chkpt
MANAGER
RUNNING
EXTRACT
RUNNING
EXT1
00:00:00
00:00:04
EXTRACT
RUNNING
PUMP1
00:00:00
00:13:39
GGSCI (localhost.localdomain) 6>

5.3b)
[oratest@localhost ggate]$ 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 (localhost.localdomain) 5> start replicat rep1
Sending START request to MANAGER ...
REPLICAT REP1 starting
GGSCI (localhost.localdomain) 6> info all
Program
Status
Group
Lag at Chkpt Time Since Chkpt
MANAGER
RUNNING
REPLICAT RUNNING
REP1
00:00:00
00:00:00
GGSCI (localhost.localdomain) 7>

6. Check/validate replication between databaes. Here, Validating the same


by creating table/insert row/detele rows.
6.1 At source:
[ora1103@localhost ggate]$ sqlplus source/oracle
SQL*Plus: Release 11.2.0.3.0 Production on Mon Nov 14 14:55:55 2016
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
SQL> select * from test;
select * from test
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> create table test (id number primary key, name varchar2(50));
Table created.
SQL> insert into test values (1,'test');
1 row created.
SQL> insert into test values (2,'test');
1 row created.
SQL> commit;
Commit complete.

6.1 at Target:
[oratest@localhost ggate]$ sqlplus target/oracle
SQL*Plus: Release 11.2.0.3.0 Production on Mon Nov 14 14:58:16 2016
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select * from test;
ID NAME
---------- -------------------------------------------------1 test
2 test
As you can see, all works. Lets execute some more SQLs and Update statements.
Source db:
SQL> delete test where id =2;
1 row deleted.
SQL> insert into test values (3,'test');
1 row created.
SQL> update test set name='test3' where id = 3;
1 row updated.
SQL> commit;
Commit complete.
SQL> select * from test;
ID NAME
---------- -------------------------------------------------1 test
3 test3

SQL> insert into test values (4,'test');


1 row created.
SQL> commit;
Commit complete.
At Target:
SQL> select * from test;
ID NAME
---------- --------------------------------------------------

1 test
3 test3
ID NAME
---------- -------------------------------------------------1 test
3 test3
4 test
Conclusion:
--------------Oracle GoldenGate is a software package for enabling the replication of data in
heterogeneous data environments. It is easy to use. It provide other great feature
such as zero downtime upgrade of database, replication between different kind of
databases and data transformation from source to targets and many others. It has
a rich topology to deploy as per the requirements.

Vous aimerez peut-être aussi