Tuesday, April 19, 2016

Oracle Streams Configuration



 Streams Configuration in two systems (ONE WAY REPLICATION) 

 (Source-.destination) 

 The replication is done on scotts emp table 


Step 1: Create two databases 

 Create source database srcdb

 Create destination database destdb


Step 2: Check weather both databases are in archive log mode are not( for both the databases) 

 Sql>archive log list;

 (Or)   Sql>select log_mode from v$database;

If the database is not in archive log mode then make the databases in archive log mode


Step 3: Following parameters should be set in the spfiles of both databases: 

CONN /AS SYSDBA
ALTER SYSTEM SET JOB_QUEUE_PROCESSES=10;
ALTER SYSTEM SET AQ_TM_PROCESSES=1;
ALTER SYSTEM SET GLOBAL_NAMES=TRUE;
SHUTDOWN IMMEDIATE;
STARTUP;

We need to shut down the database so that this parameter takes effect.


Step 4: Create Stream Administrator Account 

You need to create a stream administrator account and grant all required privileges as

shown below:

CONN /AS SYSDBA
CREATE USER streamadmin IDENTIFIED BY abc123
DEFAULT TABLESPACE users QUOTA UNLIMITED ON users;


Grant all required privileges:

GRANT CONNECT, RESOURCE, SELECT_CATALOG_ROLE TO streamadmin;
GRANT EXECUTE ON DBMS_AQADM TO streamadmin;

GRANT EXECUTE ON DBMS_CAPTURE_ADM TO streamadmin;

GRANT EXECUTE ON DBMS_PROPAGATION_ADM TO streamadmin;

GRANT EXECUTE ON DBMS_STREAMS_ADM TO streamadmin;

GRANT EXECUTE ON DBMS_APPLY_ADM TO streamadmin;

GRANT EXECUTE ON DBMS_FLASHBACK TO streamadmin;

Execute the following stored procedure in both databases

BEGIN
DBMS_RULE_ADM.GRANT_SYSTEM_PRIVILEGE(
Privilege => DBMS_RULE_ADM.CREATE_RULE_OBJ,
Grantee => 'streamadmin',
grant_option => FALSE);
END;



Steps 5: Configure listener.ora on destdb and tnsnames.ora on srcdb 

Listener.ora

SID_LIST_LIDESTDB =

 (SID_LIST =

 (SID_DESC =

 (SID_NAME = destdb)

 (ORACLE_HOME = /home/oracle/oracle/product/10.2.0/db_1)

 (PROGRAM = extproc) ) )



LIDESTDB=

 (DESCRIPTION_LIST =

 (DESCRIPTION =

 (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.21)(PORT = 1521))

 (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0)) ) )



Tnsnames.ora

TODESTDB=

 (DESCRIPTION =

 (ADDRESS_LIST =

 (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.21)(PORT = 1521))  )

 (CONNECT_DATA =

 (SERVICE_NAME = destdb) ) )


Step 6: Create database link on source database(srcdb) 

Create database link destdb connect to streamadmin identified by abc123 using ‘TODESTDB’

The name of the link should be the destination database name ie (dastdb) and should connect by using
tnsnames netservice name on source database ie (TODESTDB)


Check if dblink is working or not from source since the replication is from source to destination

Sql>select sysdate from dual@destdb-->dblink name

It should pull up the date from destination database


Step 7: Create a Queue on both source database (srcdb) and destination database ( destdb) 

 Before creating a queue we need to grant scott.emp to streamadmin from sysdba to srcdb

Conn / as sysdba

Sql>grant all on scott.emp to streamadmin;


Now we wil setup a queue on both source database (srcdb) and destination database ( destdb) as streamadmin

Conn streamadmin/abc123

begin
dbms_streams_adm.set_up_queue(
queue_table => 'streamadmin.streams_queue_table',
queue_name => 'streamadmin.streams_queue',
storage_clause => 'TABLESPACE USERS',
queue_user => 'streamadmin');
end;

/


Step 8: Set up supplemental logging on source database(srcdb) 

Conn / as sysdba

Sql>alter table set scott.emp add supplemental log group babu_pk(empno) always;

Step 9: configure propagation at source database(srcdb) as streamadmin 

Conn streamadmin/abc123;

begin
dbms_streams_adm.add_table_propagation_rules(
table_name => 'scott.emp',
streams_name => 'my_stream',
source_queue_name => 'streamadmin.streams_queue',
destination_queue_name => 'streamadmin.streams_queue@destdb',.dblink
include_dml=> true,
include_ddl=> true,
source_database => 'srcdb');
end;

/

Step 10: Configure capture process at source database (srcdb) as streamadmin 

