Skip Headers

Oracle® Database Advanced Replication Management API Reference
10g Release 1 (10.1)

Part Number B10733-01
Go to Documentation Home
Home
< a href="../../nav/portal_3.htm">Go to Book List
Book List
Go to Table o
f Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback

Go to previous page
Previous
Go to next page
Next
View PDF

2
Create Replication Site
< /h1>

This chapter illustrates how to set up both a master site and a materialize d view replication site using the replication management API.

This chapter contains these top ics:

Overview of Setting Up Replication Sites

Before you build your replication environment, you need to set u p the sites that will participate in the replication environment. As illustrated in Figure 2-2 a nd Figure 2-3, there are separate processes for setting up a master site versus setting up a ma terialized view site.

The examples in this chapter use the following databases:

Chapters 2 - 6 work with the replication environment illustrated in Figure 2-1. You start to create this environment using the instructions in this chapter. Notice that mv2.world is a materialized view based on the mv1.world materialized view, creating a multitier materialized vie w environment. The arrows in Figure 2-1 represent database links.

Figure 2-1 Three Master Sites and Two Materialized View Sites Text description of rarreps3.gif follows

T ext description of the illustration rarreps3.gif

Follow the procedures identified in Figure 2-2 when you build a new master site or in Figure 2-3 w hen you build a new materialized view site.

Fi gure 2-2 Setting Up Master Sites

Text description of rarreps2.gif follo
ws

Text description of the illustration rarreps2.gif

Setting Up Master Sites

The following sections contain step-by-step instructions for setting up the three master sites in our sample replication environment: orc1.world, orc2.world, and orc3.world< /code>. Before you set up the master sites, configure your network and Oracle Net so that all three databases can communicate with ea ch other.


Note:

If you are viewing this document online, then you can copy the text from the "BEGINNING OF SCRIPT" line after t his note to the "END OF SCRIPT" line into a text editor and then edit the text to create a script fo r your environment.


/************************* BEGINNING OF SCRI
PT ******************************

Setting Up orc1.world

Complete the following s teps to set up the orc1.world master site.

Step 1 Connect as SYSTEM at a master site at orc1.world.

Connect as SYST EM to the database that you want to set up for replication. After you set up orc1.world, begin again with Step 1 for site orc2.world and Step 1 for site orc3.world.

*/

SET ECHO ON

SPOOL setup_masters.out

CONNECT SYSTEM/MANAGER@orc1.world

/*
Step 2 Create the replication administrator at orc1.world.
< /a>

The replication administrator must be granted the necessary privileges to create and manage a replication environm ent. The replication administrator must be created at each database that participates in the replication environment.

*/

CREATE USER repadmin IDENTIFIED BY repadmin;

/*
Step 3 Grant privileg es to the replication administrator at orc1.world.

Execute the GRANT_ADMIN_ANY_ SCHEMA procedure to grant the replication administrator powerful privileges to create and manage a replicated environment.

*/

BEGIN
DBMS_REPCAT_ADMIN.GRANT_ADMIN_ANY_SCHEMA (
      username => 'repadmin');
END;
/

/*

If you w ant your repadmin to be able to create materialized view logs for any replicated table, then grant COMMENT ANY TABLE and LOCK ANY TABLE to repadmin:

*/

GRANT COMMENT ANY TABLE TO repadmin;
GRANT
 LOCK ANY TABLE TO repadmin;

/*

If you want your repadmin to be able to connect to the Replication Management tool, then grant SELECT < code>ANY DICTIONARY to repadmin:

*/

GRANT SELECT ANY DICTIONARY TO repadmin;

/*
Step 4 Register the propagator at orc1.world.

The propagator is responsible for propagating the deferred transaction queue to other master sites.

*/

BEGIN
DBMS_DEFER_S
YS.REGISTER_PROPAGATOR (
      username => 'repadmin');
END;
/

/*
Step 5 Register the receiver at orc1.world.

The receiver receives the propagated deferred tr ansactions sent by the propagator from other master sites.

*/

BEGIN
DBMS_REPCAT_ADMIN.REGISTER_USER_REPGROUP (

   username => 'repadmin',
      privilege_type => 'receiver',
      list_of_gnames =>
 NULL);
