Oracle8i Replication Management API Reference
Release 2 (8.1.6)

Part Number A76958-01

Library

Product

Contents

Index

Go to previous page Go to beginning of chapter Go to next page

Create a Master Group, 3 of 3


Create Master Group

/*************************************************************************
STEP 1:
CREATE SCHEMA AT MASTER SITES
*************************************************************************/

CONNECT system/manager@orc2.world;
CREATE USER scott IDENTIFIED BY tiger;
GRANT CONNECT, RESOURCE TO scott;

CONNECT system/manager@orc3.world;
CREATE USER scott IDENTIFIED BY tiger;
GRANT CONNECT, RESOURCE TO scott;

/*************************************************************************
STEP 2:
CREATE MASTER GROUP
*************************************************************************/

--Use the CREATE_MASTER_REPGROUP API to define a new master group.
--When you add an object to your master group or perform other replication
--administrative tasks, you reference the master group name defined
--during this step. The following must be executed by the replication
--administrator.

CONNECT repadmin/repadmin@orc1.world

BEGIN
   DBMS_REPCAT.CREATE_MASTER_REPGROUP (
      gname => 'SCOTT_MG');
END;
/

/*************************************************************************
STEP 3:
ADD OBJECTS TO MASTER GROUP
*************************************************************************/

--Use the CREATE_MASTER_REPOBJECT API to add an object to your master group.
--In most cases, you probably will be adding tables to your master group,
--but you can also add indexes, procedures, views, synonyms, and so on.  See
--CREATE_MASTER_REPOBJECT procedure for additional
--information. 

BEGIN
   DBMS_REPCAT.CREATE_MASTER_REPOBJECT (
      gname => 'SCOTT_MG',
      type => 'TABLE',
      oname => 'EMP',
      sname => 'SCOTT',
      use_existing_object => TRUE,
      copy_rows => TRUE);
END;
/

BEGIN
   DBMS_REPCAT.CREATE_MASTER_REPOBJECT (
      gname => 'SCOTT_MG',
      type => 'TABLE',
      oname => 'dept',
      sname => 'SCOTT',
      use_existing_object => TRUE,
      copy_rows => TRUE);
END;
/

--The tables EMP and DEPT have a primary key, but BONUS and SALGRADE do not have 
--a primary key. For replication to work properly, each replicated table either 
--needs a primary key or to have a "set column." The 
--DBMS_REPCAT.SET_COLUMNS procedure is sufficient for multimaster replication 
--only, but if you also want to support fast refreshable snapshots, you need a 
--primary key. It is easier to alter your object before you add it to your 
--master group.

ALTER TABLE scott.bonus ADD (CONSTRAINT bonus_pk PRIMARY KEY(ename));

BEGIN
   DBMS_REPCAT.CREATE_MASTER_REPOBJECT (
      gname => 'SCOTT_MG',
      type => 'TABLE',
      oname => 'bonus',
      sname => 'SCOTT',
      use_existing_object => TRUE,
      copy_rows => TRUE);
END;
/

--You must modify the SCOTT.SALGRADE object just as you altered the
--SCOTT.BONUS object in the previous step.

ALTER TABLE scott.salgrade ADD (CONSTRAINT salgrade_pk PRIMARY KEY(grade));

BEGIN
   DBMS_REPCAT.CREATE_MASTER_REPOBJECT (
      gname => 'SCOTT_MG',
      type => 'TABLE',
      oname => 'salgrade',
      sname => 'SCOTT',
      use_existing_object => TRUE,
      copy_rows => TRUE);
END;
/

/*************************************************************************
STEP 4:
ADD ADDITIONAL MASTER SITES
*************************************************************************/

--After you have defined your master group at the MASTERDEF site (the
--site where the master group was created becomes the MASTER DEFINITION
--site by default), you can define the other sites that will participate
--in the replicated environment. You might have guessed that you will be
--adding the ORC2.WORLD and ORC3.WORLD sites to our replicated environment.

BEGIN
   DBMS_REPCAT.ADD_MASTER_DATABASE (
      gname => 'SCOTT_MG',
      master => 'ORC2.WORLD',
      use_existing_objects => TRUE,
      copy_rows => TRUE,
      propagation_mode => 'ASYNCHRONOUS');
END;
/

/*************************************************************************
NOTE: You should wait until ORC2.WORLD appears in the DBA_REPSITES view
before continuing. Execute the following SELECT statement in another
SQL*Plus session to make sure that ORC2.WORLD has appeared):

SELECT * FROM dba_repsites WHERE gname = 'SCOTT_MG';
*************************************************************************/
PAUSE Press <RETURN> to continue.
BEGIN
   DBMS_REPCAT.ADD_MASTER_DATABASE (
      gname => 'SCOTT_MG',
      master => 'ORC3.WORLD',
      use_existing_objects => TRUE,
      copy_rows => TRUE,
      propagation_mode => 'ASYNCHRONOUS');
END;
/

/*************************************************************************
NOTE: You should wait until ORC3.WORLD appears in the DBA_REPSITES view
before continuing. Execute the following SELECT statement in another
SQL*Plus session to make sure that ORC3.WORLD has appeared):

SELECT * FROM dba_repsites WHERE gname = 'SCOTT_MG';
*************************************************************************/
PAUSE Press <RETURN> to continue.

/*************************************************************************
CAUTION:  If you added one or more tables to a master group during creation 
of the group, do not resume replication activity immediately. First consider 
the possibility of replication conflicts, and configure conflict resolution 
for the replicated tables in the group. See Chapter 6, "Conflict Resolution"  
for more information about configuring conflict resolution for master group 
objects.
*************************************************************************/

/*************************************************************************
STEP 5:
GENERATE REPLICATION SUPPORT
*************************************************************************/

BEGIN 
    DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT (
      sname => 'SCOTT',
      oname => 'EMP', 
      type => 'TABLE',
      min_communication => TRUE); 
END;
/

BEGIN 
    DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT (
      sname => 'SCOTT',
      oname => 'dept', 
      type => 'TABLE',
      min_communication => TRUE); 
END;
/

BEGIN 
    DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT (
      sname => 'SCOTT',
      oname => 'bonus', 
      type => 'TABLE',
      min_communication => TRUE); 
END;
/

BEGIN 
    DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT (
      sname => 'SCOTT',
      oname => 'salgrade', 
      type => 'TABLE',
      min_communication => TRUE); 
END;
/

/*************************************************************************
NOTE: You should wait until the DBA_REPCATLOG view is empty before
resuming master activity. Execute the following SELECT statement
to monitor your DBA_REPCATLOG view:

SELECT * FROM dba_repcatlog WHERE gname = 'SCOTT_MG';
*************************************************************************/
PAUSE Press <RETURN> to continue.

/*************************************************************************
STEP 6:
RESUME REPLICATION
*************************************************************************/

--After you have completed creating your master group, adding replication
--objects, generating replication support, and adding additional master
--databases, you need to resume replication activity. The 
--RESUME_MASTER_ACTIVITY procedure API "turns on" replication for 
--the specified master group.

BEGIN 
   DBMS_REPCAT.RESUME_MASTER_ACTIVITY (
      gname => 'SCOTT_MG'); 
END;
/



Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 1996-2000, Oracle Corporation.

All Rights Reserved.

Library

Product

Contents

Index