Conn streamadmin/abc123;

begin
dbms_streams_adm.add_table_rules(
table_name => 'scott.emp',
streams_type => 'capture',
streams_name => 'capture_simp',
queue_name=>'streamadmin.streams_queue',
include_dml => true,
include_ddl => true);
end;

/



Step 11: Installation of SCN at source database(srcdb) as streamadmin 

Conn streamadmin/abc123

declare
v_scn number;
begin
v_scn:=dbms_flashback.get_system_change_number();
dbms_apply_adm.set_table_instantiation_scn@orcl(
source_object_name => 'scott.emp',
source_database_name =>'catdb',
instantiation_scn => v_scn);
end;

/

Step 11: configure Apply process at destination database (destdb) as streamadmin 

begin
dbms_streams_adm.add_table_rules(
table_name =>'scott.emp',
streams_type => 'apply',
streams_name => 'apply_simp',
queue_name => 'streamadmin.streams_queue',
include_dml => true,
include_ddl => true,
source_database => 'srcdb');
end;

/

Step 12: Set apply process at destination database (destdb) as streamadmin 

begin
dbms_apply_adm.set_parameter(
apply_name => 'apply_simp',
parameter => 'disable_on_error',
value => 'n');
end;

/

Step 13: Start capture process at source database (srcdb) as streamadmin 

begin
dbms_capture_adm.start_capture(
capture_name => 'capture_simp');
end;

/

Step 14: Start propagation process at source database (srcdb) as streamadmin (optional) 

Just check it since this process will be already in start state we usually get an error that its already started..

begin
dbms_propagation_adm.start_propagation(
propagation_name => 'my_stream');
end;

/

Step 15 : Start apply process at destination database (destdb) as streamadmin 

begin
dbms_apply_adm.start_apply(
apply_name => 'apply_simp');
end;

/



Thursday, March 3, 2016

ERROR OGG-01705 Input checkpoint position for input trail file is greater than the size of the file

Pump, Extract or Replicat may get stuck on a trail file even if there are more trail files available in machine for the reader object to process. This issue occurs when the pump extract / Replicat read checkpoint RBA is larger than the local trail file size that it reads.
Here my Replicat got abended with the following error message …….

ERROR   OGG-01705  Input checkpoint position 33144618 for input trail file './dirdat/c4001256' is greater than the size of the file (33079717).  Please consult Oracle Knowledge Management Doc ID 1138409.1. for instructions.


GGSCI (oracledev01) 9> info REPDEV

REPLICAT   REPDEV  Last Started 2016-03-01 19:10   Status ABENDED
Checkpoint Lag       00:00:00 (updated 240:44:11 ago)
Log Read Checkpoint  File ./dirdat/c4001256
                     2016-02-20 19:19:49.000207  RBA 33144618

Now let’s check the trail file size…………

 [oracle@oracledev01 GG11]$ ls -l dirdat/c4001256
-rw-r----- 1 oracle oinstall 33079717 Feb 22 11:48 dirdat/c4001256

From above we can see that RBA is greater than the trail file size

FILTERDUPTRANSACTIONS
When using this option to start the replicat, it will use the information already stored in the checkpoint table and filter out transactions already applied.
This option is valid only for Replicat in nonintegrated mode. Integrated mode handles duplicate transactions transparently.

[oracle@oracledev01 GG11]$ ./ggsci

Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.14 17547423 OGGCORE_11.2.1.0.0OGGBP_PLATFORMS_131022.0605_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Oct 22 2013 11:03:39
Copyright (C) 1995, 2013, Oracle and/or its affiliates. All rights reserved.

GGSCI (oracledev01) 1> start replicat REPDEV FILTERDUPTRANSACTIONS
Sending START request to MANAGER ...
REPLICAT REPDEV starting

GGSCI (oracledev01) 2> info REPDEV
REPLICAT   REPDEV  Last Started 2016-03-01 20:06   Status RUNNING
Checkpoint Lag       00:00:00 (updated 00:00:04 ago)
Log Read Checkpoint  File ./dirdat/c4001257
                                         First Record  RBA 0


GGSCI (oracledev01) 3> info REPDEV
REPLICAT   REPDEV  Last Started 2016-03-01 20:06   Status RUNNING
Checkpoint Lag       240:46:27 (updated 00:00:03 ago)
Log Read Checkpoint  File ./dirdat/c4001257
                   2016-02-20 19:19:57.964167  RBA 276602

From the above we can see my replicat has moved on to the next trail file “c4001257” and it is up and running fine J

Refer:

OGG Extract / Replicat Checkpoint RBA Is Larger than Local Trail Size (Doc ID 1138409.1)