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: To run the scripts, set Replica Identity to Full for tables that are a part of replication.
The pg_p2p.sql and pg_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:
Note: The scripts prompt for the schema where you want the demonstration objects need to be installed. Additionally, pg_p2p.sql prompts for the name of the system that will be the trusted source of accurate data.
od_employee
Name |
Null? |
Type |
---|---|---|
emp_no | not null | int |
emp_first_name | varchar(20) | |
emp_last_name | varchar(20) | |
emp_dob | date | |
emp_dept_no | int | |
emp_timestamp | date |
Name |
Null? |
Type |
---|---|---|
exc_no | not null | int |
exc_type | varchar (6) | |
exc_target_table | varchar (66) | |
exc_fixed | varchar (3) | |
exc_info | varchar (500) | |
exc_timestamp | date |
exc_source
Name |
Type |
---|---|
pri_system | varchar |
Note: Apart from these tables, other demonstration objects are also created those are not part of this demonstration.
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 both systems (for both databases).
Shut down SharePlex.
sp_ctrl(peer1)>shutdown
Run the pg_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:
Perform these steps to configure SharePlex:
On each system, open the conflict_resolution.database 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.database 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
demo.od_employee | demo.od_employee | peer2@r.database |
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
demo.od_employee | demo.od_employee | peer1@r.database |
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 peer2, insert a row into od_employee.
insert into od_employee values(1, 'John', 'Doe', '1949-04-01', 1, '2022-01-01');
On peer1, insert the same row (same values).
insert into od_employee values(1, 'John', 'Doe', '1949-04-01', 1, '2022-01-01');
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 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. |
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. |
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