15.3 DBMS_REPCAT: Replication Environment AdministrationThe DBMS_REPCAT package performs many advanced replication operations, including some described in other chapters. This section describes only the DBMS_REPCAT programs that you'll use to administer the advanced replication environment. 15.3.1 Getting Started with DBMS_REPCATThe DBMS_REPCAT package is created when the Oracle database is installed. The dbmsrepc.sql script (found in the built-in packages source directory, as described in Chapter 1 ) contains the source code for this package's specification. This script is called by catrep.sql , which must be run to install the advanced replication packages. The script creates the public synonym DBMS_REPCAT. The package procedure DBMS_REPCAT_AUTH.GRANT_SURROGATE_REPCAT grants EXECUTE privileges on the package to the specified grantee. In addition, the package owner (SYS) and users with the EXECUTE ANY PROCEDURE system privilege may execute it. 15.3.1.1 DBMS_REPCAT programsTable 15.3 lists in alphabetical order the DBMS_REPCAT procedures used to maintain an advanced replication environment. In the sections that follow, we divide these programs by category (replication groups, replication objects, replication support, master sites, the "repcatlog" queue, and quiescence); each section includes a table showing the programs available in that category. For example, the section Section 15.3.2, "Replication Groups with DBMS_REPCAT" " describes only the replication group programs.
15.3.1.2 ExceptionsTable 15.4 describes exceptions raised by the DBMS_REPCAT programs described in this chapter.
15.3.2 Replication Groups with DBMS_REPCATOnce you have created administrative accounts for your advanced replication environment and established the appropriate database links among your various sites, you are ready for the next step, which is to create a replication group. Here are the procedures you will use:
The following sections describe these programs in detail. Figure 15.1 shows how replication groups work. Figure 15.1: . Replication groups15.3.2.1 The DBMS_REPCAT.CREATE_MASTER_REPGROUP procedureThe CREATE_MASTER_REPGROUP procedure creates a replication group at the master definition site. Here's the specification: PROCEDURE DBMS_REPCAT.CREATE_MASTER_REPGROUP (gname IN VARCHAR2, group_comment IN VARCHAR2 := '', master_comment IN VARCHAR2 := '', qualifier IN VARCHAR2 := ''); Parameters are summarized in the following table.
15.3.2.1.1 ExceptionsThe CREATE_MASTER_REPGROUP procedure may raise the following exceptions:
15.3.2.1.2 RestrictionsYou must be connected to the replication administrator account (typically REPADMIN) to call CREATE_MASTER_REPGROUP. 15.3.2.1.3 ExampleThe following call creates a replication group named SPROCKET: BEGIN DBMS_REPCAT.CREATE_MASTER_REPGROUP( gname=> 'SPROCKET', - group_comment => 'Replication group SPROCKET created on '||sysdate|| ' by ' ||user, - master_comment => 'Master Definition Site created on '||sysdate|| ' by ' ||user); END; This call creates a replication group with no objects. The site from which you make the call is the master definition site for the group. For an additional example, see the repgroup.sql file on the companion disk. That example queries the DBA_REPGROUP data dictionary view and lists all replication groups in the database. 15.3.2.2 The DBMS_REPCAT.DROP_MASTER_REPGROUP procedureThe DROP_MASTER_REPGROUP procedure drops one or more replication groups at the master definition site. Here's the specification: PROCEDURE DBMS_REPCAT.DROP_MASTER_REPGROUP (gname IN VARCHAR2, drop_contents IN BOOLEAN := FALSE, all_sites IN BOOLEAN := FALSE); Parameters are summarized in the following table.
15.3.2.2.1 ExceptionsThe DROP_MASTER_REPGROUP procedure raises the following exceptions:
15.3.2.2.2 RestrictionsNote the following restrictions on calling DROP_MASTER_REPGROUP:
15.3.2.2.3 ExampleThis call, from the master definition site, drops a replication group from all sites where it exists: BEGIN DBMS_REPCAT.DROP_MASTER_REPGROUP( gname => 'SPROCKET', all_sites => TRUE ); END; The next call drops a replication group and all of its objects from the calling site, assumed to be a master site (not a master definition site): BEGIN DBMS_REPCAT.DROP_MASTER_REPGROUP( gname => 'SPROCKET', drop_contents => TRUE ); END; If you want to drop a replication group from all master sites, along with the replicated objects, you can do the following: BEGIN DBMS_REPCAT.DROP_MASTER_REPGROUP( gname => 'SPROCKET', all_sites => TRUE drop_contents => TRUE ); END; 15.3.2.3 The DBMS_REPCAT. COMMENT_ON_REPGROUP procedureThis procedure adds a new schema comment field to the DBA_REPCAT data dictionary view, or changes an existing one. The specifications differ for Oracle7 and Oracle8 as follows. Here is the Oracle7 specification: PROCEDURE DMBS_REPCAT.COMMENT_ON_REPGROUP (gname IN VARCHAR2 := '', comment IN VARCHAR2, sname IN VARCHAR2 := ''); Here is the Oracle8 specification: PROCEDURE DMBS_REPCAT.COMMENT_ON_REPGROUP (gname IN VARCHAR2, comment IN VARCHAR2); Parameters are summarized in the following table.
15.3.2.3.1 ExceptionsThe COMMENT_ON_REPROUP procedure may raise the following exceptions:
15.3.2.3.2 RestrictionsThe COMMENT_ON_REPGROUP procedure must be called from the master definition site. 15.3.2.3.3 ExampleThis call adds or replaces the comment in DBA_REPGROUP for the SPROCKET replication group: BEGIN DBMS_REPCAT.COMMENT_ON_REPGROUP( gname 'SPROCKET', comment => 'Comment added on '||sysdate|| ' by '||user); END; COMMENT_ON_REPGROUP queues an RPC to update the field at all other master sites. 15.3.3 Replicated Objects with DBMS_REPCATAfter you have created your replication group(s) (with or without comments), you are ready to add, alter, and remove member objects. Here are the procedures you need:
The following sections describe these programs in detail. 15.3.3.1 The DBMS_REPCAT.CREATE_MASTER_REPOBJECT procedureThe CREATE_MASTER_REPOBJECT procedure creates a replicated object. Its specification follows: PROCEDURE DBMS_REPCAT.CREATE_MASTER_REPOBJECT( sname IN VARCHAR2, oname IN VARCHAR2, type IN VARCHAR2, use_existing_object IN BOOLEAN := TRUE, ddl_text IN VARCHAR2 := NULL, comment IN VARCHAR2 := '', retry IN BOOLEAN := FALSE, copy_rows IN BOOLEAN := TRUE, gname IN VARCHAR2 := ''); Parameters are summarized in the following table.
15.3.3.1.1 ExceptionsThe CREATE_MASTER_REPOBJECT procedure may raise the following exceptions:
15.3.3.1.2 RestrictionsNote the following restrictions on calling CREATE_MASTER_REPOBJECT:
15.3.3.1.3 ExampleThis section contains a series of examples showing how to create replication objects. 15.3.3.1.4 Adding an existing table to a replication groupThis call adds table SPROCKET. PRODUCTS to the replication group SPROCKET: BEGIN DBMS_REPCAT.CREATE_MASTER_REPOBJECT(sname => 'SPROCKET', oname => 'PRODUCTS', type => 'TABLE', gname => 'SPROCKET'); END; Since we have not specified ddl_text in this example, the table must already exist. 15.3.3.1.5 Creating an object at the master definition siteIn this next example, we use CREATE_MASTER_REPOBJECT to create an object at the master definition site and add it to the replication group: BEGIN DBMS_REPCAT.CREATE_MASTER_REPOBJECT( sname => 'SPROCKET', oname => 'STATES', type => 'TABLE' ddl_text => 'CREATE TABLE sprocket.states(state_id VARCHAR2(2), state_name VARCHAR2(20))', gname => 'SPROCKET'); END; Notice that the CREATE TABLE statement in this example specifies the owner of the table. Typically, the replication administrator account uses DBMS_REPCAT, not the owner of the replicated schema. When this is the case, you must be sure to specify the schema in which to create objects. One of the privileges granted through DBMS_REPCAT_ADMIN.GRANT_ADMIN_ANY_REPGROUP is CREATE ANY TABLE. In all likelihood, you will not create objects with the CREATE_MASTER_REPOBJECT procedure very often, because doing so is rather clumsy for all but the most simple objects. But it's there if you want it. Setting the retry and use_existing_object parameters to TRUE in this third example creates the table PRODUCTS at all master sites where it does not already exist; setting copy_rows to TRUE copies the data from the master definition site to the master sites. BEGIN DBMS_REPCAT.CREATE_MASTER_REPOBJECT( sname => 'SPROCKET', oname => 'PRODUCTS', type => 'TABLE', use_existing_object => TRUE, retry => TRUE, copy_rows => TRUE, gname => 'SPROCKET'); END; If tables exist at master sites, but do not have the same definition as at the master definition site, Oracle returns an error.
15.3.3.1.6 Replicating a packageIn this final example, we replicate a package. To replicate a package, you must make two calls to CREATE_MASTER_REPOBJECT, one for the package, and one for the package body. BEGIN DBMS_REPCAT.CREATE_MASTER_REPOBJECT sname => 'SPROCKET', oname => 'PRODUCTMAINT', type => 'PACKAGE', use_existing_object => TRUE, comment => 'Added on '||sysdate, retry => FALSE, gname => 'SPROCKET'); DBMS_REPCAT.CREATE_MASTER_REPOBJECT sname => 'SPROCKET', oname => 'PRODUCTMAINT', type => 'PACKAGE BODY', use_existing_object => TRUE, comment => 'Added on '||sysdate, retry => FALSE, gname => 'SPROCKET'); END; For an additional example, see the repobjs.sql file on the companion disk. The example queries the DBA_REPOBJECT data dictionary view and lists all replicated objects in the database. 15.3.3.2 The DBMS_REPCAT. SET_COLUMNS procedureWhen you replicate a table, Oracle must be able to uniquely identify each record in the table so that it can propagate changes to the correct row or rows. By default, the advanced replication facility uses the primary key to identify rows. However, if your table does not have a primary key, or if you wish to use a different criteria to uniquely identify records, you can use SET_COLUMNS to designate a pseudo-primary key. Here's the specification for the package: PROCEDURE DBMS_REPCAT.SET_COLUMNS (sname IN VARCHAR2, oname IN VARCHAR2, column_list IN VARCHAR2 | column_table IN dbms_utility.name_array); Parameters are summarized in the following table.
15.3.3.2.1 ExceptionsDBMS_REPCAT.SET_COLUMNS may raise the following exceptions:
15.3.3.2.2 RestrictionsNote the following restrictions on calling DBMS_REPCAT.SET_COLUMNS.
15.3.3.2.3 ExampleThe following call designates columns COLOR, MODEL, and YEAR as the pseudo-primary key columns in table SPROCKET.PRODUCTS: BEGIN DBMS_REPCAT.SET_COLUMNS(sname => 'SPROCKET', oname => 'PRODUCTS', column_list => 'COLOR,MODEL,YEAR'); END; 15.3.3.3 The DBMS_REPCAT.DROP_MASTER_REPOBJECT procedureThe DROP_MASTER_REPOBJECT procedure drops a replicated object at the master site. The specification follows: PROCEDURE DBMS_REPOBJECT.DROP_MASTER_REPOBJECT (sname IN VARCHAR2, oname IN VARCHAR2, type IN VARCHAR2, drop_objects IN BOOLEAN := FALSE); Parameters are summarized in the following table.
15.3.3.3.1 ExceptionsThe DROP_MASTER_REPOBJECT procedure may raise the following exceptions:
15.3.3.3.2 RestrictionsNote the following restrictions on calling DROP_MASTER_REPOBJECT:
15.3.3.3.3 ExamplesThe following call removes table SPROCKET.PRODUCTS from the SPROCKET replication group, but preserves the table: BEGIN DBMS_REPCAT.DROP_MASTER_REPOBJECT( sname => 'SPROCKET', oname => 'PRODUCTS', type => 'TABLE'); END; Dropping a table from a replication group automatically drops all replication triggers associated with the table and removes it from the replication data dictionary views. The DROP_MASTER_REPOBJECT procedure can remove the object from the replication group, and also drop the object from the schema by setting the drop_objects parameter to TRUE, as shown in this example: BEGIN DBMS_REPCAT.DROP_MASTER_REPOBJECT( sname => 'SPROCKET', oname => 'PRODUCTS', type => 'TABLE', drop_objects => TRUE); END; 15.3.3.4 The DBMS_REPCAT. EXECUTE_DDL procedureDBMS_REPCAT.CREATE_MASTER_REPOBJECT and DBMS_REPCAT.DROP_MASTER_REPOBJECT do not support every type of object. For example, you cannot use these procedures to drop and create constraints. Enter DBMS_REPCAT's EXECUTE_DDL procedure. The EXECUTE_DDL procedure allows you to perform DDL at multiple sites. The specification follows: PROCEDURE DBMS_REPCAT.EXECUTE_DDL (gname IN VARCHAR2 := '', {master_list IN VARCHAR2 := NULL, | master_table IN dbms_utility.dblink_array,} ddl_text IN VARCHAR2, sname IN VARCHAR2 := ''); Parameters are summarized in the following table.
15.3.3.4.1 ExceptionsThe EXECUTE_DDL procedure may raise the following exceptions:
15.3.3.4.2 RestrictionsNote the following restrictions on calling EXECUTE_DDL:
15.3.3.4.3 ExampleThis example creates an index on the SPROCKET.STATES table at sites D7CA.BIGWHEEL.COM and D7NY.BIGWHEEL.COM. Note that as in the example of CREATE_MASTER_REPOBJECT, we must specify the schema in which to create the index. DECLARE vMasters VARCHAR2(30); BEGIN vMasters := 'D7CA.BIGWHEEL.COM,D7NY.BIGWHEEL.COM'; DBMS_REPCAT.EXECUTE_DDL( gname => 'SPROCKET', master_list => vMasters, ddl_text =>'CREATE INDEX sprocket.i_state_id ON sprocket.tstates(state_id)', sname =>'SPROCKET'); END; 15.3.3.5 The DBMS_REPCAT. ALTER_MASTER_REPOBJECT procedureJust as you can propagate DDL to create objects with the EXECUTE_DDL procedure, you can also propagate DDL to alter objects with DBMS_REPCAT.ALTER_MASTER_REPOBJECT. Unlike EXECUTE_DDL, ALTER_MASTER_REPOBJECT does not allow you to specify a list of master sites; the call affects all masters. In other words, Oracle does not support site-specific customizations of replicated objects. The specification follows: PROCEDURE DBMS_REPCAT.ALTER_MASTER_REPOBJECT (sname IN VARCHAR2, oname IN VARCHAR2, type IN VARCHAR2, ddl_text IN VARCHAR2, comment IN VARCHAR2 := '', retry IN BOOLEAN := FALSE); Parameters are summarized in the following table.
15.3.3.5.1 ExceptionsThe ALTER_MASTER_REPOBJECT procedure may raise the following exceptions:
15.3.3.5.2 RestrictionsNote the following restrictions on calling ALTER_MASTER_REPOBJECT: 15.3.3.5.3 ExampleIf you set the retry parameter to TRUE, ALTER_MASTER_REPOBJECT applies the DDL only at sites where the object has a status of INVALID in the DBA_OBJECTS data dictionary view. BEGIN DBMS_REPCAT.ALTER_MASTER_REPOBJECT( sname => 'SPROCKET', oname => 'PRODUCTMAINT', type => 'PACKAGE BODY' ddl_text => 'ALTER PACKAGE SPROCKET.PRODUCTMAINT COMPILE BODY', comment => 'Recompiled on '||sysdate|| ' by '||user, retry => TRUE ); END; Notice that we specify the schema for the object that we are altering. As with DBMS_REPCAT.EXECUTE_DDL, the ALTER_MASTER_REPOBJECT procedure operates on objects in the caller's schema by default, and the caller is generally the replication administrator account, not the schema account. This example alters the width of the state_id column in table SPROCKET.STATES at all sites: BEGIN DBMS_REPCAT.ALTER_MASTER_REPOBJECT( sname => 'SPROCKET', oname => 'PRODUCTMAINT', type => 'PACKAGE BODY' ddl_text => 'ALTER TABLE SPROCKET.STATES MODIFY (STATE_ID NUMBER(10))' , comment => 'state_id widened on '||sysdate|| ' by '||user); END; 15.3.3.6 The DBMS_REPCAT. COMMENT_ON_REPOBJECT procedureAs you have seen in the previous examples, you can associate comments with a replicated object when you create or alter it by passing a VARCHAR2 string to the comment parameter. You can see these comments in the object_comment field of DBA_REPOBJECTS. You can also create comments without creating or altering the object with DBMS_REPCAT's COMMENT_ON_REPOBJECT procedure. The specification follows: PROCEDURE DBMS_REPCAT.COMMENT_ON_REPOBJECT (sname IN VARCHAR2, oname IN VARCHAR2, type IN VARCHAR2, comment IN VARCHAR2); Parameters are summarized in the following table.
15.3.3.6.1 ExceptionsThe COMMENT_ON_REPOBJECT procedure may raise the following exceptions:
15.3.3.6.2 RestrictionsThe COMMENT_ON_REPOBJECT procedure must be called from the master definition site. 15.3.3.6.3 ExampleThe following call updates the comment for replicated table SPROCKET.PRICES: BEGIN DBMS_REPCAT.COMMENT_ON_REPOBJECT( sname => 'SPROCKET', - oname => 'PRICES', - type => 'TABLE', - comment => 'Headquarters updates this table once a month.'); END; 15.3.4 Replication Support with DBMS_REPCATThe next step in the creation of a replicated environment is to generate replication support for your replicated tables, packages, and package bodies. In the case of replicated tables, this step creates a BEFORE ROW trigger, called tablename$RT, and three packages:
This code propagates DML to remote sites, and applies DML on behalf of remote sites. We'll examine this code in the examples of these procedures:
15.3.4.1 The DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT procedureThe GENERATE_REPLICATION_SUPPORT procedure generates support for replicated tables, packages, and package bodies. The specifications differ for Oracle7 and Oracle8 as follows. Here is the Oracle7 specification: PROCEDURE DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT (sname IN VARCHAR2, oname IN VARCHAR2, type IN VARCHAR2, package_prefix IN VARCHAR2 := NULL, procedure_prefix IN VARCHAR2 := NULL, distributed IN BOOLEAN := TRUE, gen_objs_owner IN VARCHAR2 := NULL, gen_rep2_trigger IN BOOLEAN := FALSE); Here is the Oracle8 specification: PROCEDURE DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT (sname IN VARCHAR2, oname IN VARCHAR2, type IN VARCHAR2, package_prefix IN VARCHAR2 := NULL, procedure_prefix IN VARCHAR2 := NULL, distributed IN BOOLEAN := TRUE, gen_objs_owner IN VARCHAR2 := NULL, min_communication IN BOOLEAN := TRUE); Parameters are summarized in the following table.
15.3.4.1.1 ExceptionsThe GENERATE_REPLICATION_SUPPORT procedure may raise the following exceptions:
15.3.4.1.2 RestrictionsNote the following restrictions on calling GENERATE_REPLICATION_SUPPORT:
15.3.4.1.3 ExampleSuppose that we have a table SPROCKET.REON defined as follows:
Assuming that we have already added this table to the SPROCKET replication group, here is how we would generate replication support for it: BEGIN EXECUTE dbms_repcat.generate_replication_support( - sname => 'SPROCKET', - oname => 'REGION', - type => 'TABLE', - distributed => TRUE, - gen_objs_owner=> 'SPROCKET', - gen_rep2_trigger=> FALSE); END; This call creates a trigger and three packages, as described in the following table. Oracle immediately creates these objects at the master definition site, as well as the participating master sites.
In the next sections, we examine what Oracle creates for us when we generate replication support for this table. 15.3.4.1.4 The replication support triggerThe following example shows the text of the REGION$RT trigger that the GENERATE_REPLICATION_SUPPORT call generates: declare flag char; begin if "REGION$TP".active then if inserting then flag := 'I'; elsif updating then flag := 'U'; elsif deleting then flag := 'D'; end if; "REGION$TP".replicate( :old."REGION_ID",:new."REGION_ID", :old."REGION_NAME",:new."REGION_NAME", flag); end if; end; As you can see, this BEFORE ROW trigger simply sets a flag to indicate the type of DML being performed: "I" for inserts, "U" for updates, and "D" for deletes. It then passes this flag, along with the new and old values of each field, to the REGIONS$TP.REPLICATE procedure. 15.3.4.1.5 The replication support packagesThe replication package REGION$TP invokes DBMS_SNAPSHOT.I_AM_A_REFRESH (see the description of this procedure in Chapter 14 ) to determine if the DML that fired the REGION$RT trigger originated locally, or if it is DML that another site has propagated. If the DML originated locally, then the REGION$TP builds a deferred call -- one of the REGION$RP procedures (REP_UPDATE, REP_INSERT, or REP_DELETE), as appropriate. Oracle queues this deferred call to all master sites. Here is the Oracle-generated code: package body "REGION$TP" as I_am_a_snapshot CHAR; is_snapshot BOOLEAN; function active return boolean is begin return (not((is_snapshot and dbms_snapshot.I_am_a_refresh) or not dbms_reputil.replication_is_on)); end active; procedure replicate( "REGION_ID1_o" IN NUMBER, "REGION_ID1_n" IN NUMBER, "REGION_NAME2_o" IN VARCHAR2, "REGION_NAME2_n" IN VARCHAR2, flag IN CHAR) is begin if flag = 'U' then dbms_defer.call('SPROCKET','REGION$RP','REP_UPDATE',6,'SPROCKET'); dbms_defer.number_arg("REGION_ID1_o"); dbms_defer.number_arg("REGION_ID1_n"); dbms_defer.varchar2_arg("REGION_NAME2_o"); dbms_defer.varchar2_arg("REGION_NAME2_n"); elsif flag = 'I' then dbms_defer.call('SPROCKET','REGION$RP','REP_INSERT',4,'SPROCKET'); dbms_defer.number_arg("REGION_ID1_n"); dbms_defer.varchar2_arg("REGION_NAME2_n"); elsif flag = 'D' then dbms_defer.call('SPROCKET','REGION$RP','REP_DELETE',4,'SPROCKET'); dbms_defer.number_arg("REGION_ID1_o"); dbms_defer.varchar2_arg("REGION_NAME2_o"); end if; dbms_defer.varchar2_arg(dbms_reputil.global_name); dbms_defer.char_arg(I_am_a_snapshot); end replicate; begin select decode(master, 'N', 'Y', 'N') into I_am_a_snapshot from all_repcat where gname = 'SPROCKET'; is_snapshot := (I_am_a_snapshot = 'Y'); end "REGION$TP"; Notice that Oracle passes the old and new values of each column in the table to the REGION$RP procedure. Oracle uses these values to confirm that the version of the row at the originating site is the same as the version of the row at the destination sites. If the old column values at the originating site do not match the current column values at the destination site, then Oracle detects a conflict and invokes the appropriate conflict resolution method. You can see this logic in the package body of REGION$RP: package body "REGION$RP" as procedure rep_delete( "REGION_ID1_o" IN NUMBER, "REGION_NAME2_o" IN VARCHAR2, site_name IN VARCHAR2, propagation_flag IN CHAR) is begin if propagation_flag = 'N' then dbms_reputil.replication_off; end if; dbms_reputil.rep_begin; dbms_reputil.global_name := site_name; delete from "REGION" where ("REGION_ID1_o" = "REGION_ID" and "REGION_NAME2_o" = "REGION_NAME"); if sql%rowcount = 0 then raise no_data_found; elsif sql%rowcount > 1 then raise too_many_rows; end if; dbms_reputil.rep_end; exception when no_data_found then begin if not "REGION$RR".delete_conflict_handler( "REGION_ID1_o", "REGION_NAME2_o", site_name, propagation_flag) then dbms_reputil.rep_end; raise; end if; dbms_reputil.rep_end; exception when others then dbms_reputil.rep_end; raise; end; when others then dbms_reputil.rep_end; raise; end rep_delete; procedure rep_insert( "REGION_ID1_n" IN NUMBER, "REGION_NAME2_n" IN VARCHAR2, site_name IN VARCHAR2, propagation_flag IN CHAR) is begin if propagation_flag = 'N' then dbms_reputil.replication_off; end if; dbms_reputil.rep_begin; dbms_reputil.global_name := site_name; insert into "REGION" ( "REGION_ID", "REGION_NAME") values ( "REGION_ID1_n", "REGION_NAME2_n"); dbms_reputil.rep_end; exception when dup_val_on_index then begin if not "REGION$RR".unique_conflict_insert_handler( "REGION_ID1_n", "REGION_NAME2_n", site_name, propagation_flag, SQLERRM) then dbms_reputil.rep_end; raise; end if; dbms_reputil.rep_end; exception when others then dbms_reputil.rep_end; raise; end; when others then dbms_reputil.rep_end; raise; end rep_insert; procedure rep_update( "REGION_ID1_o" IN NUMBER, "REGION_ID1_n" IN NUMBER, "REGION_NAME2_o" IN VARCHAR2, "REGION_NAME2_n" IN VARCHAR2, site_name IN VARCHAR2, propagation_flag IN CHAR) is begin if propagation_flag = 'N' then dbms_reputil.replication_off; end if; dbms_reputil.rep_begin; dbms_reputil.global_name := site_name; update "REGION" set "REGION_ID" = "REGION_ID1_n", "REGION_NAME" = decode("REGION_NAME2_o", "REGION_NAME2_n", "REGION_NAME", "REGION_NAME2_n") where (((1 = 1 and "REGION_NAME2_o" = "REGION_NAME2_n")) or (1 = 1 and "REGION_NAME2_o" = "REGION_NAME")) and "REGION_ID1_o" = "REGION_ID"; if sql%rowcount = 0 then raise no_data_found; elsif sql%rowcount > 1 then raise too_many_rows; end if; dbms_reputil.rep_end; exception when no_data_found then begin if not "REGION$RR".update_conflict_handler( "REGION_ID1_o", "REGION_ID1_n", "REGION_NAME2_o", "REGION_NAME2_n", site_name, propagation_flag) then dbms_reputil.rep_end; raise; end if; dbms_reputil.rep_end; exception when others then dbms_reputil.rep_end; raise; end; when dup_val_on_index then begin if not "REGION$RR".unique_conflict_update_handler( "REGION_ID1_o", "REGION_ID1_n", "REGION_NAME2_o", "REGION_NAME2_n", site_name, propagation_flag, SQLERRM) then dbms_reputil.rep_end; raise; end if; dbms_reputil.rep_end; exception when others then dbms_reputil.rep_end; raise; end; when others then dbms_reputil.rep_end; raise; end rep_update; end "REGION$RP"; As you can see, Oracle invokes REGION$RR, the conflict resolution package: package body "REGION$RR" as function unique_conflict_insert_handler( "REGION_ID1_n" IN NUMBER, "REGION_NAME2_n" IN VARCHAR2, site_name IN VARCHAR2, propagation_flag IN CHAR, errmsg IN VARCHAR2) return boolean is begin return FALSE; end unique_conflict_insert_handler; function delete_conflict_handler( "REGION_ID1_o" IN NUMBER, "REGION_NAME2_o" IN VARCHAR2, site_name IN VARCHAR2, propagation_flag IN CHAR) return boolean is begin return FALSE; end delete_conflict_handler; function update_conflict_handler( "REGION_ID1_o" IN NUMBER, "REGION_ID1_n" IN NUMBER, "REGION_NAME2_o" IN VARCHAR2, "REGION_NAME2_n" IN VARCHAR2, site_name IN VARCHAR2, propagation_flag IN CHAR) return boolean is begin return FALSE; end update_conflict_handler; function unique_conflict_update_handler( "REGION_ID1_o" IN NUMBER, "REGION_ID1_n" IN NUMBER, "REGION_NAME2_o" IN VARCHAR2, "REGION_NAME2_n" IN VARCHAR2, site_name IN VARCHAR2, propagation_flag IN CHAR, errmsg IN VARCHAR2) return boolean is begin return FALSE; end unique_conflict_update_handler; end "REGION$RR"; This is the default conflict handling package that GENERATE_REPLICATION_SUPPORT creates. Since no conflict resolution methods are defined for REGION, the unique_conflict_insert_handler, delete_conflict_handler, update_conflict_handler, and unique_conflict_update_handler programs all return FALSE, indicating that they cannot resolve the conflict. Chapter 17 contains details about how to define conflict resolution handlers. 15.3.4.1.6 Generating replication support for packages and proceduresAs well as tables, you can also replicate procedures and packages. When you call a replicated procedure, Oracle builds a deferred RPC that it propagates to all master sites. This deferred RPC invokes the same procedure with the same arguments as the originating call. Oracle recommends procedural replication for situations that call for massive updates to tables (i.e., updates affecting tens of thousands of rows). Procedural replication duplicates the procedure call only, which is more efficient and network-friendly than row-level replication. (Row-level replication sends the old and new column values for every field of every row.) Just as we made two calls to CREATE_MASTER_REPOBJECT to create a replicated package, we must also make two calls to GENERATE_REPLICATION_SUPPORT: BEGIN DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT( sname => 'SPROCKET', oname => 'PRODUCTMAINT', type => 'PACKAGE', distributed => TRUE, gen_objs_owner => 'SPROCKET', gen_rep2_trigger=> FALSE); DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT( sname => 'SPROCKET', oname => 'PRODUCTMAINT', type => 'PACKAGE BODY', distributed => TRUE, gen_objs_owner => 'SPROCKET', gen_rep2_trigger=> FALSE); END; These two calls create a "wrapper" package and package body, named DEFER_PRODUCTMAINT. This package uses DBMS_DEFER.CALL (described in Chapter 17 ) to build RPCs to PRODUCTMAINT. To replicate a call to procedure ADDPRODUCT, we would call DEFER_PRODUCTMAINT.ADDPRODUCT. package "DEFER_PRODUCTMAINT" as I_am_a_snapshot CHAR; procedure "ADDPRODUCT"( "PRODUCT_TYPE_IN" IN number, "CATALOG_ID_IN" IN varchar2, "DESCRIPTION_IN" IN varchar2, "REV_LEVEL_IN" IN varchar2, "PRODUCTION_DATE_IN" IN date, "PRODUCT_STATUS_IN" IN varchar2, call_local IN char := 'N', call_remote IN char := 'Y'); end "DEFER_PRODUCTMAINT"; package body "DEFER_PRODUCTMAINT" as procedure "ADDPRODUCT"( "PRODUCT_TYPE_IN" IN NUMBER, "CATALOG_ID_IN" IN VARCHAR2, "DESCRIPTION_IN" IN VARCHAR2, "REV_LEVEL_IN" IN VARCHAR2, "PRODUCTION_DATE_IN" IN DATE, "PRODUCT_STATUS_IN" IN VARCHAR2, call_local IN char := 'N', call_remote IN char := 'Y') is begin select decode(master, 'N', 'Y', 'N') into I_am_a_snapshot from all_repcat where gname = 'SPROCKET'; if call_local = 'Y' then "SPROCKET"."PRODUCTMAINT"."ADDPRODUCT"( "PRODUCT_TYPE_IN", "CATALOG_ID_IN", "DESCRIPTION_IN", "REV_LEVEL_IN", "PRODUCTION_DATE_IN", "PRODUCT_STATUS_IN"); end if; if call_remote = 'Y' then 8, 'SPROCKET'); dbms_defer.number_arg("PRODUCT_TYPE_IN"); dbms_defer.varchar2_arg("CATALOG_ID_IN"); dbms_defer.varchar2_arg("DESCRIPTION_IN"); dbms_defer.varchar2_arg("REV_LEVEL_IN"); dbms_defer.date_arg("PRODUCTION_DATE_IN"); dbms_defer.varchar2_arg("PRODUCT_STATUS_IN"); dbms_defer.char_arg('Y'); dbms_defer.char_arg(I_am_a_snapshot); end if; end "ADDPRODUCT"; begin select decode(master, 'N', 'Y', 'N') into I_am_a_snapshot from all_repcat where gname = 'SPROCKET'; end "DEFER_PRODUCTMAINT"; 15.3.4.2 The DBMS_REPCAT. GENERATE_REPLICATION_PACKAGE procedureIn some situations, you may wish to generate only replication support triggers or replication support packages. For example, if you use DBMS_REPCAT's ALTER_MASTER_PROPAGATION procedure to change from synchronous to asynchronous replication, you will have to recreate replication triggers. The GENERATE_REPLICATION_PACKAGE and GENERATE_REPLICATION_TRIGGERS procedures provide this functionality. The GENERATE_REPLICATION_PACKAGE procedure allows you to generate replication support packages. The specification follows: PROCEDURE DBMS_REPCAT.GENERATE_REPLICATION_PACKAGE (sname IN VARCHAR2, oname IN VARCHAR2); Parameters are summarized in the following table.
15.3.4.2.1 ExceptionsThe GENERATE_REPLICATON_PACKAGE procedure may raise the following exceptions:
15.3.4.2.2 RestrictionsNote the following restrictions on calling GENERATE_REPLICATION_PACKAGE:
15.3.4.2.3 ExampleThe following call generates the replication support packages for table SPROCKET.PRODUCTS in all master sites: BEGIN DBMS_REPCAT.GENERATE_REPLICATION_PACKAGE( sname => 'SPROCKET', oname => 'PRODUCTS'); END; 15.3.4.3 The DBMS_REPCAT.GENERATE_REPLICATION_TRIGGER procedureThe GENERATE_REPLICATION_TRIGGER procedure allows you to generate replication support triggers. The specifications differ for Oracle7 and Oracle8 as follows. Here is the Oracle7 specification: PROCEDURE DBMS_REPCAT.GENERATE_REPLICATION_TRIGGER (sname IN VARCHAR2, oname IN VARCHAR2, gen_objs_owner IN VARCHAR2 := NULL, gen_rep2_trigger IN BOOLEAN := FALSE); PROCEDURE DBMS_REPCAT.GENERATE_REPLICATION_TRIGGER (gname IN VARCHAR2, {master_list IN VARCHAR2 := NULL | master_table IN dbms_utility.dblink_array}, gen_objs_owner IN VARCHAR2 := NULL); Here is the Oracle8 specification: PROCEDURE DBMS_REPCAT.GENERATE_REPLICATION_TRIGGER (sname IN VARCHAR2, oname IN VARCHAR2, gen_objs_owner IN VARCHAR2 := NULL, min_communication IN BOOLEAN := TRUE); PROCEDURE DBMS_REPCAT.GENERATE_REPLICATION_TRIGGER (gname IN VARCHAR2, gen_objs_owner IN VARCHAR2 := NULL, min_communication IN BOOLEAN := NULL); Parameters are summarized in the following table.
15.3.4.3.1 ExceptionsThe GENERATE_REPLICATION_TRIGGER procedure may raise the following exceptions:
15.3.4.3.2 RestrictionsNote the following restrictions on calling GENERATE_REPLICATION_TRIGGER:
15.3.4.3.3 ExamplesThe simplest invocation of the GENERATE_REPLICATION_TRIGGER procedure does the most work; this call generates replication triggers for all replicated tables at all master sites: BEGIN DBMS_REPCAT.GENERATE_REPLICATION_TRIGGER(gname=> 'SPROCKET' ); END; This next example generates replication triggers for the replicated table SPROCKET.PRODUCTS at all master sites: BEGIN DBMS_REPCAT.GENERATE_REPLICATION_TRIGGER( gname => 'SPROCKET', oname => 'PRODUCTS' ); END; The following call generates replication triggers for all replicated tables in the SPROCKET replication group at the master sites D7HI.BIGWHEEL.COM and D7WA.BIGWHEEL.COM: BEGIN DBMS_REPCAT.GENERATE_REPLICATION_TRIGGER( gname => 'SPROCKET', master_list=> 'D7HI.BIGWHEEL.COM, D7WA.BIGWHEEL.COM' ); END; The following call regenerates the replication support for all objects in replication group SPROCKET at all master sites: EXECUTE DBMS_REPCAT.GENERATE_REPLICATION_TRIGGER(gname=> 'SPROCKET' ) For an additional example, see the invalids.sql file on the companion disk. The example lists all objects in the database with a status of INVALID and generates the appropriate SQL statements to attempt to validate them. 15.3.5 Adding and Removing Master Sites with DBMS_REPCATNow you have generated replication support for those objects you intend to replicate, and you are ready to add master sites to your environment. In advanced replication parlance, a master site is a database instance where replicated objects and their replication support triggers and packages exist. Master sites are sometimes called peers , because every master site has the same objects and identical (or nearly identical) data. Any master site can perform DML on a replicated table, and Oracle propagates the DML to all other master sites. There is no single authoritative site, not even the master definition site. The distinction between the master definition site and the other masters is that the master definition site is the only site that can perform DDL on replicated objects, and the only one that can suspend or resume replication activity. Here are the DBMS_REPCAT programs associated with creating and maintaining master sites in your replicated environment:
We describe these programs in the following sections. 15.3.5.1 The DBMS_REPCAT.ADD_MASTER_DATABASE procedureThe ADD_MASTER_DATABASE procedure adds a master site. The specifications differ for Oracle7 and Oracle8 as follows. (Note that the sname parameter no longer exists in Oracle8.) Here is the Oracle7 specification: PROCEDURE DBMS_REPCAT.ADD_MASTER_DATABASE (gname IN VARCHAR2 := '', master IN VARCHAR2, use_existing_objects IN BOOLEAN := TRUE, copy_rows IN BOOLEAN := TRUE, comment IN VARCHAR2 := '', propagation_mode IN VARCHAR2 := 'ASYNCHRONOUS', sname N VARCHAR2 := ''); Here is the Oracle8 specification: PROCEDURE DBMS_REPCAT.ADD_MASTER_DATABASE (gname IN VARCHAR2 := '', master IN VARCHAR2, use_existing_objects IN BOOLEAN := TRUE, copy_rows IN BOOLEAN := TRUE, comment IN VARCHAR2 := '', propagation_mode IN VARCHAR2 := 'ASYNCHRONOUS'); Parameters are summarized in the following table.
15.3.5.1.1 ExceptionsThe ADD_MASTER_DATABASE procedure may raise the following exceptions:
15.3.5.1.2 RestrictionsNote the following restrictions on calling ADD_MASTER_DATABASE:
15.3.5.1.3 ExampleThe ADD_MASTER_DATABASE procedure is relatively simple to use. For example, this call adds site D7NY.BIGWHEEL.COM to the SPROCKET replication group and instantiates all objects there: BEGIN DBMS_REPCAT.ADD_MASTER_DATABASE( gname => 'SPROCKET', master => 'D7NY.BIGWHEEL.COM', use_existing_objects=> 'FALSE', copy_rows => 'TRUE', propagation_mode=> 'ASYNCHRONOUS'); END; For additional examples, see the repsites.sql and links.sql files on the companion disk. The repsites.sql example queries all replication sites, sorted by replication group, and queries the DBA_REPSITES data dictionary view. The links.sql example lists all database links in the database (but not the passwords for those that were created using a CONNECT clause).
15.3.5.2 The DBMS_REPCAT.REMOVE_MASTER_DATABASES procedureThe REMOVE_MASTER_DATABASES procedure complements the ADD_MASTER_DATABASE procedure by removing master sites. The master sites being removed do not need to be accessible, but all other masters do. As with the ADD_MASTER_DATABASE procedure, the Oracle7 and Oracle8 specifications differ; Oracle8 does not have the sname parameter. Here is the Oracle7 specification: PROCEDURE DBMS_REPCAT.REMOVE_MASTER_DATABASES (gname IN VARCHAR2 := '', master_list IN VARCHAR2, sname IN VARCHAR2 := ''); Here is the Oracle8 specification: PROCEDURE DBMS_REPCAT.REMOVE_MASTER_DATABASES (gname IN VARCHAR2 := '', master_list IN VARCHAR2);, Parameters are summarized in the following table.
15.3.5.2.1 ExceptionsThe REMOVE_MASTER_DATABASES procedure may raise the following exceptions:
15.3.5.2.2 RestrictionsThe REMOVE_MASTER_DATABASES procedure must be run from the master definition site. 15.3.5.2.3 ExampleTo remove site D7NY.BIGWHEEL.COM from the SPROCKET replication group and inform all other master sites, specify the following: BEGIN DBMS_REPCAT.REMOVE_MASTER_DATABASES( name => 'SPROCKET', master_list => 'D7NY.BIGWHEEL.COM'); END;
15.3.5.3 The DBMS_REPCAT.COMMENT_ON_REPSITES procedureThe COMMENT_ON_REPSITES procedure allows you to add or change a comment associated with a master site specified in the DBA_REPSITES data dictionary view. Here's the specification: PROCEDURE DBMS_REPCAT.COMMENT_ON_REPSITES (gname IN VARCHAR2, master IN VARCHAR, comment IN VARCHAR2); Parameters are summarized in the following table.
15.3.5.3.1 ExceptionsThe COMMENT_ON_REPSITES procedure may raise the following exceptions:
15.3.5.3.2 RestrictionsYou must call the COMMENT_ON_REPSITES procedure from the master definition site. 15.3.5.3.3 ExampleThe following call updates the comment for master site D7NY. BIGWHEEL.COM: BEGIN DBMS_REPCAT.COMMENT_ON_REPSITES( gname => 'SPROCKET', master => 'D7NY.BIGWHEEL.COM', comment => 'Comment added on '||sysdate|| ' by ' ||user) END; 15.3.5.4 The DBMS_REPCAT. RELOCATE_MASTERDEF procedureIf your master definition site becomes unusable, or if you simply want another site to serve that role, you can configure a different master site as the master definition site with the RELOCATE_MASTERDEF procedure described in this section. Follow these guidelines:
The specifications differ for Oracle7 and Oracle8 as follows. Here is the Oracle7 specification: PROCEDURE DBMS_REPCAT.RELOCATE_MASTERDEF (gname IN VARCHAR2 := '', old_masterdef IN VARCHAR2, new_masterdef IN VARCHAR2, notify_masters IN BOOLEAN := TRUE, include_old_masterdef IN BOOLEAN := TRUE, sname IN VARCHAR2 := '') Here is the Oracle8 specification: PROCEDURE DBMS_REPCAT.RELOCATE_MASTERDEF (gname IN VARCHAR2, old_masterdef IN VARCHAR2, new_masterdef IN VARCHAR2, notify_masters IN BOOLEAN := TRUE, include_old_masterdef IN BOOLEAN := TRUE); Parameters are summarized in the following table.
15.3.5.4.1 ExceptionsThe RELOCATE_MASTERDEF procedure may raise the following exceptions:
15.3.5.4.2 RestrictionsYou must call RELOCATE_MASTERDEF from a master or master definition site. 15.3.5.4.3 ExampleThe following call relocates the master definition site for replication group SPROCKET from D7CA.BIGWHEEL.COM to D7NY.BIGWHEEL.COM, and informs all masters, as well as the master definition site, of the change: BEGIN DBMS_REPCAT.RELOCATE_MASTERDEF( gname => 'SPROCKET', old_master_def => 'D7CA.BIGWHEEL.COM', new_master_def => 'D7NY.BIGWHEEL.COM', notify_masters => TRUE, include_old_masterdef=> TRUE); END; Suppose that the master definition site D7CA.BIGWHEEL.COM becomes permanently unavailable. We can convert another site, such as D7NY.BIGWHEEL.COM, into the master definition site without having to communicate with D7CA.BIGWHEEL.COM. We set the include_old_masterdef parameter to FALSE. BEGIN DBMS_REPCAT.RELOCATE_MASTERDEF( gname => 'SPROCKET', old_master_def => 'D7CA.BIGWHEEL.COM', new_master_def => 'D7NY.BIGWHEEL.COM', notify_masters => TRUE, include_old_masterdef=> FALSE); END; 15.3.6 Maintaining the Repcatlog Queue with DBMS_REPCATThe programs in this category maintain the " repcatlog" queue. You'll use these procedures:
The following sections describe these programs. 15.3.6.1 The DBMS_REPCAT .DO_DEFERRED_REPCAT_ADMIN procedureWhenever you create or alter replicated objects -- for example, with the GENERATE_REPLICATION_SUPPORT or ALTER_MASTER_REPOBJECT procedure -- Oracle queues the changes in the "repcatlog" queue; the entries in this queue correspond to entries in the DBA_REPCATLOG data dictionary view. All DDL changes must originate at the master definition site, but the repcatlog queue exists at every master site. The DO_DEFERRED_REPCAT_ADMIN procedure processes entries in the repcatlog queue at all master sites. You may have noticed this job in the job queue, scheduled to run once every ten minutes. Oracle creates this scheduled job the first time you execute one of the packages that performs DDL. The specifications differ for Oracle7 and Oracle8 as follows. Here is the Oracle7 specification: PROCEDURE DBMS_REPCAT.DO_DEFERRED_REPCAT_ADMIN (gname IN VARCHAR2 := '', all_sites IN BOOLEAN := FALSE, sname IN VARCHAR2 := ''); Here is the Oracle8 specification: PROCEDURE DBMS_REPCAT.DO_DEFERRED_REPCAT_ADMIN (gname IN VARCHAR2, all_sites IN BOOLEAN := FALSE); As with all of the other DBMS_REPCAT procedures, the Oracle8 version does not have the sname parameter. Parameters are summarized in the following table.
15.3.6.1.1 ExceptionsThe DO_DEFERRED_REPCAT_ADMIN procedure may raise the following exceptions:
15.3.6.1.2 RestrictionsThe DO_DEFERRED_REPCAT_ADMIN procedure performs only the procedures that have been queued by the invoking user. Note that the job queue is used to perform the queued procedures automatically. 15.3.6.1.3 Example.If you want to run DO_DEFERRED_REPCAT_ADMIN manually, either because you do not have DBMS_JOB background processes running, or because you want to push the repcatlog queue immediately, you can do so. Here is an example: BEGIN DBMS_REPCAT.DO_DEFFERED_REPCAT_ADMIN ( gname => 'SPROCKET', all_sites => TRUE); END; For an additional example, see the catlog.sql file on the companion disk. The example lists entries in the repcatlog (DBA_REPCATLOG) with the time of submission in hours, minutes, and seconds. 15.3.6.2 The DBMS_REPCAT.WAIT_MASTER_LOG procedureYou can use the WAIT_MASTER_LOG procedure to ascertain whether the changes in the repcatlog queue have reached the master sites. This procedure has an OUT parameter, true_count, which the procedure populates with the number of outstanding tasks. The specifications differ for Oracle7 and Oracle8 as follows. Here is the Oracle7 specification: PROCEDURE DBMS_REPCAT.WAIT_MASTER_LOG (gname IN VARCHAR2 := '', record_count IN NATURAL, timeout IN NATURAL, true_count OUT NATURAL, sname IN VARCHAR2 := ''); Here is the Oracle8 specification: PROCEDURE DBMS_REPCAT.WAIT_MASTER_LOG (gname IN VARCHAR2, record_count IN NATURAL, timeout IN NATURAL, true_count OUT NATURAL); Parameters are summarized in the following table.
There are no restrictions on calling WAIT_MASTER_LOG. 15.3.6.2.1 ExceptionsThe WAIT_MASTER_LOG procedure may raise the following exception:
15.3.6.2.2 ExampleThe following call returns after 60 seconds, or after five entries have been entered into the DBA_REPCATLOG data dictionary view at the current master for replication group SPROCKET. The number of records (corresponding to incomplete tasks) is stored in the variable vRecCount. VARIABLE vRecCount NATURAL BEGIN DBMS_REPCAT.WAIT_MASTER_LOG(gname=> 'SPROCKET', record_count => 5, timeout => 60, true_count => vRecCount); END;
15.3.6.3 The DBMS_REPCAT. PURGE_MASTER_LOG procedureThe DBA_REPCATLOG data dictionary view retains entries on DDL propagations that have failed; these entries are not removed when you resolve the problem that caused the failure. You may notice entries such as these: 1 SELECT source, status, request, to_char(timestamp, 'HH24:MI:SS') timestamp 2 FROM dba_repcatlog 3* ORDER BY id system@d7ca SQL> / Source Status Request Time -------------------- ------- ------------------------ --------------- D7CA.BIGWHEEL.COM ERROR CREATE_MASTER_REPOBJECT 23:13:07 D7CA.BIGWHEEL.COM ERROR CREATE_MASTER_REPOBJECT 23:13:07 D7CA.BIGWHEEL.COM ERROR CREATE_MASTER_REPOBJECT 23:25:20 D7CA.BIGWHEEL.COM ERROR CREATE_MASTER_REPOBJECT 23:25:20 D7CA.BIGWHEEL.COM ERROR CREATE_MASTER_REPOBJECT 23:26:53 D7CA.BIGWHEEL.COM ERROR CREATE_MASTER_REPOBJECT 23:26:53 D7CA.BIGWHEEL.COM ERROR DROP_MASTER_REPOBJECT 14:03:27 D7CA.BIGWHEEL.COM ERROR DROP_MASTER_REPOBJECT 14:03:27 8 rows selected. You must use the PURGE_MASTER_LOG procedure to remove these entries from DBA_REPCATLOG. You can specify records to delete by id, originating master, replication group, and schema. If a parameter is NULL, it is treated as a wildcard. Specifications differ for Oracle7 and Oracle8 as follows. Here is the Oracle7 specification: PROCEDURE DBMS_REPCAT.PURGE_MASTER_LOG (id IN NATURAL, source IN VARCHAR2, gname IN VARCHAR2 := '', sname IN VARCHAR2 := ''); Here is the Oracle8 specification: PROCEDURE DBMS_REPCAT.PURGE_MASTER_LOG (id IN NATURAL, source IN VARCHAR2, gname IN VARCHAR2); Parameters are summarized in the following table.
15.3.6.3.1 ExceptionsThe PURGE_MASTER_LOG procedure may raise the following exception:
15.3.6.3.2 RestrictionsThe calling site must be a master site. 15.3.6.3.3 ExampleThe following call removes all entries associated with replication group SPROCKET from the DBA_REPCATLOG data dictionary view: BEGIN DBMS_REPCAT.PURGE_MASTER_LOG(gname=> 'SPROCKET' ); END; For an additional example, see the caterr.sql file on the companion disk. The example lists entries in the repcatlog (DBA_REPCATLOG) containing errors, and displays the error message associated with each error.
15.3.7 Quiescence with DBMS_REPCATYou may have noticed that many of the DBMS_REPCAT packages require you to quiesce the environment before using them. Quiescence, as it is called, accomplishes two things:
In other words, quiescence ensures that all sites are up to date, and forces the replicated environment to stand still.
You will use the following programs to quiesce your environment and start it up again:
15.3.7.1 The DBMS_REPCAT.SUSPEND_MASTER_ACTIVITY procedureThe SUSPEND_MASTER_ACTIVITY procedure quiesces an environment. The specifications differ for Oracle7 and Oracle8 as follows. Here is the Oracle7 specification: PROCEDURE DBS_REPCAT.SUSPEND_MASTER_ACTIVITY (gname IN VARCHAR2 := '', execute_as_user IN BOOLEAN := FALSE, sname IN VARCHAR2 := ''); Here is the Oracle8 specification: PROCEDURE DBMS_REPCAT.SUSPEND_MASTER_ACTIVITY (gname IN VARCHAR2, override IN BOOLEAN := FALSE); Parameters are summarized in the following table.
15.3.7.1.1 ExceptionsThe SUSPEND_MASTER_ACTIVITY procedure may raise the following exceptions:
15.3.7.1.2 RestrictionsNote the following restrictions on calling SUSPEND_MASTER_ACTIVITY:
15.3.7.1.3 ExampleThe following call suspends replication activity for the SPROCKET replication group: BEGIN DBMS_REPCAT.SUSPEND_MASTER_ACTIVITY( gname => 'SPROCKET' ); END;
15.3.7.2 The DBMS_REPCAT.RESUME_MASTER_ACTIVITY procedureThe RESUME_MASTER_ACTIVITY procedure starts up an environment that has been quiesced. The specifications differ for Oracle7 and Oracle8 as follows. Here is the Oracle7 specification: PROCEDURE DBMS_REPCAT.RESUME_MASTER_ACTIVITY (gname IN VARCHAR2 := '', override IN BOOLEAN := FALSE, sname IN VARCHAR2 := ''); Here is the Oracle8 specification: PROCEDURE DBMS_REPCAT.RESUME_MASTER_ACTIVITY (gname IN VARCHAR2, override IN BOOLEAN := FALSE); Parameters are summarized in the following table.
15.3.7.2.1 ExceptionsThe RESUME_MASTER_ACTIVITY procedure may raise the following exceptions:
15.3.7.2.2 RestrictionsNote the following restrictions on calling RESUME_MASTER_ACTIVITY:
15.3.7.2.3 ExampleThe following example resumes replication activity for a replication group: BEGIN DBMS_REPCAT.RESUME_MASTER_ACTIVITY( gname => 'SPROCKET' ); END; 15.3.8 Miscellaneous DBMS_REPCAT ProceduresThis section describes several DBMS_REPCAT programs that don't fall into any of the earlier categories.
15.3.8.1 The DBMS_REPCAT. REPCAT_IMPORT_CHECK procedureFrom time to time, you may need to rebuild a master site from an export dump file as either a recovery or maintenance procedure. Because object id numbers (as seen in SYS.OBJ$.OBJ# and DBA_OBJECTS.OBJECT_ID) change during these rebuilds, Oracle supplies a procedure (REPCAT_IMPORT_CHECK) that you must run immediately after an import of any master site to synchronize the new id numbers with the data stored in the table SYSTEM.REPCAT$_REPOBJECT. You must run the REPCAT_IMPORT_CHECK procedure immediately after you import any master site. The specifications differ for Oracle7 and Oracle8 as follows. Here is the Oracle7 specification: PROCEDURE DBMS_REPCAT.REPCAT_IMPORT_CHECK (gname IN VARCHAR2 := '', master IN BOOLEAN, sname IN VRCHAR2 := ''); Here is the Oracle8 specification: PROCEDURE DBMS_REPCAT.REPCAT_IMPORT_CHECK (gnamee in VARCHAR2 := '', master IN BOOLEAN); Parameters are summarized in the following table.
15.3.8.1.1 ExceptionsThe REPCAT_IMPORT_CHECK procedure may raise the following exceptions:
15.3.8.1.2 ExampleThe following call revalidates all replicated objects and supporting objects for the SPROCKET replication group. Issue this call after an import: BEGIN DBMS_REPCAT.REPCAT_IMPORT_CHECJ( sname => 'SPROCKET', master => TRUE ); END;
15.3.8.2 The DBMS_REPCAT. ALTER_MASTER_PROPAGATION procedureThe advanced replication option supports two modes of propagation: synchronous and asynchronous. The following table summarizes the pros and cons of each mode.
As a practical matter, you should opt for synchronous replication only if your sites are tightly linked to each other in your network, both physically and logically. Examples of acceptably tight links include two machines sharing a hub, or two machines connected by a crossover cable. Regardless of the propagation method you choose, Oracle lets you change a replication group's propagation mode later with the ALTER_MASTER_PROPAGATION procedure. Call this procedure to change the propagation mode of a replication group (from synchronous to asynchronous, or vice versa). Here's the specification: PROCEDURE DBMS_REPCAT.ALTER_MASTER_PROPAGATION (gname IN VARCHAR2, master IN VARCHAR2, {dblink_table IN dbms_utility.dblink_array | dblink_list IN VARCHAR2}, propagation_modee IN VARCHAR2 := 'ASYNCHRONOUS', comment IN VARCHAR2 := ''); Parameters are summarized in the following table.
15.3.8.2.1 ExceptionsThe ALTER_MASTER_PROPAGATION procedure may raise the following exceptions:
15.3.8.2.2 RestrictionsNote the following restrictions on calling ALTER_MASTER_PROPAGATION:
15.3.8.2.3 ExampleThe following call changes the propagation mode between D7CA.BIGWHEEL.COM and D7NY.BIGWHEEL.COM to SYNCHRONOUS: BEGIN DBMS_REPCAT.ALTER_MASTER_PROPAGATION( gname => 'SPROCKET', master => 'D7CA.BIGWHEEL.COM', dblink_list => 'D7NY.BIGWHEEL.COM', use_existing_objects=> 'FALSE', propagation_mode=> 'SYNCHRONOUS'); END;
15.3.8.3 The DBMS_REPCAT. SEND_AND_COMPARE_OLD_VALUES procedure (Oracle8 only)The default behavior of advanced replication is to send the old and new values of every column to participating master sites whenever you update a row in a replicated table. At the destination sites, Oracle uses this information to ensure that the version of the row that you updated matches the version of the row currently at the destination. However, if you know that certain columns in a table will never change, you can avoid sending the data in these columns when you propagate updates to participating master sites. Using the SEND_AND_COMPARE_OLD_VALUES procedure (available only in Oracle8) in this way, you'll reduce propagation overhead. Here is the specification: PROCEDURE DBMS_REPCAT.SEND_AND_COMPARE_OLD_VALUES (sname IN VARCHAR2 oname IN VARCHAR2, {column_list IN VARCHAR2 | column_table IN dbms_repcat.varchar2s}, operation IN VARCHAR2 := 'UPDATE', send IN BOOLEAN := TRUE); Parameters are summarized in the following table.
15.3.8.3.1 ExceptionsThe SEND_AND_COMPARE_OLD_VALUES procedure may raise the following exceptions:
15.3.8.3.2 RestrictionsNote the following restrictions on calling SEND_AND_COMPARE_OLD_VALUES:
Copyright (c) 2000 O'Reilly & Associates. All rights reserved. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|