END;
/

/*

Step 6 Schedule purge at master site orc1.world.

In order to keep the size of the deferred transaction queue in check, you should purge successfu lly completed deferred transactions. The SCHEDULE_PURGE procedure automates the purge process for you. You must execute this procedure as the replication administrator.


Note:

Date expressions are used for the NEXT_DATE and INTER VAL parameters. For example:

  • Now is specified as: SYS DATE
  • An interval of one hour is specified as: SYSDATE + 1/24< /li>
  • An interval of seven days could be specified as: SYSDATE + 7

*/

CONNECT repadmin/repa
dmin@orc1.world

BEGIN
DBMS_DEFER_SYS.SCHEDUL
E_PURGE (
      next_date => SYSDATE,
      interval => 'SYSDATE + 1/24',
      delay_seconds => 0);
END;
/

/*



See Also:

Oracle Database Administrato r's Guide and Oracle Database SQL Refere nce for more information about date expressions

Step 7 Create proxy master site users at orc1.world.

If you plan to create materialized view sites based on this master site, then create proxy master site users at orc1.world that correspond to users at the materialized view site.

Create the proxy materialized view administrator.

The proxy materialized view administrator performs tasks at the target master site on behalf of the materialized view administrator at the materialized view site.

*/

CONNECT SYSTEM/MANAGER@orc1.world

CREATE USER proxy_mvi
ewadmin IDENTIFIED BY proxy_mviewadmin;

BEGIN
DBMS_REPCAT_ADMIN.REGISTER_USER_REPGROUP (
      username => 'proxy_mviewadmin',

    privilege_type => 'proxy_snapadmin',
      list_of_gnames => NULL);
END;
/

-- Place GRANT SELECT_CATALOG_ROLE statement here if necessary.


/*

If you want your materialized view admini strator at materialized view sites to be able to perform administrative operations using the Replication Management tool, then grant SELECT_CATALOG_ROLE to proxy_mviewadmin:

GRANT SELECT_CATALOG_ROLE
TO proxy_mviewadmin;

Granting this privilege to the proxy_mview admin is not required if you do not plan to use the Replication Management tool. However, if you plan to use the Replication M anagement tool, then move the GRANT statement to the line directly after the previous REGISTER_USER_REPGROUP statement.

Create the proxy refresher.

The proxy re fresher performs tasks at the master site on behalf of the refresher at the materialized view site.

*/

CREATE USER proxy_refresher IDENTIFIED BY proxy_refresher;

GRANT CREATE SESSION TO proxy_refresher;
GRANT SELECT ANY TABLE TO proxy_refresher;

/*
See Also:

"Security Setup for Materialized View Replication "

Setting Up orc2.world

C omplete the following steps to set up the orc2.world master site.

Step 1 Connect as SYSTEM at orc2.world.

You must connec t as SYSTEM to the database that you want to set up for replication. After you set up orc2.world, begin wit h Step 1 for site orc3.world.

*/

CONNECT SYSTEM/MANAGER@orc2.world

/*
Step 2 Create the replication administrat or at orc2.world.

The replication administrator must be granted the necessary privile ges to create and manage a replication environment. The replication administrator must be created at each database that participates in the replication environment.

*/

create user REPAD
MIN identified by REPADMIN;

/*
Step 3 Grant privileges to replication administrator at orc2.world.

Execute the GRANT_ADMIN_ANY_SCHEMA procedure to grant the replication administrator powerful privileges to crea te and manage a replicated environment.

*/

BEGIN
DBMS_REPCAT_ADMIN.GRANT_ADMIN_ANY_SCHEMA (
      username =>
 'repadmin');
END;
/

/*

If you want your repadmin to be able to create materialized view logs for any replic ated table, then grant COMMENT ANY TABLE and LOCK ANY TABLE privileges to repadmin:

*/

GRANT C
OMMENT ANY TABLE TO repadmin;
GRANT LOCK ANY TABLE TO repadmin;

/*

If you want your repadmin to be able to connect to the Replic ation Management tool, then grant SELECT ANY DICTIONARY to repadmin:

*/

