Using the DIFFERENCES Procedure
The DIFFERENCES procedure compares two replicas of a table, and determines all rows in the first replica that are not in the second and all rows in the second that are not in the first. The output of this procedure is stored in two user-created tables. The first table stores the values of the missing rows, and the second table is used to indicate which site contains each row.
The RECTIFY procedure uses the information generated by the DIFFERENCES procedure to rectify the two tables. Any rows found in the first table and not in the second are inserted into the second table. Any rows found in the second table and not in the first are deleted from the second table.
To restore equivalency between all copies of a replicated table, complete the following steps:
1. Select one copy of the table to be the “reference” table. This copy will be used to update all other replicas of the table as needed.
2. Determine if it is necessary to check all rows and columns in the table for differences, or only a subset.
For example, it may not be necessary to check rows that have not been updated since the last time that you checked for differences. Although it is not necessary to check all columns, your column list must include all columns that make up the primary key (or that you designated as a substitute identity key) for the table.
3. After determining which columns you will be checking in the table, create two tables to hold the results of the comparison.
You must create one table that can hold the data for the columns being compared. For example, if you decide to compare the employee_id, salary, and department_id columns of the employees table, then your CREATE statement would need to be similar to the following:
CREATE TABLE hr.missing_rows_data (
employee_id NUMBER(6),
salary NUMBER(8,2),
department_id NUMBER(4));
You must also create a table that indicates where the row is found. This table must contain three columns with the datatypes shown in the following example:
CREATE TABLE hr.missing_rows_location (
present VARCHAR2(128),
absent VARCHAR2(128),
r_id ROWID);
4. Suspend replication activity for the replication group containing the tables that you want to compare. Although suspending replication activity for the group is not a requirement, rectifying tables that were not quiesced first can result in inconsistencies in your data.
BEGIN
DBMS_REPCAT.SUSPEND_MASTER_ACTIVITY (
gname => 'hr_repg');
END;
/
5. At the site containing the “reference” table, call the DIFFERENCES procedure in the DBMS_RECTIFIER_DIFF package.
For example, if you wanted to compare the employees tables at the New York and San Francisco sites, then your procedure call would look similar to the following:
BEGIN
DBMS_RECTIFIER_DIFF.DIFFERENCES (
sname1 => 'hr',
oname1 => 'employees',
reference_site => 'ny.world',
sname2 => 'hr',
oname2 => 'employees',
comparison_site => 'sf.world',
where_clause => '',
column_list => 'employee_id,salary,department_id',
missing_rows_sname => 'hr',
missing_rows_oname1 => 'missing_rows_data',
missing_rows_oname2 => 'missing_rows_location',
missing_rows_site => 'ny.world',
max_missing => 500,
commit_rows => 50);
END;
6. Rectify the table at the “comparison” site to be equivalent to the table at the “reference” site by calling the RECTIFY procedure in the as shown in the DBMS_RECTIFIER_DIFF package following example:
BEGIN
DBMS_RECTIFIER_DIFF.RECTIFY (
sname1 => 'hr',
oname1 => 'employees',
reference_site => 'ny.world',
sname2 => 'hr',
oname2 => 'employees',
comparison_site => 'sf.world',
column_list => 'employee_id,salary,department_id',
missing_rows_sname => 'hr',
missing_rows_oname1 => 'missing_rows_data',
missing_rows_oname2 => 'missing_rows_location',
missing_rows_site => 'ny.world',
commit_rows => 50);
END;
/
The RECTIFY procedure temporarily disables replication at the “comparison” site while it performs the necessary insertions and deletions, as you would not want to propagate these changes. RECTIFY first performs all of the necessary DELETE operations and then performs all of the INSERT operations. This ensures that there are no violations of a PRIMARY KEY constraint.
After you have successfully executed the RECTIFY procedure, your missing rows tables should be empty.