Oracle9i Replication Management API Reference Release 2 (9.2) Part Number A96568-01 |
|
Materialized view replication provides the flexibility to build data sets to meet the needs of your users and front-end applications, while still meeting the requirements of your security configuration. This chapter describes how to manage materialized view sites with the replication management API.
This chapter contains these topics:
Refreshing a materialized view synchronizes the data in the materialized view's master(s) and the data in the materialized view. You can either refresh all of the materialized views in a refresh group at once, or you can refresh materialized views individually. If you have applications that depend on more than one materialized view at a materialized view site, then Oracle Corporation recommends using refresh groups so that the data is transactionally consistent in all of the materialized views used by the application.
The following example refreshes the hr_refg
refresh group:
EXECUTE DBMS_REFRESH.REFRESH ('hr_refg');
The following example refreshes the hr.departments_mv
materialized view:
BEGIN DBMS_MVIEW.REFRESH ( list => 'hr.departments_mv', method => '?'); END; /
To change the master site of a materialized view group at a level 1 materialized view site to another master site, call the SWITCH_MVIEW_MASTER
procedure in the DBMS_REPCAT
package, as shown in the following example:
BEGIN DBMS_REPCAT.SWITCH_MVIEW_MASTER ( gname => 'hr_repg', master => 'orc3.world'); END; /
In this example, the master site for the hr_repg
replication group is changed to the orc3.world
master site. You must call this procedure at the materialized view site whose master site you want to change. The new database must be a master site in the replication environment. When you call this procedure, Oracle uses the new master to perform a full refresh of each materialized view in the local materialized view group. Make sure you have set up the materialized view site to use the new master site before you run the SWITCH_MVIEW_MASTER
procedure.
The entries in the SYS.SLOG$
table at the old master site for the switched materialized view are not removed. As a result, the materialized view log (MLOG$
table) of the switched updatable materialized view at the old master site has the potential to grow indefinitely, unless you purge it by calling DBMS_MVIEW.PURGE_LOG
.
You may need to drop replication activity at a materialized view site for a number of reasons. Perhaps the data requirements have changed or an employee has left the company. In any case, as a DBA you will need to drop the replication support for the target materialized view site.
This section contains the following sections:
If a materialized view group was created with a deployment template, then, before you drop the materialized view group at the remote materialized view site, you need to execute the DROP_SITE_INSTANTIATION
procedure at the target master site of the materialized view group. In addition to removing the metadata relating to the materialized view group, this procedure also removes the related deployment template data regarding this site.
The DROP_SITE_INSTANTIATION
procedure has a public and a private version. The public version allows the owner of the materialized view group to drop the materialized view site, while the private version allows the replication administrator to drop a materialized view site on behalf of the materialized view group owner.
Meet the following requirements to complete these actions:
Executed As:
Executed At:
Replication Status: Normal
Complete the following steps to drop a materialized view group created with a deployment template.
/************************* BEGINNING OF SCRIPT ******************************
*/ SET ECHO ON SPOOL drop_mv_group_public.out CONNECT hr/hr@orc3.world /*
*/ BEGIN DBMS_REPCAT_INSTANTIATE.DROP_SITE_INSTANTIATION( refresh_template_name => 'hr_refg_dt', site_name => 'orc3.world'); END; / /*
*/ CONNECT mviewadmin/mviewadmin@mv4.world /*
If you are not able to connect to the remote materialized view site, then the target materialized view group cannot refresh, but the existing data still remains at the materialized view site.
*/ BEGIN DBMS_REPCAT.DROP_MVIEW_REPGROUP ( gname => 'hr_repg', drop_contents => TRUE); END; / /*
If you want to physically remove the contents of the materialized view group from the materialized view database, then be sure that you specify TRUE
for the drop_contents
parameter.
*/ BEGIN DBMS_REFRESH.DESTROY ( name => 'hr_refg'); END; / SET ECHO OFF SPOOL OFF /************************* END OF SCRIPT **********************************/
The following steps are to be performed by the replication administrator on behalf of the materialized view group owner. Meet the following requirements to complete these actions:
Executed As:
Executed At:
Replication Status: Normal
Complete the following steps to drop a materialized view group created with a deployment template.
/************************* BEGINNING OF SCRIPT ******************************
*/ SET ECHO ON SPOOL drop_mv_group_private.out CONNECT repadmin/repadmin@orc1.world /*
*/ BEGIN DBMS_REPCAT_RGT.DROP_SITE_INSTANTIATION ( refresh_template_name => 'hr_refg_dt', user_name => 'hr', site_name => 'orc3.world'); END; / /*
*/ CONNECT mviewadmin/mviewadmin@mv4.world /*
If you are unable to connect to the remote materialized view site, then the target materialized view group cannot refresh, but the existing data still remains at the materialized view site.
*/ BEGIN DBMS_REPCAT.DROP_MVIEW_REPGROUP ( gname => 'hr_repg', drop_contents => TRUE gowner => 'hr'); END; / /*
If you want to physically remove the contents of the materialized view group from the materialized view database, then be sure that you specify TRUE
for the drop_contents
parameter.
*/ BEGIN DBMS_REFRESH.DESTROY ( name => 'hr_refg'); END; / SET ECHO OFF SPOOL OFF /************************* END OF SCRIPT **********************************/
The most secure method of removing replication support for a materialized view site is to physically drop the replicated objects or groups at the materialized view site. The following two sections describe how to drop these objects and groups while connected to the materialized view group.
Ideally, these procedures should be executed while the materialized view is connected to its target master site or master materialized view site. A connection ensures that any related metadata at the master site or master materialized view site is removed. If a connection to the master site or master materialized view site is not possible, then be sure to complete the procedure described in "Cleaning Up a Master Site or Master Materialized View Site" to manually remove the related metadata.
When it becomes necessary to remove a materialized view group from a materialized view site, use the DROP_MVIEW_REPGROUP
procedure to drop a materialized view group. When you execute this procedure and are connected to the target master site or master materialized view site, the metadata for the target materialized view group at the master site or master materialized view site is removed. If you cannot connect, then see "Cleaning Up a Master Site or Master Materialized View Site" for more information.
Meet the following requirements to complete these actions:
Executed As: Materialized View Administrator
Executed At: Remote Materialized View Site
Replication Status: N/A
Complete the following steps to drop a materialized view group at a materialized view site:
CONNECT mviewadmin/mviewadmin@mv1.world
BEGIN DBMS_REPCAT.DROP_MVIEW_REPGROUP ( gname => 'hr_repg', drop_contents => TRUE); END; /
If you want to physically remove the contents of the materialized view group from the materialized view database, then be sure that you specify TRUE
for the drop_contents
parameter.
When it becomes necessary to remove an individual materialized view from a materialized view site, use the DROP_MVIEW_REPOBJECT
procedure API to drop a materialized view. When you execute this procedure and are connected to the target master site or master materialized view site, the metadata for the target materialized view at the master site or master materialized view site is removed. If you cannot connect, then see "Cleaning Up a Master Site or Master Materialized View Site" for more information.
Meet the following requirements to complete these actions:
Executed As: Materialized View Administrator
Executed At: Remote Materialized View Site
Replication Status: N/A
Complete the following steps to drop an individual materialized view at a materialized view site.
CONNECT mviewadmin/mviewadmin@mv1.world
BEGIN DBMS_REPCAT.DROP_MVIEW_REPOBJECT ( sname => 'hr', oname => 'employees_mv1', type => 'SNAPSHOT', drop_objects => TRUE); END; /
If you want to physically remove the contents of the materialized view from the materialized view database, then be sure that you specify TRUE
for the drop_contents
parameter.
If you are unable to drop a materialized view group or materialized view object while connected to the target master site or master materialized view site, then you must remove the related metadata at the master site or master materialized view site manually. Cleaning up the metadata also ensures that you are not needlessly maintaining master table or master materialized view changes to a materialized view log. The following sections describe how to clean up your master site or master materialized view site after dropping a materialized view group or object.
If you have executed the steps described in "Dropping a Materialized View Group Created Manually" and were not connected to the master site or master materialized view site, then you are encouraged to complete the following steps to clean up the target master site or master materialized view site.
Meet the following requirements to complete these actions:
Executed As: Replication Administrator
Executed At: Master Site or Master Materialized View Site for Target Materialized View Site
Replication Status: Normal
Complete the following steps to clean up a master site or master materialized view site after dropping a materialized view group:
/************************* BEGINNING OF SCRIPT ******************************
*/ SET ECHO ON SPOOL cleanup_master1.out CONNECT repadmin/repadmin@orc1.world /*
*/ BEGIN DBMS_REPCAT.UNREGISTER_MVIEW_REPGROUP ( gname => 'hr_repg', mviewsite => 'mv1.world'); END; / /*
PURGE_MVIEW_FROM_LOG
procedure for each materialized view that was in the materialized view groups you unregistered in Step 2.
Note: If for some reason unregistering the materialized view group fails, then you should still complete this step. |
*/ BEGIN DBMS_MVIEW.PURGE_MVIEW_FROM_LOG ( mviewowner => 'hr', mviewname => 'countries_mv1', mviewsite => 'mv1.world'); END; / BEGIN DBMS_MVIEW.PURGE_MVIEW_FROM_LOG ( mviewowner => 'hr', mviewname => 'departments_mv1', mviewsite => 'mv1.world'); END; / BEGIN DBMS_MVIEW.PURGE_MVIEW_FROM_LOG ( mviewowner => 'hr', mviewname => 'employees_mv1', mviewsite => 'mv1.world'); END; / BEGIN DBMS_MVIEW.PURGE_MVIEW_FROM_LOG ( mviewowner => 'hr', mviewname => 'jobs_mv1', mviewsite => 'mv1.world'); END; / BEGIN DBMS_MVIEW.PURGE_MVIEW_FROM_LOG ( mviewowner => 'hr', mviewname => 'job_history_mv1', mviewsite => 'mv1.world'); END; / BEGIN DBMS_MVIEW.PURGE_MVIEW_FROM_LOG ( mviewowner => 'hr', mviewname => 'locations_mv1', mviewsite => 'mv1.world'); END; / BEGIN DBMS_MVIEW.PURGE_MVIEW_FROM_LOG ( mviewowner => 'hr', mviewname => 'regions_mv1', mviewsite => 'mv1.world'); END; / SET ECHO OFF SPOOL OFF /************************* END OF SCRIPT **********************************/
If you have executed the steps described in "Dropping Objects at a Materialized View Site" and were not connected to the master site or master materialized view site, then you are encouraged to complete the following steps to clean up the target master site or master materialized view site.
Meet the following requirements to complete these actions:
Executed As: Replication Administrator
Executed At: Master Site or Master Materialized View Site for Target Materialized View Site
Replication Status: Normal
Complete the following steps to clean up a master site or master materialized view site after dropping an individual materialized view.
/************************* BEGINNING OF SCRIPT ******************************
*/ SET ECHO ON SPOOL cleanup_master2.out CONNECT repadmin/repadmin@orc1.world /*
*/ BEGIN DBMS_MVIEW.UNREGISTER_MVIEW ( mviewowner => 'hr', mviewname => 'employees_mv1', mviewsite => 'mv1.world'); END; / /*
Note: If for some reason unregistering the materialized view fails, then you should still complete this step. |
*/ BEGIN DBMS_MVIEW.PURGE_MVIEW_FROM_LOG ( mviewowner => 'hr', mviewname => 'employees_mv1', mviewsite => 'mv1.world'); END; / SET ECHO OFF SPOOL OFF /************************* END OF SCRIPT **********************************/
The following sections explain how to manage materialized view logs:
After creating a materialized view log, you can alter its storage parameters and support for corresponding materialized views. The following sections explain more about altering materialized view logs. Only the following users can alter a materialized view log:
SELECT
privilege for the master table or master materialized view and ALTER
privilege on the MLOG$
_master_name, where master_name is the name of the master for the materialized view log. For example, if the master table is employees
, then the materialized view log table name is MLOG$_employees
.To alter a materialized view log's storage parameters, use the ALTER
MATERIALIZED
VIEW
LOG
statement. For example, the following statement alters a materialized view log on the employees
table in the hr
schema:
ALTER MATERIALIZED VIEW LOG ON hr.employees PCTFREE 25 PCTUSED 40;
To add new columns to a materialized view log, use the SQL statement ALTER
MATERIALIZED
VIEW
LOG
. For example, the following statement alters a materialized view log on the customers
table in the sales
schema:
ALTER MATERIALIZED VIEW LOG ON hr.employees ADD (department_id);
See Also:
Oracle9i Replication for more information about adding columns to a materialized view log |
Oracle automatically tracks which rows in a materialized view log have been used during the refreshes of materialized views, and purges these rows from the log so that the log does not grow endlessly. Because multiple simple materialized views can use the same materialized view log, rows already used to refresh one materialized view may still be needed to refresh another materialized view. Oracle does not delete rows from the log until all materialized views have used them.
For example, suppose two materialized views were created against the customers
table in a master site. Oracle refreshes the customers
materialized view at the spdb1
database. However, the server that manages the master table and associated materialized view log does not purge the materialized view log rows used during the refresh of this materialized view until the customers
materialized view at the spdb2
database also refreshes using these rows.
Because Oracle must wait for all dependent materialized views to refresh before purging rows from a materialized view log, unwanted situations can occur that cause a materialized view log to grow indefinitely when multiple materialized views are based on the same master table or master materialized view. For example, such situations can occur when more than one materialized view is based on a master table or master materialized view and one of the following conditions is true:
Always try to keep a materialized view log as small as possible to minimize the database space that it uses. To remove rows from a materialized view log and make space for newer log records, you can perform one of the following actions:
To manually purge rows from a materialized view log, execute the PURGE_LOG
procedure of the DBMS_MVIEW
package at the database that contains the log. For example, to purge entries from the materialized view log of the customers
table that are necessary only for the least recently refreshed materialized view, execute the following procedure:
BEGIN DBMS_MVIEW.PURGE_LOG ( master => 'hr.employees', num => 1, flag => 'DELETE'); END; /
Only the owner of a materialized view log or a user with the EXECUTE
privilege for the DBMS_MVIEW
package can purge rows from the materialized view log by executing the PURGE_LOG
procedure.
If a materialized view log grows and allocates many extents, then purging the log of rows does not reduce the amount of space allocated for the log. In such cases, you should truncate the materialized view log. Only the owner of a materialized view log or a user with the DELETE
ANY
TABLE
system privilege can truncate a materialized view log.
To reduce the space allocated for a materialized view log by truncating it, complete the following steps:
LOCK TABLE hr.employees IN EXCLUSIVE MODE;
MLOG$
base table) to a temporary table. For example, issue a statement similar to the following:CREATE TABLE hr.templog AS SELECT * FROM hr.MLOG$_employees;
TRUNCATE
. For example, issue a statement similar to the following:TRUNCATE hr.MLOG$_employees;
INSERT INTO hr.MLOG$_employees SELECT * FROM hr.templog; DROP TABLE hr.templog;
ROLLBACK;
To improve performance and optimize disk use, you can periodically reorganize master tables. This section describes how to reorganize a master and preserve the fast refresh capability of associated materialized views.
Note: These sections do not discuss online redefinition of tables. Online redefinition is not allowed on master tables with materialized view logs, master materialized views, or materialized views. Online redefinition is allowed only on master tables that do not have materialized view logs. See the Oracle9i Database Administrator's Guide for more information about online redefinition of tables. |
When you reorganize a table, any ROWID
information of the materialized view log must be invalidated. Oracle detects a table reorganization automatically only if the table is truncated as part of the reorganization.
If the table is not truncated, then Oracle must be notified of the table reorganization. To support table reorganizations, two procedures in the DBMS_MVIEW
package, BEGIN_TABLE_REORGANIZATION
and END_TABLE_REORGANIZATION
, notify Oracle that the specified table has been reorganized. The procedures perform clean-up operations, verify the integrity of the logs and triggers that the fast refresh mechanism needs, and invalidate the ROWID
information in the table's materialized view log. The inputs are the owner and name of the master to be reorganized. There is no output.
When a table is truncated, its materialized view log is also truncated. However, for primary key materialized views, you can preserve the materialized view log, allowing fast refreshes to continue. Although the information stored in a materialized view log is preserved, the materialized view log becomes invalid with respect to rowids when the master is truncated. The rowid information in the materialized view log will seem to be newly created and cannot be used by rowid materialized views for fast refresh.
The PRESERVE
MATERIALIZED
VIEW
LOG
option is the default. Therefore, if you specify the PRESERVE
MATERIALIZED
VIEW
LOG
option or no option, then the information in the master's materialized view log is preserved, but current rowid materialized views can use the log for a fast refresh only after a complete refresh has been performed.
Note: To ensure that any previously fast refreshable materialized view is still refreshable, follow the guidelines in "Methods of Reorganizing a Database Table". |
If the PURGE
MATERIALIZED
VIEW
LOG
option is specified, then the materialized view log is purged along with the master.
Either of the following two statements preserves materialized view log information when the master table named orders
is truncated:
TRUNCATE TABLE hr.employees PRESERVE MATERIALIZED VIEW LOG; TRUNCATE TABLE hr.employees;
The following statement truncates the materialized view log along with the master table:
TRUNCATE TABLE hr.employees PURGE MATERIALIZED VIEW LOG;
Oracle provides four table reorganization methods that preserve the capability for fast refresh. These appear in the following sections. Other reorganization methods require an initial complete refresh to enable subsequent fast refreshes.
Complete the following steps:
DBMS_MVIEW.BEGIN_TABLE_REORGANIZATION
for table employees
.employees
to employees_old
.employees
as SELECT * FROM employees_old
.DBMS_MVIEW.END_TABLE_REORGANIZATION
for new table employees
.
Caution: When a table is renamed, its associated PL/SQL triggers are also adjusted to the new name of the table. |
Ensure that no transaction is issued against the reorganized table between calling BEGIN_TABLE_REORGANIZATION
and END_TABLE_REORGANIZATION
.
Complete the following steps:
DBMS_MVIEW.BEGIN_TABLE_REORGANIZATION
for table employees
.employees
.employees
with PRESERVE
MATERIALIZED
VIEW
LOG
option.employees
using conventional path.DBMS_MVIEW.END_TABLE_REORGANIZATION
for new table employees
.
Caution: When you truncate masters as part of a reorganization, you must use the |
Ensure that no transaction is issued against the reorganized table between calling BEGIN_TABLE_REORGANIZATION
and END_TABLE_REORGANIZATION
.
Complete the following steps:
DBMS_MVIEW.BEGIN_TABLE_REORGANIZATION
for table employees
.employees
.employees
to employees_old
.employees
using conventional path.DBMS_MVIEW.END_TABLE_REORGANIZATION
for new table employees
.
Caution: When a table is renamed, its associated PL/SQL triggers are also adjusted to the new name of the table. |
Ensure that no transaction is issued against the reorganized table between calling BEGIN_TABLE_REORGANIZATION
and END_TABLE_REORGANIZATION
.
Complete the following steps:
DBMS_MVIEW.BEGIN_TABLE_REORGANIZATION
for table employees
.employees
to a flat file.employees
to employees_old
.employees
with the same shape as employees_old
.DBMS_MVIEW.END_TABLE_REORGANIZATION
for new table employees
.
Caution: When a table is renamed, its associated PL/SQL triggers are also adjusted to the new name of the table. |
Ensure that no transaction is issued against the reorganized table between calling BEGIN_TABLE_REORGANIZATION
and END_TABLE_REORGANIZATION
.
You can delete a materialized view log regardless of its master or any existing materialized views. For example, you might decide to drop a materialized view log if one of the following conditions is true:
Here, a master can be a master table or a master materialized view. To delete a materialized view log, execute the DROP
MATERIALIZED
VIEW
LOG
statement in SQL*Plus. For example, the following statement deletes the materialized view log for a table named customers
in the sales
schema:
DROP MATERIALIZED VIEW LOG ON hr.employees;
Only the owner of the master or a user with the DROP
ANY
TABLE
system privilege can drop a materialized view log.
Expanding established replication environments can cause network traffic when you add a new materialized view site to your replication environment. This is caused by propagating the entire contents of the table or materialized view through the network to the new replicated site.
To minimize such network traffic, you can expand your replication environment by using the offline instantiation procedure. Offline instantiation takes advantage of Oracle's Export and Import utilities, which allow you to create an export file and transfer the data to the new site through another storage medium, such as CD-ROM, tape, and so on.
For the same reasons that you might want to perform an offline instantiation of a master site, you may also want to create a new materialized view group at a materialized view site using the offline instantiation process. In some cases, it is even more useful for materialized views considering that the target computer could very well be a laptop using a modem connection.
The following script performs an offline instantiation for a new materialized view group. Meet the following requirements to complete these actions:
Executed As:
Executed At:
Replication Status: Normal
Complete the following steps to perform an offline instantiation of a materialized view site using export/import.
/************************* BEGINNING OF SCRIPT ******************************
Make sure that the appropriate schema and database links have been created before you perform the offline instantiation of your materialized view.
*/ SET ECHO ON SPOOL offline_instant_mv.out PAUSE Press <RETURN> to continue the new materialized view site is set up. /*
*/ CONNECT repadmin/repadmin@orc1.world /*
If materialized view logs do not already exist for the target master tables, then create them at the target master site.
*/ CREATE MATERIALIZED VIEW LOG ON hr.countries; CREATE MATERIALIZED VIEW LOG ON hr.departments; CREATE MATERIALIZED VIEW LOG ON hr.employees; CREATE MATERIALIZED VIEW LOG ON hr.jobs; CREATE MATERIALIZED VIEW LOG ON hr.job_history; CREATE MATERIALIZED VIEW LOG ON hr.locations; CREATE MATERIALIZED VIEW LOG ON hr.regions; /*
Note: If you added any of the conflict resolution routines described in Chapter 6, "Configure Conflict Resolution", then you may have additional columns in your tables. Be certain to include these additional columns in the |
*/ CREATE MATERIALIZED VIEW hr.countries_mv REFRESH FAST WITH PRIMARY KEY FOR UPDATE AS SELECT country_id, country_name, region_id FROM hr.countries; CREATE MATERIALIZED VIEW hr.departments_mv REFRESH FAST WITH PRIMARY KEY FOR UPDATE AS SELECT department_id, department_name, manager_id, location_id FROM hr.departments; CREATE MATERIALIZED VIEW hr.employees_mv REFRESH FAST WITH PRIMARY KEY FOR UPDATE AS SELECT employee_id, first_name, last_name, email, phone_number, hire_date, job_id, salary, commission_pct, manager_id, department_id FROM hr.employees; CREATE MATERIALIZED VIEW hr.jobs_mv REFRESH FAST WITH PRIMARY KEY FOR UPDATE AS SELECT job_id, job_title, min_salary, max_salary FROM hr.jobs; CREATE MATERIALIZED VIEW hr.job_history_mv REFRESH FAST WITH PRIMARY KEY FOR UPDATE AS SELECT employee_id, start_date, end_date, job_id, department_id FROM hr.job_history; CREATE MATERIALIZED VIEW hr.locations_mv REFRESH FAST WITH PRIMARY KEY FOR UPDATE AS SELECT location_id, street_address, postal_code, city, state_province, country_id FROM hr.locations; CREATE MATERIALIZED VIEW hr.regions_mv REFRESH FAST WITH PRIMARY KEY FOR UPDATE AS SELECT region_id, region_name FROM hr.regions; /*
Use the Oracle Export utility to generate the export file that you will transfer to the new materialized view site. The export file will contain the base tables of your temporary materialized views.
Note: The following example is for Oracle8i and higher databases only. Base tables in database versions earlier than Oracle8i are preceded by the |
See Also:
Oracle9i Database Utilities for additional information about exporting |
The following is an example of an export command for the hr
schema.
exp hr/hr@orc1.world TABLES='countries_mv','departments_mv','employees_mv', 'jobs_mv','job_history_mv','locations_mv','regions_mv' */ PAUSE Press <RETURN> to continue when the export is complete. /*
SYSTEM
user.*/ CONNECT system/manager@mview.world /*
Before you perform the offline instantiation of your materialized views, create the schema that will contain the materialized views at the new materialized view site and the database link from the materialized view site to the master site. The materialized views must be in the same schema that contains the master objects at the master site.
*/ CREATE TABLESPACE demo_mview DATAFILE 'demo_mview.dbf' SIZE 10M AUTOEXTEND ON EXTENT MANAGEMENT LOCAL AUTOALLOCATE; CREATE TEMPORARY TABLESPACE temp_mview TEMPFILE 'temp_mview.dbf' SIZE 5M AUTOEXTEND ON; CREATE USER hr IDENTIFIED BY hr; ALTER USER hr DEFAULT TABLESPACE demo_mview QUOTA UNLIMITED ON demo_mview; ALTER USER hr TEMPORARY TABLESPACE temp_mview; GRANT CREATE SESSION, CREATE TABLE, CREATE PROCEDURE, CREATE SEQUENCE, CREATE TRIGGER, CREATE VIEW, CREATE SYNONYM, ALTER SESSION, CREATE MATERIALIZED VIEW, ALTER ANY MATERIALIZED VIEW, CREATE DATABASE LINK, TO hr; CONNECT hr/hr@mview.world CREATE DATABASE LINK orc1.world CONNECT TO hr IDENTIFIED by hr; /*
*/ CONNECT mviewadmin/mviewadmin@mview.world /*
Run the DBMS_REPCAT.CREATE_MVIEW_REPGROUP
procedure at the new materialized view site to create an empty materialized view group to which you will add your materialized views.
*/ BEGIN DBMS_REPCAT.CREATE_MVIEW_REPGROUP ( gname => 'hr_repg', master => 'orc1.world', propagation_mode => 'ASYNCHRONOUS'); END; / /*
The DBMS_OFFLINE_SNAPSHOT.BEGIN_LOAD
procedure creates the necessary support mechanisms for the new materialized views. This step also adds the new materialized views to the materialized view group that you created in the previous step. Be sure to execute the BEGIN_LOAD
procedure for each materialized view that you will be importing.
*/ BEGIN DBMS_OFFLINE_SNAPSHOT.BEGIN_LOAD ( gname => 'hr_repg', sname => 'hr', master_site => 'orc1.world', snapshot_oname => 'countries_mv'); END; / BEGIN DBMS_OFFLINE_SNAPSHOT.BEGIN_LOAD ( gname => 'hr_repg', sname => 'hr', master_site => 'orc1.world', snapshot_oname => 'departments_mv'); END; / BEGIN DBMS_OFFLINE_SNAPSHOT.BEGIN_LOAD ( gname => 'hr_repg', sname => 'hr', master_site => 'orc1.world', snapshot_oname => 'employees_mv'); END; / BEGIN DBMS_OFFLINE_SNAPSHOT.BEGIN_LOAD ( gname => 'hr_repg', sname => 'hr', master_site => 'orc1.world', snapshot_oname => 'jobs_mv'); END; / BEGIN DBMS_OFFLINE_SNAPSHOT.BEGIN_LOAD ( gname => 'hr_repg', sname => 'hr', master_site => 'orc1.world', snapshot_oname => 'job_history_mv'); END; / BEGIN DBMS_OFFLINE_SNAPSHOT.BEGIN_LOAD ( gname => 'hr_repg', sname => 'hr', master_site => 'orc1.world', snapshot_oname => 'locations_mv'); END; / BEGIN DBMS_OFFLINE_SNAPSHOT.BEGIN_LOAD ( gname => 'hr_repg', sname => 'hr', master_site => 'orc1.world', snapshot_oname => 'regions_mv'); END; / /*
Use the Oracle Import utility to import the file that you exported in Step 5. Make sure that you import your data as the same user who exported the data. This user hr
in the following example:
imp hr/hr@mview.world FULL=y IGNORE=y */ PAUSE Press <RETURN> to continue when the import is complete. /*
Execute the DBMS_OFFLINE_SNAPSHOT.END_LOAD
procedure to finish the offline instantiation of the imported materialized views.
*/ BEGIN DBMS_OFFLINE_SNAPSHOT.END_LOAD ( gname => 'hr_repg', sname => 'hr', snapshot_oname => 'countries_mv'); END; / BEGIN DBMS_OFFLINE_SNAPSHOT.END_LOAD ( gname => 'hr_repg', sname => 'hr', snapshot_oname => 'departments_mv'); END; / BEGIN DBMS_OFFLINE_SNAPSHOT.END_LOAD ( gname => 'hr_repg', sname => 'hr', snapshot_oname => 'employees_mv'); END; / BEGIN DBMS_OFFLINE_SNAPSHOT.END_LOAD ( gname => 'hr_repg', sname => 'hr', snapshot_oname => 'jobs_mv'); END; / BEGIN DBMS_OFFLINE_SNAPSHOT.END_LOAD ( gname => 'hr_repg', sname => 'hr', snapshot_oname => 'job_history_mv'); END; / BEGIN DBMS_OFFLINE_SNAPSHOT.END_LOAD ( gname => 'hr_repg', sname => 'hr', snapshot_oname => 'locations_mv'); END; / BEGIN DBMS_OFFLINE_SNAPSHOT.END_LOAD ( gname => 'hr_repg', sname => 'hr', snapshot_oname => 'regions_mv'); END; / /*
*/ CONNECT hr/hr@mview.world /*
In addition to retrieving the latest changes from the master tables, refreshing the materialized views at the new materialized view site registers the offline instantiated materialized views at the target master site.
*/ BEGIN DBMS_MVIEW.REFRESH ('countries_mv'); END; / BEGIN DBMS_MVIEW.REFRESH ('departments_mv'); END; / BEGIN DBMS_MVIEW.REFRESH ('employees_mv'); END; / BEGIN DBMS_MVIEW.REFRESH ('jobs_mv'); END; / BEGIN DBMS_MVIEW.REFRESH ('job_history_mv'); END; / BEGIN DBMS_MVIEW.REFRESH ('locations_mv'); END; / BEGIN DBMS_MVIEW.REFRESH ('regions_mv'); END; / /*
*/ CONNECT repadmin/repadmin@orc1.world /*
*/ DROP MATERIALIZED VIEW hr.countries_mv; DROP MATERIALIZED VIEW hr.departments_mv; DROP MATERIALIZED VIEW hr.employees_mv; DROP MATERIALIZED VIEW hr.jobs_mv; DROP MATERIALIZED VIEW hr.job_history_mv; DROP MATERIALIZED VIEW hr.locations_mv; DROP MATERIALIZED VIEW hr.regions_mv; SET ECHO OFF SPOOL OFF /************************* END OF SCRIPT **********************************/
Specifying a group owner when you define a new materialized view group and its related objects enables you to create multiple materialized view groups based on the same replication group at a single materialized view site. At a materialized view site, specifying group owners enables you to create multiple materialized view groups that are based on the same replication group at a master site or master materialized view site. You accomplish this by creating the materialized view groups under different schemas at the materialized view site.
Complete the following steps to use a group owner.
See Also:
Oracle9i Replication for a complete description of using group owners and the advantages of using multiple data sets |
/************************* BEGINNING OF SCRIPT ******************************
*/ SET ECHO ON SPOOL mv_group_owner.out CONNECT mviewadmin/mviewadmin@mv1.world /*
gowner
) bob
using the CREATE_MVIEW_REPGROUP
procedure.The replication group that you specify in the gname
parameter must match the name of the replication group that you are replicating at the target master site or master materialized view site. The gowner
parameter enables you to specify an additional identifier that lets you create multiple materialized view groups based on the same replication group at the same materialized view site.
In this example, materialized view groups are created for the group owners bob
and jane
, and these two materialized view groups are based on the same replication group.
*/ BEGIN DBMS_REPCAT.CREATE_MVIEW_REPGROUP ( gname => 'hr_repg', master => 'orc1.world', propagation_mode => 'ASYNCHRONOUS', gowner => 'bob'); END; / BEGIN DBMS_REPCAT.CREATE_MVIEW_REPGROUP ( gname => 'hr_repg', master => 'orc1.world', propagation_mode => 'ASYNCHRONOUS', gowner => 'jane'); END; / /*
bob
.The gowner
value used when creating your materialized view objects must match the gowner
value specified when you created the materialized view group in the previous procedures. After creating the materialized view groups, you can create materialized views based on the same master in the hr_repg
materialized view group owned by bob
and jane
.
Whenever you create a materialized view, always specify the schema name of the table owner in the query for the materialized view. In the examples below, hr
is specified as the owner of the table in each query.
*/ CREATE MATERIALIZED VIEW hr.countries_bob REFRESH FAST WITH PRIMARY KEY FOR UPDATE AS SELECT * FROM hr.countries@orc1.world; CREATE MATERIALIZED VIEW hr.departments_bob REFRESH FAST WITH PRIMARY KEY FOR UPDATE AS SELECT * FROM hr.departments@orc1.world; CREATE MATERIALIZED VIEW hr.employees_bob REFRESH FAST WITH PRIMARY KEY FOR UPDATE AS SELECT * FROM hr.employees@orc1.world; CREATE MATERIALIZED VIEW hr.jobs_bob REFRESH FAST WITH PRIMARY KEY FOR UPDATE AS SELECT * FROM hr.jobs@orc1.world; CREATE MATERIALIZED VIEW hr.job_history_bob REFRESH FAST WITH PRIMARY KEY FOR UPDATE AS SELECT * FROM hr.job_history@orc1.world; CREATE MATERIALIZED VIEW hr.locations_bob REFRESH FAST WITH PRIMARY KEY FOR UPDATE AS SELECT * FROM hr.locations@orc1.world; CREATE MATERIALIZED VIEW hr.regions_bob REFRESH FAST WITH PRIMARY KEY FOR UPDATE AS SELECT * FROM hr.regions@orc1.world; /*
jane
.*/ CREATE MATERIALIZED VIEW hr.departments_jane REFRESH FAST WITH PRIMARY KEY FOR UPDATE AS SELECT * FROM hr.departments@orc1.world; CREATE MATERIALIZED VIEW hr.employees_jane REFRESH FAST WITH PRIMARY KEY FOR UPDATE AS SELECT * FROM hr.employees@orc1.world; /*
bob
to the materialized view group.*/ BEGIN DBMS_REPCAT.CREATE_MVIEW_REPOBJECT ( gname => 'hr_repg', sname => 'hr', oname => 'countries_bob', type => 'SNAPSHOT', min_communication => TRUE, gowner => 'bob'); END; / BEGIN DBMS_REPCAT.CREATE_MVIEW_REPOBJECT ( gname => 'hr_repg', sname => 'hr', oname => 'departments_bob', type => 'SNAPSHOT', min_communication => TRUE, gowner => 'bob'); END; / BEGIN DBMS_REPCAT.CREATE_MVIEW_REPOBJECT ( gname => 'hr_repg', sname => 'hr', oname => 'employees_bob', type => 'SNAPSHOT', min_communication => TRUE, gowner => 'bob'); END; / BEGIN DBMS_REPCAT.CREATE_MVIEW_REPOBJECT ( gname => 'hr_repg', sname => 'hr', oname => 'jobs_bob', type => 'SNAPSHOT', min_communication => TRUE, gowner => 'bob'); END; / BEGIN DBMS_REPCAT.CREATE_MVIEW_REPOBJECT ( gname => 'hr_repg', sname => 'hr', oname => 'job_history_bob', type => 'SNAPSHOT', min_communication => TRUE, gowner => 'bob'); END; / BEGIN DBMS_REPCAT.CREATE_MVIEW_REPOBJECT ( gname => 'hr_repg', sname => 'hr', oname => 'locations_bob', type => 'SNAPSHOT', min_communication => TRUE, gowner => 'bob'); END; / BEGIN DBMS_REPCAT.CREATE_MVIEW_REPOBJECT ( gname => 'hr_repg', sname => 'hr', oname => 'regions_bob', type => 'SNAPSHOT', min_communication => TRUE, gowner => 'bob'); END; / /*
jane
to the materialized view group.*/ BEGIN DBMS_REPCAT.CREATE_MVIEW_REPOBJECT ( gname => 'hr_repg', sname => 'hr', oname => 'departments_jane', type => 'SNAPSHOT', min_communication => TRUE, gowner => 'jane'); END; / BEGIN DBMS_REPCAT.CREATE_MVIEW_REPOBJECT ( gname => 'hr_repg', sname => 'hr', oname => 'employees_jane', type => 'SNAPSHOT', min_communication => TRUE, gowner => 'jane'); END; / SET ECHO OFF SPOOL OFF
See Also:
Chapter 5, "Create Materialized View Group" (Step 6) for more information about adding materialized views to a refresh group |
/************************* END OF SCRIPT **********************************/
|
Copyright © 1996, 2002 Oracle Corporation. All Rights Reserved. |
|