GRANT SELECT ANY DICTIONARY TO repadmin;


/*
Step 4 Register the pr opagator at orc2.world.

The propagator is responsible for propagating the deferred tr ansaction queue to other master sites.

*/

BEGIN
DBMS_DEFER_SYS.REGISTER_PROPAGATOR (
      username => 'repad
min');
END;
/

/*
Step 5 Register the receiver at orc2.world.

The receiver receives the propagated deferred transactions sent by the propagator from the other master sites.

*/

BEGIN
DBMS_
REPCAT_ADMIN.REGISTER_USER_REPGROUP (
      username => 'repadmin',
      privilege_ty
pe => 'receiver',
      list_of_gnames => NULL);
END;
/

/*
Step 6 Schedu le purge at master site at orc2.world.

In order to keep the size of the deferred tran saction queue in check, you should purge successfully completed deferred transactions. The SCHEDULE_PURGE procedure auto mates the purge process for you. You must execute this procedure as the replication administrator.

*/

CONNECT repadmin/repadmin@orc2.world

BEGIN

DBMS_DEFER_SYS.SCHEDULE_PURGE (
      next_date => SYSDA
TE,
      interval => 'SYSDATE + 1/24',
      delay_seconds => 0);

END;
/

/*
Step 7 Create proxy master site users at orc2.world.

If you plan to create materialized view sites based on this master site, then create proxy master site users at orc2.world that correspond to users at the materialized view site.

Create the proxy materialized view admini strator.

The proxy materialized view administrator performs tasks at the target master site o n behalf of the materialized view administrator at the materialized view site.

*/

CONNECT SYSTEM/MANAGER@orc2.world

CREATE USER proxy_mviewadmin
 IDENTIFIED BY proxy_mviewadmin;

BEGIN
DBMS
_REPCAT_ADMIN.REGISTER_USER_REPGROUP (
      username => 'proxy_mviewadmin',
      pri
vilege_type => 'proxy_snapadmin',
      list_of_gnames => NULL);
END;
<
/a>/

-- Place GRANT SELECT_CATALOG_ROLE statement here if necessary.

/*

If you want your materialized view administrator at materialized view sites to be able to perform administrative operations using the Replication Management tool, then grant S ELECT_CATALOG_ROLE to proxy_mviewadmin:

*/

GRANT SELECT_CATALOG_ROLE TO proxy_mviewadmin;

/*

Granting this privilege to the proxy_mviewadmin is not required if you do not plan to u se the Replication Management tool. However, if you plan to use the Replication Management tool, then move the GRANT sta tement to the line directly after the previous REGISTER_USER_REPGROUP statement.

Create the proxy refresher.

The proxy refresher performs tasks at the master site on behalf of the refresher at the materialized view site.

*/

C
REATE USER proxy_refresher IDENTIFIED BY proxy_refresher;

GRANT CREATE SESSION TO proxy_refr
esher;
GRANT SELECT ANY TABLE TO proxy_refresher;

/*

Setti ng Up orc3.world

Complete the following steps to set up the orc3 .world master site.

Step 1 Connect as SYST EM at orc3.world.

You must connect as SYSTEM to the database that you wa nt to set up for replication.

*/

CONNECT SYSTEM/MANA
GER@orc3.world

/*
Step 2 Create the replication administrator at orc3.world.

The replicati on administrator must be granted the necessary privileges to create and manage a replication environment. The replication administrat or must be created at each database that participates in the replication environment.

*/

create user REPADMIN identified by REPADMIN;

/*
Step 3 Grant privileges to replication administrator at orc3.world.

Execute the GRANT_ADMIN_ANY_SCHEMA procedure to grant the replication administrator powerful privileges to create and manage a replicated environment.

*/

BEGIN
DBMS_REPCAT_ADMIN.GRANT_ADMIN_ANY
_SCHEMA (
      username => 'repadmin');
END;
/

/*

If you want your repadmin to b e able to create materialized view logs for any replicated table, then grant COMMENT ANY TABLE and LOCK ANY TABLE to repadmin:

*/

GRANT COMMENT ANY TABLE TO repadmin;
GRANT LOCK ANY TABLE TO repadmin;

/*

If you want your repadmin to be able to connect to the Replication Management tool, then grant SELECT ANY DICTIONARY to repadmin:

*/

GRANT SELECT ANY D
ICTIONARY TO repadmin;

/*
Step 4 Register the propagator at orc3.world.

The propagator is responsible for propagating the deferred transaction queue to other master sites.

*/

BEGIN
DBMS_DEFER_SYS.REGISTER_PROPAGATOR (
      username => 'repadmin');
END;
/

/*

Step 5 Register t he receiver at orc3.world.

The receiver receives the propagated deferred transactions sent by the propagator from the other master sites.

*/


BEGIN
DBMS_REPCAT_ADMIN.REGISTER_USER_REPGROUP (
      u
sername => 'repadmin',
      privilege_type => 'receiver',
      list_of_gnames => N
ULL);
END;
/

/*
Step 6 Schedule purge at master site at orc3.world.

In order to keep the size of the deferred transaction queue in check, you should purge successfully completed defer red transactions. The SCHEDULE_PURGE API automates the purge process for you. You must execute this procedure as the rep lication administrator.

*/

CONNECT repadmin/repadmin
@orc3.world

BEGIN
DBMS_DEFER_SYS.SCHEDULE_P
URGE (
      next_date => SYSDATE,
      interval => 'SYSDATE + 1/24',
      delay_seconds => 0);
END;
/

/*



Step 7 Create proxy master site users at orc1.worl d.

If you plan to create materialized view sites based on this master site, then crea te proxy master site users at orc1.world that correspond to users at the materialized view site.

Create the proxy materialized view administrator.

The proxy materialized vie w administrator performs tasks at the target master site on behalf of the materialized view administrator at the materialized view si te.

*/

CONNECT SYSTEM/MANAGER@orc3.world

CREATE USER proxy_mviewadmin IDENTIFIED BY proxy_mviewadmin;

B
EGIN
DBMS_REPCAT_ADMIN.REGISTER_USER_REPGROUP (
      userna
me => 'proxy_mviewadmin',
      privilege_type => 'proxy_snapadmin',
      list_of_gnam
es => NULL);
END;
/

-- Place GRANT SELECT_CATALOG
_ROLE statement here if necessary.

/*

If you want your materialized view administrator at materialized view sites to be able to perform administrative operations using the Replication Management tool, then grant SELECT_CATALOG_ROLE to proxy_mviewadmin:

*/

GRANT SELECT_CATALOG_ROLE TO proxy_mviewadmin;
<
/a>
/*

Granting this privilege to the proxy _mviewadmin is not required if you do not plan to use the Replication Management tool. However, if you plan to use the Replica tion Management tool, then move the GRANT statement to the line directly after the previous REGISTER_USER_REPGROUP statement.

Create proxy refresher.

The proxy refresher performs tasks at the master site on behalf of the refresher at the materialized view site.

*/

CREATE USER proxy_refresher IDENTIFIED BY proxy_refresher;

GRANT CREATE SESSION TO proxy_refresher;
GRANT SELECT ANY TABLE TO proxy_refresher;

/*
See Also:

"Security Setup for Materialized View Replication"

Se e Also:

"Security Setup for Materialized View Replicati on"

Creating Scheduled Links Between the Master Sites

Complete the following steps to create scheduled links between the master sites.

Step 1 Create database links between master sites.

The database links provide the necessary distributed mechanisms to allow the different replication sites t o replicate data among themselves. Before you create any private database links, you must create the public database links that each private database link will use. You then must create a database link between all replication administrators at each of the master sit es that you have set up.

See Also:

Oracle Database Administrator's Guide for more information about database links

*/

CONNECT SYSTEM/MANAGER@orc1.world
<
/a>CREATE PUBLIC DATABASE LINK orc2.world USING 'orc2.world';
CREATE PUBLIC DATABASE LINK orc3.world USING 'orc3.
world';

CONNECT repadmin/repadmin@orc1.world
CREATE DATABASE LINK orc2.w
orld CONNECT TO repadmin IDENTIFIED BY repadmin;
CREATE DATABASE LINK orc3.world CONNECT TO repadmin IDENTIFIED B
Y repadmin;

CONNECT SYSTEM/MANAGER@orc2.world
CREATE PUBLIC DATABASE LIN
K orc1.world USING 'orc1.world';
CREATE PUBLIC DATABASE LINK orc3.world USING 'orc3.world';

CONNECT repadmin/repadmin@orc2.world
CREATE DATABASE LINK orc1.world CONNECT TO repadmin IDEN
TIFIED BY repadmin;
CREATE DATABASE LINK orc3.world CONNECT TO repadmin IDENTIFIED BY repadmin;
<
/a>
CONNECT SYSTEM/MANAGER@orc3.world
CREATE PUBLIC DATABASE LINK orc1.world USING 'orc1.worl
d';
CREATE PUBLIC DATABASE LINK orc2.world USING 'orc2.world';

CONNECT r
epadmin/repadmin@orc3.world
CREATE DATABASE LINK orc1.world CONNECT TO repadmin IDENTIFIED BY repadmin;
CREATE DATABASE LINK orc2.world CONNECT TO repadmin IDENTIFIED BY repadmin;

/*



Step 2 Define a schedule for each database link to create scheduled links.

Create a scheduled link by defining a database link when y ou execute the SCHEDULE_PUSH procedure. The scheduled link determines how often your deferred transaction queue is propa gated to each of the other master sites. You need to execute the SCHEDULE_PUSH procedure for each database link that you created in Step 1. The database link is specified in the destination parameter of the SCHEDUL E_PUSH procedure.

Even when using Oracle's asynchronous replication mechanisms, you ca n configure a scheduled link to simulate continuous, real-time replication. The scheduled links in this example simulate continuous r eplication.

See Also:

Oracle Database Advanced Replication for more information about simulating continuous replication

*/

CONNECT repadmin/repadmin@orc1.world

BEGIN
DBMS_DEFER_SYS.SCHEDULE_PUSH (
      destination => 'orc2.world',
      interval => 'SYSDATE + (1/144)',
      ne
xt_date => SYSDATE,
      parallelism => 1,
      execution_seconds => 1500,
      delay_seconds => 1200);
END;
/

BEGIN
DBMS_DEFER_SYS.SCHEDULE_PUSH (
      destination =>
; 'orc2.world',
      interval => 'SYSDATE + (1/144)',
      next_date => SYSDATE,
      parallelism => 1,
      execution_seconds => 1500,
      delay_se
conds => 1200);
END;
/

BEGIN

DBMS_DEFER_SYS.SCHEDULE_PUSH (
      destination => 'orc3.world',
      interval => 'SYSDATE + (1/144)',
      next_date => SYSDATE,
      paral
lelism => 1,
      execution_seconds => 1500,
      delay_seconds => 1200);
END;
/

CONNECT repadmin/repadmin@orc2.world


BEGIN
DBMS_DEFER_SYS.SCHEDULE_PUSH (
      destination => 'orc1.world',
      interval => 'SYSDATE + (1/144)',
      next_
date => SYSDATE,
      parallelism => 1,
      execution_seconds => 1500,
      delay_seconds => 1200);
END;
/

BE
GIN
DBMS_DEFER_SYS.SCHEDULE_PUSH (
      destination => '
orc3.world',
      interval => 'SYSDATE + (1/144)',
      next_date => SYSDATE,
      parallelism => 1,
      execution_seconds => 1500,
      delay_secon
ds => 1200);
END;
/

CONNECT repadmin/repadmin@orc
3.world

BEGIN
DBMS_DEFER_SYS.SCHEDULE_PUSH
(
      destination => 'orc1.world',
      interval => 'SYSDATE + (1/144)',
      next_date => SYSDATE,
      parallelism => 1,
      execution_second
s => 1500,
      delay_seconds => 1200);
END;
/

BEGIN
DBMS_DEFER_SYS.SCHEDULE_PUSH (

     destination => 'orc2.world',
      interval => 'SYSDATE + (1/144)',
      next_dat
e => SYSDATE,
      parallelism => 1,
      execution_seconds => 1500,
      delay_seconds => 1200);
END;
/

SET E
CHO OFF

SPOOL OFF

/**************************END OF
 SCRIPT***********************************/

Setting Up Materialized View Sites

Figure 2-3 Setting Up Materialized View Sites

< a name="25808">Text description of rarrepsa.gif follows

Text d escription of the illustration rarrepsa.gif

Setting Up mv1.world

Complete the f ollowing steps to set up the mv1.world master materialized view site. mv1.world is a master materialized vi ew site because mv2.world will be based on it. Before you set up the materialized sites, configure your network and Orac le Net so that all mv1.world can communicate with orc1.world and mv2.world can communicate wit h mv1.world.


Note:

If you are viewing this document online, then you can copy the text from the "BEGINNING OF SCRI PT" line after this note to the "END OF SCRIPT" line into a text editor and then edit the text to cr eate a script for your environment.


/************************* B
EGINNING OF SCRIPT ******************************
Step 1 Connect as SYSTEM at materialized view site at mv1.world.

You must connect as SYSTEM to the database that you want to set up as a materialized view site.

*
/

SET ECHO ON

SPOOL setup_mvs.out
<
/a>
CONNECT SYSTEM/MANAGER@mv1.world

/*
Step 2 Create materialized view site users at mv1.world.

Several users must be created at the materialized view site. These users are:

  • Materialized view administrator
  • Propagator
  • Refresher
  • Receiver (if the site will serve as a master materialized view site for other materialized views, as mv1.world is)

Complete the following tasks to create these users.

Create the materialized view administrator.

The materialized view admin istrator is responsible for creating and managing the materialized view site. Execute the GRANT_ADMIN_ANY_SCHEMA procedu re to grant the materialized view administrator the appropriate privileges.

*/

create user MVIEWADMIN identified by MVIEWADMIN;

BEGIN
DBMS_REPCAT_ADMIN.GRANT_ADMIN_ANY_SCHEMA (
      username => 'mviewa
dmin');
END;
/

GRANT COMMENT ANY TABLE TO mviewadmin
;

GRANT LOCK ANY TABLE TO mviewadmin;

/*


If you want your mviewadmin to be able to connect to the Replicat ion Management tool, then grant SELECT ANY DICTIONARY to mviewadmin:

*/

GRANT SELECT ANY DICTIONARY TO mviewadmin;

/*

Create the propagator.

The propagator is responsible for propagating the deferred transaction queue to the target master site.

*/

CREATE USER propagator IDENTIFIED BY propagator;

BEGIN
DBMS_DEFER_SYS.REGISTER_PROPAGATOR (
      username => 'propagator');
END;
/

/*

Create the refresher.

The refresher is responsible for "pulling" changes made to the replicated tables at the target master site to the materialized view site. This user refreshes one or more materialized views. If you want the mviewadmin user to be the refresher, then this step is not required.

*/

CREATE USER refresher IDENTIFIED BY re
fresher;

GRANT CREATE SESSION TO refresher;

GRANT A
LTER ANY MATERIALIZED VIEW TO refresher;

/*

Register the receiver.

The receiver receives the propagated deferred transact ions sent by the propagator from materialized view sites. The receiver is necessary only if the site will function as a master materi alized view site for other materialized view sites.

*/

<
/a>BEGIN
DBMS_REPCAT_ADMIN.REGISTER_USER_REPGROUP (
      us
ername => 'mviewadmin',
      privilege_type => 'receiver',
      list_of_gnames =>
NULL);
END;
/

/*
Step 3 Create database links to the master site.

Create a public database link.

*/

CO
NNECT SYSTEM/MANAGER@mv1.world

CREATE PUBLIC DATABASE LINK orc1.world USING 'orc1.world';

/*

Create the materialized vie w administrator database link.

You need to create a database link from the materialized view administrator at the materialized view site to the proxy materialized view administrator at the master site.

*/

CONNECT mviewadmin/mviewadmin@mv1.world;

CREATE DATABASE LINK orc1.world 
  CONNECT TO proxy_mviewadmin IDENTIFIED BY proxy_mviewadmin;

/*

Create the propagator/receiver dat abase link.

You need to create a database link from the propagator at the materialized view s ite to the receiver at the master site. The receiver was defined when you created the master site.

*/

CONNECT propagator/propagator@mv1.world

CR
EATE DATABASE LINK orc1.world 
  CONNECT TO repadmin IDENTIFIED BY repadmin;

/*
See Also:

Step 5

Step 4 Schedule purge at the mv1.world materialized view site.

In order to keep the size of the deferred transaction queue in check, you should purge successfully completed deferred transactions. The SCHEDULE_PURGE procedure automates the purge process for you. If your materialized view site only contains "read-only" materialized views, then you do not need to execute this procedure.

*/

CONNECT mviewadmin/mviewadmin@mv1.world

BEGIN
DBMS_DEFER_SYS.SCHEDULE_PURGE (

   next_date => SYSDATE,
   interval => 'SYSDATE + 1/24',
   delay_seconds => 0,
<
a name="8428">   rollback_segment => '');
END;
/

<
/a>/*
Step 5 Schedule push at the mv1.world ma terialized view site (optional).

If the materialized view site has a constant connect ion to its master site, then you optionally can schedule push at the mv1.world materialized view site. If the materializ ed view site is disconnected from its master site for extended periods of time, then it is typically better not to schedule push and refresh on demand, which pushes changes to the master site.

The SCHEDULE_PUSH pr ocedure schedules when the deferred transaction queue should be propagated to the target master site.

*/

CONNECT mviewadmin/mviewadmin@mv1.world


BEGIN
DBMS_DEFER_SYS.SCHEDULE_PUSH (
      destination => '
orc1.world',
      interval => 'SYSDATE + 1/24',
      next_date => SYSDATE,
      stop_on_error => FALSE,
      delay_seconds => 0,
      parallelism => 0)
;
END;
/

/*
Step 6 Create proxy users at the mv1.world materialized view site.

Create the proxy materialized view administrator.

The proxy mater ialized view administrator performs tasks at the target master materialized view site on behalf of the materialized view administrato r at the materialized view sites based on this materialized view site. This user is not required if the site will not function as a m aster materialized view site for other materialized view sites.

*/

CONNECT SYSTEM/MANAGER@mv1.world

CREATE USER proxy_mviewadmin IDENTIFIED BY p
roxy_mviewadmin;

BEGIN
DBMS_REPCAT_ADMIN.RE
GISTER_USER_REPGROUP (
      username => 'proxy_mviewadmin',
      privilege_type =>
; 'proxy_snapadmin',
      list_of_gnames => NULL);
END;
/

-- Place GRANT SELECT_CATALOG_ROLE statement here if necessary.

/*

If you want your materialized view administrator at materialized view sites based on this materialized view site to be able to perform administrative operations using the Replication Management too l, then grant SELECT_CATALOG_ROLE to proxy_mviewadmin:

GRANT SELECT
_CATALOG_ROLE TO proxy_mviewadmin;

Granting this privilege to the proxy_mviewadmin is not required if you do not plan to use the Replication Management tool. However, if you plan to use the Replication Management tool, then move the GRANT statement to the line directly after the previous REGISTER_USER_ REPGROUP statement.

Create the proxy refresher.

The proxy refresher performs tasks at the master materialized view site on behalf of the refresher at the materialized view sites b ased on this materialized view site. This user is not required if the site will not function as a master materialized view site for o ther materialized view sites.

*/

CREATE USER proxy_r
efresher IDENTIFIED BY proxy_refresher;

GRANT CREATE SESSION TO proxy_refresher;
GRANT SELECT ANY TABLE TO proxy_refresher;

/*

Setting Up mv2.world

Complete the following steps to set up the mv2.world materi alized view site. mv2.world is part of a multitier materialized view configuration because it is based on mv1.worl d, another materialized view.

Step 1 Conne ct as SYSTEM at level 2 materialized view site mv2.world.

You must connect as S YSTEM to the database that you want to set up as a level 2 materialized view site. This site, mv2.world, wil l be a materialized view site that is based on mv1.world.

*/

CONNECT SYSTEM/MANAGER@mv2.world

/*
Step 2 Create level 2 materialized view site users at mv2.world.

Several users must be created at the level 2 materialized view site. These users are:

  • Materialized view administrator
  • Propagator
  • Refresher

Complete the following tasks to create these users.

Create the materialized view administrator.

The materialized view administrator is responsible for creating and mana ging the level 2 materialized view site. Execute the GRANT_ADMIN_ANY_SCHEMA procedure to grant the materialized view adm inistrator the appropriate privileges.

*/

create use
r MVIEWADMIN identified by MVIEWADMIN;

BEGIN
DBMS_REPCAT_ADMIN.GRANT_ADMIN_ANY_SCHEMA (
      username => 'mviewadmin');
END;
/

/*

If you want your mviewadmin to be able to connect to the Replication Management tool, then grant SELECT ANY DICTIONARY to mviewadmin:

*/

GRANT SELECT ANY DICTIONARY TO mviewadmin;

/*

Create the propagator.

The propagator is responsible for propaga ting the deferred transaction queue to the target master materialized view site.

*/

CREATE USER propagator IDENTIFIED BY propagator;

BEGIN
DBMS_DEFER_SYS.REGISTER_PROPAGATOR (
      username => 'propag
ator');
END;
/

/*

Create the refresher.

The refresher is responsible for "pulling " changes made to the replicated materialized views at the target master materialized view site to the level 2 materialized view site .

*/

CREATE USER refresher IDENTIFIED BY refresher;

GRANT CREATE SESSION TO refresher;
GRANT ALTER ANY MATERIALIZED VIEW TO
refresher;

/*
Step 3 Create database links to master materialized view site.

Create a publ ic database link.

*/

CONNECT SYSTEM/MANAGER@mv2.worl
d

CREATE PUBLIC DATABASE LINK mv1.world USING 'mv1.world';

/*

Create materialized view administrator database link.

You need to create a database link from the materialized view administrator at the level 2 materi alized view site to the proxy materialized view administrator at the master materialized view site.

*/

CONNECT mviewadmin/mviewadmin@mv2.world;


CREATE DATABASE LINK mv1.world 
  CONNECT TO proxy_mviewadmin IDENTIFIED BY proxy_mviewadmin;

/*

Create a propagator/receiver database link.< /p>

You need to create a database link from the propagator at the level 2 materialized view site to the receiver at the master materialized view site. The receiver was defined when you created the master materialized view site.

*/

CONNECT propagator/propagator@mv2.world

CREATE DATABASE LINK mv1.world 
  CONNECT TO mviewadmin IDENTIFIED BY mviewadmin;
<
a name="22400">
/*
Ste p 4 Schedule purge at level 2 materialized view site at mv2.world.

In order to keep t he size of the deferred transaction queue in check, you should purge successfully completed deferred transactions. The SCHEDULE _PURGE procedure automates the purge process for you. If your level 2 materialized view site only contains "read-only" materia lized views, then you do not need to execute this procedure.

*/

CONNECT mviewadmin/mviewadmin@mv2.world

BEGIN
DBMS_DEFER_SYS.SCHEDULE_PURGE (
     next_date => SYSDATE,
     interva
l => 'SYSDATE + 1/24',
     delay_seconds => 0,
     rollback_segment => '');
END;
/

/*
Step 5 Schedule push at the mv2.world materialized view site (optional).

If the materialized view site has a constant connection to its master materialized view site, then you opt ionally can schedule push at the mv2.world materialized view site. If the materialized view site is disconnected from it s master materialized view site for extended periods of time, then it is typically better not to schedule push and refresh on demand, which pushes changes to the master materialized view site.

The SCHEDULE_PUSH pr ocedure schedules when the deferred transaction queue should be propagated to the target master materialized view site.

*/

CONNECT mviewadmin/mviewadmin@mv2.world

<
a name="19711">BEGIN
DBMS_DEFER_SYS.SCHEDULE_PUSH (

  destination => 'mv1.world',
      interval => 'SYSDATE + 1/24',
      next_date =>
 SYSDATE,
      stop_on_error => FALSE,
      delay_seconds => 0,

     parallelism => 0);
END;
/

SET ECHO OFF

SPOOL OFF

/************************* END OF SCRIPT *****
*****************************/