Prerequisite: Before proceeding, make certain the SharePlex demonstration objects are installed. See Prework for the demonstration.
In this demonstration, you will configure SharePlex to use generic conflict resolution procedures to resolve a replication conflict. Generic conflict resolution allows you to use one PL/SQL procedure to resolve conflicts for multiple tables.
The following conflict-resolution strategy is demonstrated:
IMPORTANT! Peer-to-peer replication is not compatible with all business applications. When suitable for an environment, it requires careful analysis and execution, including the creation of custom conflict resolution procedures that are typically more complex than those in this demonstration. Do not use this demonstration as the foundation of a production peer-to-peer deployment. For more information about peer-to-peer replication, see the SharePlex Administration Guide.
Install the demonstration objects as described below before you start the demonstrations.
Note: The below pre-work is applicable only for the Oracle peer. For the information on the pre-work of PostgreSQL peer, see Pre-work for the Demonstrations - PostgreSQL.
The p2p.sql and od.sql scripts install the demonstration objects that you will use during these demonstrations. These scripts are stored in the util sub-directory of the SharePlex product directory.
To run the scripts:
The scripts prompt for the following items:
od_employee
Name |
Null? |
Type |
---|---|---|
EMP_NO | NOT NULL | NUMBER |
EMP_FIRST_NAME | VARCHAR2 | |
EMP_LAST_NAME | VARCHAR2 | |
EMP_DOB | DATE | |
EMP_DEPT_NO | NUMBER | |
EMP_TIMESTAMP | DATE |
od_timesheet
Name |
Null? |
Type |
---|---|---|
TS_EMP_NO | NUMBER | |
TS_IN_TIME | DATE | |
TS_OUT_TIME | DATE | |
TS_MOD_TIME | DATE |
od_department
Name |
Null? |
Type |
---|---|---|
DEPT_NO | NOT NULL | NUMBER |
DEPT_NAME | VARCHAR2 | |
DEPT_CODE | VARCHAR2 |
od_salary
Name |
Null? |
Type |
---|---|---|
SALE_EMP_NO | NUMBER | |
SAL_VALUE | NUMBER | |
SAL_CHANGED | DATE |
od_sales_emp_data
Name |
Null? |
Type |
---|---|---|
EMP_NO_KEY | NOT NULL | NUMBER |
EMPLOYEE_NAME | VARCHAR2 (70) | |
SALARY | NUMBER | |
DEPARTMENT | VARCHAR2 (50) |
oxc_table
Name |
Null? |
Type |
---|---|---|
EXC_NO | NOT NULL | NUMBER |
EXC_TYPE | VARCHAR2 (6) | |
EXC_TARGET_TABLE | VARCHAR2 (66) | |
EXC_FIXED | VARCHAR2 (3) | |
EXC_INFO | VARCHAR2 (500) | |
EXC_TIMESTAMP | DATE |
Note: In this demonstration, the demonstration objects are assumed to be in the schema named demo. Substitute the actual schema, if different.
The following steps provide information on how to prepare the demonstration objects for Oracle peer. For information on how to prepare the demonstration objects of PostgreSQL peer, see Prepare the objects.
Perform these steps on Oracle peer:
Shut down SharePlex.
sp_ctrl(peer1)>shutdown
Grant the user who owns the demonstration objects the system privilege to execute the sp_cr package, which was installed in the SharePlex schema when SharePlex was first installed.
SQL>grant execute on sp_cr to user_name
Run the p2p.sql script from the util sub-directory of the SharePlex product directory. This installs the od_employee_gen demonstration conflict resolution routine. You are prompted for the following:
The name of the SharePlex database user.
Perform these steps to configure SharePlex:
Note: In this configuration, Peer 1 is Postgresql database and Peer2 is Oracle database. The name of the conflict_resolution file for Oracle is conflict_resolution.sid, and for PostgreSQL it is conflict_resolution.database.
On each system, open the conflict_resolution file in a text editor. This file is located in the data sub-directory of the SharePlex variable-data directory.
Note: Post checks this file when there is a replication conflict to determine if there is a resolution procedure to call.
On each system, create the following entries in the conflict_resolution file. Separate each column with at least a few spaces or a tab character.
demo.od_employee | IUD | demo.od_employee_gen |
Note: The first component is a table, the second specifies the operation types for which a resolution routine will be called if there is a conflict on that table, and the third is the name of the resolution routine that will be used.
On peer1 (the trusted source), create a configuration file named od_peer1 that replicates the od_employee table to the od_employee table on peer2.
sp_ctrl(peer1)> create config od_peer1
datasource:r.dbname | ||
"demo"."od_employee" ("emp_no", "emp_first_name", "emp_last_name", "emp_dob", "emp_dept_no", "emp_timestamp") | "DEMO"."OD_EMPLOYEE" ("EMP_NO", "EMP_FIRST_NAME", "EMP_LAST_NAME", "EMP_DOB", "EMP_DEPT_NO", "EMP_TIMESTAMP") | peer2@o.sid |
On peer2 (the secondary source), create a configuration file named od.peer2 that replicates the od_employee table to the od_employee table on peer1.
sp_ctrl(peer2)> create config od_peer2
datasource:o.sid | ||
"DEMO"."OD_EMPLOYEE" ("EMP_NO", "EMP_FIRST_NAME", "EMP_LAST_NAME", "EMP_DOB", "EMP_DEPT_NO", "EMP_TIMESTAMP") | "demo"."od_employee" ("emp_no", "emp_first_name", "emp_last_name", "emp_dob", "emp_dept_no", "emp_timestamp") | peer2@r.dbname |
Note: In the above example, column mapping feature is used since both (source and target) tables have different case sensitivity.
Perform these steps to activate and start replication:
On peer1, activate the od_peer1 configuration.
On peer2, activate the od_peer2 configuration.
On each system, confirm that the configuration activated successfully. The name od_peer1 or od_peer2 (depending on the system) should appear under File Name, and the word Active should appear under State.
sp_ctrl(source)>list config
In this demonstration, an INSERT that originates on peer1 will override a conflicting INSERT that is replicated from peer2.
On peer1, insert a row into od_employee.
insert into od_employee values(1, 'John', 'Doe', '1949-04-01', 1, '2022-01-01');
On peer2, insert the same row (same values).
INSERT INTO OD_EMPLOYEE VALUES (1,'John','Doe',to_date ('04/01/1949','MM/DD/RRRR'),1,to_date('01/01/2022','MM/DD/RRRR'));
In this demonstration, whenever there is a conflict for an UPDATE statement, the row with the most current value of the emp_timestamp column gets precedence.
Note: The EMP_TIMESTAMP field, along with the other columns, must be modified to a non-null value in order for timestamp priority to function. The stored procedure won't be able to resolve the conflict if the timestamp column in the UPDATE statement is not being updated or is being modified to a null value. Out-of-sync problems will then be seen.
In this demonstration, if a DELETE statement generates a conflict, it is ignored.
A table named exc_table was installed in the schema that you specified when you installed the demonstration objects. You can view it through PSQL for PostgreSQL and SQLPLUS for Oracle to view information about each conflict. The following is the table description.
Column | Description |
---|---|
EXC_NO | The exception number of the conflict. |
EXC_TYPE | The type of SQL statement, whether INSERT, UPDATE or DELETE. |
EXC_TARGET_TABLE | The table on which the conflict occurred. |
EXC_FIXED |
The results of the conflict resolution routine. YES means that the routine was successful. NO means that the routine failed and the row needs to be manually changed to the correct value. |
EXC_INFO | The cause of the conflict. |
EXC_TIMESTAMP | The time that the conflict occurred on this machine. |
Note: Before proceeding, make certain the SharePlex demonstration objects are installed. See Pre-work for the demonstrations.
In this demonstration, you will use a supplied transformation procedure to have SharePlex replicate data from two separate source tables and apply it to one target table.
Note: In this demonstration, the demonstration objects are assumed to be in the schema named demo. Substitute the actual schema, if different.
Perform the following steps to prepare the objects:
If you ran previous demonstrations, do the following:
On the source and target, run sp_ctrl and issue the following command to shut down sp_cop.
sp_ctrl (source)shutdown
sp_ctrl (target)shutdown
On the source and target, TRUNCATE the od_employee and od_salary tables.
SQL> truncate table demo.od_employee;
SQL> truncate table demo.od_salary;
On the target, grant the user who owns the demonstration objects the system privilege to execute the sp_cr package, which was installed in the SharePlex schema when SharePlex was first installed.
SQL>grant execute on sp_cr touser_name
On the target, log into SQL*Plus as the user who owns the SharePlex demonstration objects, then run the transform.sql script from the util sub-directory of the SharePlex product directory. This installs transformation routines named od_transform_employee_insert and od_transform_employee_update. You are prompted for:
Perform the following steps to configure SharePlex:
On the target, open the transformation.SID file (where SID is the ORACLE_SID of the target database) in a text editor. This file is located in the data sub-directory in the SharePlex variable-data directory.
Note: Post checks this file to determine if there is a transformation procedure that it must call instead of posting the operation to the database.
Create the following entries in the transformation.SID file.
Separate each column with at least a few spaces or a tab character.
demo.od_employee |
I |
demo.od_transform_employee_insert |
demo.od_employee |
U |
demo.od_transform_employee_update |
demo.od_salary |
I |
demo.od_transform_employee_insert |
demo.od_salary |
U |
demo.od_transform_employee_update |
Note: The components of each entry are as follows, in the order they must appear:
|
On the source, create a configuration file named od.transform that replicates the od_salary and od_employee tables.
sp_ctrl(source)>create config od_transform
In the text editor, build your configuration file based on the following template.
datasource:o.r.dbid |
|
|
demo.od_salary |
"DEMO"."OD_SALARY" |
target_system@o.target_SID |
demo.od_employee |
"DEMO"."OD_EMPLOYEE" |
target_system@o.target_SID |
Perform the following steps to activate and start replication:
On the source, activate the configuration.
Confirm that the configuration activated successfully. The name od_transform should appear under File Name, and the word Active should appear under State.
sp_ctrl(source)>list config
On the source, log in as the demo schema owner, then execute the od_add_emps procedure to populate the od_employee and od_salary tables. Use an IN parameter of 10 to create 50 new employees in the od_sales_emp_data table.
dbname# call od_add_emps(10);
Perform the following steps to view the transformed data:
In SQL*Plus, select all rows from od_sales_emp_data.
View the transformed data. You should see the following results:
SharePlex gets its replication instructions from “configurations,” which are user-defined specifications that tell SharePlex what to do. For each group of objects that you want to replicate, you create a configuration file.
Configurations reside on the source system and define:
To create the demonstration configuration:
Create a replication configuration named sample_config by issuing the create config command in sp_ctrl on the source system. This opens the default text editor, which is vi for Linux systems.
Refer to Template 1 below as you construct your configuration.
Template 1: Basic demonstration configuration sample_config
datasource:r.source_DB | ||
"qarun"."basic_c127" | "splex"."basic_c127" | 10.250.14.105@r.sp_ad |
On the first non-commented line of the file, type the following, leaving no space between any of the items.
(Substitute the PostgreSQL database name of the source instance for source_databasename.) This tells SharePlex where to find the table whose data will be replicated. The r. tells Share- Plex that PostgreSQL data is being replicated.
On the next line, enter the owner name (splex) and table name (demo_src) of the source table, separating the two items with a dot (.) but no spaces. Using the owner’s name with a table name ensures that SharePlex replicates the correct table, since different tables in different schemas in a database could have the same name.
In the second column, enter the owner name (splex) and table name (demo_dest) of the target table, separating the two items with a dot (.) but no spaces.
Type a few spaces or a tab to create a third column. Do not press Enter.
In the third column, type the following items with no space between them. This creates the routing map for your configuration, telling SharePlex where to put the replicated data.
Example:
sysB@r.databasename
[OPTIONAL] To view the configuration, issue the view config command in sp_ctrl on the source system:
Activate the configuration in sp_ctrl on the source system. Configuration names are case-sensitive.
To confirm that your configuration is active, type the following sp_ctrl command on the source system to display a list of all configurations. The sample_config configuration should appear under “File Name,” and the word “Active” should appear under “State.”
Tip: If your configuration activation fails, use the view config sample_config command in sp_ctrl to view the file. Compare it to Template 1 and make sure all of the information you entered is correct. For example, check for extra spaces that are not supposed to be there, or for missing components, such as the r. before the database name.
To correct mistakes in the configuration file:
Note: To change an active configuration, you must copy it to a new file first with the copy config command, and then edit and activate the copy.
Note: Before proceeding, make certain the SharePlex demonstration objects are installed.
In this demonstration, you will create and activate a replication configuration, load data to the source table, and then confirm that the data was replicated successfully to the target table. You will also repair a table that is out of synchronization.
Note: In this demonstration, the demonstration objects are assumed to be in the schema named demo. Substitute the actual schema, if different.
Perform these steps on the source system:
Run sp_ctrl .
Issue the following command to create a configuration file named sample_config that replicates the sample_department, sample_salary, sample_timesheet, and sample_employee tables to target tables of the same names on the target system..
sp_ctrl(source)>create config sample_config
In the text editor, build your configuration file based on the following template. Allow no spaces between the characters in a component (source specification, target specification, routing map), and place at least one space between each component.
# sample_config configuration file | ||
datasource:r.source_databasename | ||
"demo"."sample_department" |
"demo"."sample_department" |
target_system@r.target_databasename |
"demo"."sample_salary" | "demo"."sample_salary" |
target_system@r.target_databasename |
"demo"."sample_timesheet" | "demo"."sample_timesheet" | target_system@r.target_databasename |
"demo"."sample_employee" | "demo"."sample_employee" | target_system@r.target_databasename |
where:
In sp_ctrl, verify that the configuration file will activate successfully.
sp_ctrl(source)>verify config sample_config
An example of a config file for PostgreSQL to PostgreSQL replication:
# data2k configuration file | ||
datasource:r.source_databasename | ||
"demo"."data2k" | "demo"."data2k" | target_system@r.target_databasename |
An example of a config file for PostgreSQL to Oracle replication:
# data2k configuration file | ||
datasource:r.source_databasename | ||
"demo"."data2k" | "demo"."data2k" | target_system@o.target_databasename |
Perform these steps on the source system. When you activate a configuration, SharePlex is ready to capture transactional changes that are made to the specified source data.
Activate the configuration.
sp_ctrl(source)>activate config sample_config
Note: Configuration names are case-sensitive.
Confirm that the configuration activated successfully. The name config sample_config should appear under File Name, and the word Active should appear under State.
sp_ctrl(source)>list config
© ALL RIGHTS RESERVED. Nutzungsbedingungen Datenschutz Cookie Preference Center