Oracle® TimesTen In-Memory Database Replication Guide 11g Release 2 (11.2.2) Part Number E21635-04 |
|
|
PDF · Mobi · ePub |
This chapter describes how to define replication schemes that are not active standby pairs. For information about defining active standby pair replication schemes, see Chapter 3, "Defining an Active Standby Pair Replication Scheme". If you want to replicate a database that has cache groups, see Chapter 5, "Administering an Active Standby Pair with Cache Groups".
To reduce the amount of bandwidth required for replication, see "Compressing replicated traffic".
To replicate tables with columns in a different order or with a different number of partitions, see "Replicating tables with different definitions".
This chapter includes these topics:
These are the primary objectives of any replication scheme:
Provide one or more backup databases to ensure that the data is always available to applications
Provide a means to recover failed databases from their backup databases
Distribute workloads efficiently to provide applications with the quickest possible access to the data
Enable software upgrades and maintenance without disrupting service to users
In a highly available system, a subscriber database must be able to survive failures that may affect the master. At a minimum, the master and subscriber need to be on separate hosts. For some applications, you may want to place the subscriber in an environment that has a separate power supply. In certain cases, you may need to place a subscriber at an entirely separate site.
In this chapter, we consider the replication schemes described in "Types of replication schemes":
Unidirectional
Bidirectional split workload
Bidirectional distributed workload
Propagation
In addition, consider whether you want to replicate a whole database or selected elements of the database. Also consider the number of subscribers in the replication scheme. Unidirectional and propagation replication schemes allow you to choose the number of subscribers.
The rest of this section includes these topics:
For more information about using replication to facilitate online upgrades, see "Performing an online upgrade with replication" and "Performing an online upgrade with active standby pair replication" in Oracle TimesTen In-Memory Database Installation Guide.
As you plan a replication scheme, consider every failover and recovery scenario. For example, subscriber failures generally have no impact on the applications connected to the master databases. Their recovery does not disrupt user service. If a failure occurs on a master database, you should have a means to redirect the application load to a subscriber and continue service with no or minimal interruption. This process is typically handled by a cluster manager or custom software designed to detect failures, redirect users or applications from the failed database to one of its subscribers, and manage recovery of the failed database. See Chapter 11, "Managing Database Failover and Recovery".
When planning failover strategies, consider which subscribers will take on the role of the master and for which users or applications. Also consider recovery factors. For example, a failed master must be able to recover its database from its most up-to-date subscriber, and any subscriber must be able to recover from its master. A bidirectional scheme that replicates the entire database can take advantage of automatic restoration of a failed master. See "Automatic catch-up of a failed master database".
Consider the failure scenario for the unidirectionally replicated database shown in Figure 9-1. In the case of a master failure, the application cannot access the database until it is recovered from the subscriber. You cannot switch the application connection or user load to the subscriber unless you use an ALTER REPLICATION
statement to redefine the subscriber database as the master. See "Replacing a master database".
Figure 9-1 Recovering a master in a unidirectional scheme
Figure 9-2 shows a bidirectional distributed workload scheme in which the entire database is replicated. Failover in this type of replication scheme involves shifting the users of the application on the failed database to the application on the surviving database. Upon recovery, the workload can be redistributed to the application on the recovered database.
Figure 9-2 Recovering a master in a distributed workload scheme
Similarly, the users in a split workload scheme must be shifted from the failed database to the surviving database. Because replication in a split workload scheme is not at the database level, you must use an ALTER REPLICATION
statement to set a new master database. See "Replacing a master database". Upon recovery, the users can be moved back to the recovered master database.
Propagation replication schemes also require the use of the ALTER REPLICATION
statement to set a new master or a new propagator if the master or propagator fails. Higher availability is achieved if two propagators are defined in the replication scheme. See Figure 1-11 for an example of a propagation replication scheme with two propagators.
When you design a replication scheme, weigh operational efficiencies against the complexities of failover and recovery. Factors that may complicate failover and recovery include the network topology that connects a master with its subscribers and the complexity of the replication scheme. For example, it is easier to recover a master that has been fully replicated to a single subscriber than recover a master that has selected elements replicated to different subscribers.
You can configure replication to work asynchronously (the default), "semi-synchronously" with return receipt service, or fully synchronously with return twosafe service. Selecting a return service provides greater confidence that your data is consistent on the master and subscriber databases. Your decision to use default asynchronous replication or to configure return receipt or return twosafe mode depends on the degree of confidence you require and the performance tradeoff you are willing to make in exchange.
Table 9-1 summarizes the performance and recover tradeoffs of asynchronous replication, return receipt service and return twosafe service.
Table 9-1 Performance and recovery tradeoffs
Type of behavior | Asynchronous replication (default) | Return receipt | Return twosafe |
---|---|---|---|
Commit sequence |
Each transaction is committed first on the master database. |
Each transaction is committed first on the master database |
Each transaction is committed first on the subscriber database. |
Performance on master |
Shortest response time and best throughput because there is no log wait between transactions or before the commit on the master. |
Longer response time and less throughput than asynchronous. The application is blocked for the duration of the network round-trip after commit. Replicated transactions are more serialized than with asynchronous replication, which results in less throughput. |
Longest response time and least throughput. The application is blocked for the duration of the network round-trip and remote commit on the subscriber before the commit on the master. Transactions are fully serialized, which results in the least throughput. |
Effect of a runtime error |
Because the transaction is first committed on the master database, errors that occur when committing on a subscriber require the subscriber to be either manually corrected or destroyed and then recovered from the master database. |
Because the transaction is first committed on the master database, errors that occur when committing on a subscriber require the subscriber to be either manually corrected or destroyed and then recovered from the master database. |
Because the transaction is first committed on the subscriber database, errors that occur when committing on the master require the master to be either manually corrected or destroyed and then recovered from the subscriber database. |
Failover after failure of master |
If the master fails and the subscriber takes over, the subscriber may be behind the master and must reprocess data feeds and be able to remove duplicates. |
If the master fails and the subscriber takes over, the subscriber may be behind the master and must reprocess data feeds and be able to remove duplicates. |
If the master fails and the subscriber takes over, the subscriber is at least up to date with the master. It is also possible for the subscriber to be ahead of the master if the master fails before committing a transaction it had replicated to the subscriber. |
In addition to the performance and recovery tradeoffs between the two return services, you should also consider the following:
Return receipt can be used in more configurations, whereas return twosafe can only be used in a bidirectional configuration or an active standby pair.
Return twosafe allows you to specify a "local action" to be taken on the master database in the event of a timeout or other error encountered when replicating a transaction to the subscriber database.
A transaction is classified as return receipt or return twosafe when the application updates a table that is configured for either return receipt or return twosafe. Once a transaction is classified as either return receipt or return twosafe, it remains so, even if the replication scheme is altered before the transaction completes.
For more information about return services, see "Using a return service".
Consider configuring the databases to distribute application workloads and make the best use of a limited number of servers. For example, it may be efficient and economical to configure the databases in a bidirectional distributed workload replication scheme so that each serves as both master and subscriber, rather than as separate master and subscriber databases. However, a distributed workload scheme works best with applications that primarily read from the databases. Implementing a distributed workload scheme for applications that frequently write to the same elements in a database may diminish performance and require that you implement a solution to prevent or manage update conflicts, as described in Chapter 14, "Resolving Replication Conflicts".
After you have designed your replication scheme, use the CREATE REPLICATION
SQL statement to apply the scheme to your databases. You must have the ADMIN
privilege to use the CREATE REPLICATION
statement.
Table 9-2 shows the components of a replication scheme and identifies the clauses associated with the topics in this chapter. The complete syntax for the CREATE REPLICATION
statement is provided in Oracle TimesTen In-Memory Database SQL Reference.
Table 9-2 Components of a replication scheme
Component | See... |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Note:
Naming errors in yourCREATE REPLICATION
statement are often hard to troubleshoot, so take the time to check and double-check the element, database, and host names for mistakes.The replication scheme used by a database persists across system reboots. Modify a replication scheme by using the ALTER REPLICATION
statement. See Chapter 13, "Altering Replication".
The replication scheme and the replicated objects must be owned by the same user on every database in a replication scheme. To ensure that there is a common owner across all databases, you should explicitly specify the user and replication scheme in the CREATE REPLICATION
statement.
For example, create a replication scheme named repscheme
owned by user repl
. The first line of the CREATE REPLICATION
statement for repscheme
is:
CREATE REPLICATION rep1.repscheme
These are the roles of the databases in a replication scheme:
Master: Applications update the master database. The master sends the updates to the propagator or to the subscribers directly.
Propagator: The propagator database receives updates from the master database and sends them to subscriber databases.
Subscriber: Subscribers receive updates from the propagator or the master.
Before you define the replication scheme, you need to define the data source names (DSNs) for the databases in the replication scheme. On UNIX platforms, create an odbc.ini
file. On Windows, use the ODBC Administrator to name the databases and set connection attributes. See "Step 1: Create the DSNs for the master and the subscriber" for an example.
Each database "name" specified in a replication scheme must match the prefix of the database file name without the path specified for the DataStore
data store attribute in the DSN definition. Use the same name for both the DataStore
and Data Source Name
data store attributes in each DSN definition. If the database path is directory
/
subdirectory
/foo.ds0
, then foo
is the database name that you should use. For example, this entry in an odbc.ini
file shows a Data Source Name
(DSN) of masterds
, while the DataStore
value shows the path for masterds
:
[masterds] DataStore=/tmp/masterds DatabaseCharacterSet=AL32UTF8 ConnectionCharacterSet=AL32UTF8
The name and owner of replicated tables participating in the replication scheme must be identical on the master and subscriber databases. The column definitions of replicated tables participating in the replication scheme must be identical on the master and subscriber databases unless you specify a TABLE DEFINITION CHECKING
value of RELAXED
in the CREATE REPLICATION
statement. If you specify RELAXED
, then the tables must have the same key definition, number of columns and column data types. See "Replicating tables with different definitions".
Replicated tables must have one of the following:
A primary key
A unique index over non-nullable columns
Replication uses the primary key or unique index to uniquely identify each row in the replicated table. Replication always selects the first usable index that turns up in a sequential check of the table's index array. If there is no primary key, replication selects the first unique index without NULL
columns it encounters. The selected index on the replicated table in the master database must also exist on its counterpart table in the subscriber.
Note:
The keys on replicated tables are transmitted in each update record to the subscribers. Smaller keys are transmitted more efficiently.Replicated tables have these data type restrictions:
VARCHAR2
, NVARCHAR2
, VARBINARY
and TT_VARCHAR
columns in replicated tables is limited to a size of 4 megabytes. For a VARCHAR2
column, the maximum length when using character length semantics depends on the number of bytes each character occupies when using a particular database character set. For example, if the character set requires four bytes for each character, the maximum possible length is one million characters. For an NVARCHAR2
column, which requires two bytes for each character, the maximum length when using character length semantics is two million characters.
Columns with the BLOB
data type in replicated tables are limited to a size of 16 megabytes. Columns with the CLOB
or NCLOB
data type in replicated tables are limited to a size of 4 megabytes.
A primary key column cannot have a LOB data type.
You cannot replicate tables with compressed columns.
If these requirements and restrictions present difficulties, you may want to consider using the Transaction Log API (XLA) as a replication mechanism. See "Using XLA as a replication mechanism" in Oracle TimesTen In-Memory Database C Developer's Guide.
A replication scheme consists of one or more ELEMENT
descriptions that contain the name of the element, its type (DATASTORE
, TABLE
or SEQUENCE
), the master database on which it is updated, and the subscriber databases to which the updates are replicated.
If you want to replicate a database with cache groups, see Chapter 5, "Administering an Active Standby Pair with Cache Groups".
These are restrictions on elements:
Do not include a specific object (table, sequence or database) in more than one element description.
Do not define the same element in the role of both master and propagator.
An element must include the database on the current host as either the master, subscriber or propagator.
Element names must be unique within a replication scheme.
The correct way to define elements in a multiple subscriber scheme is described in "Multiple subscriber schemes with return services and a log failure threshold". The correct way to propagate elements is described in "Propagation scheme".
The name of each element in a scheme can be used to identify the element if you decide later to drop or modify the element by using the ALTER REPLICATION
statement.
You can add tables, sequences and databases to an existing replication scheme. See "Altering a replication scheme". You can drop a table or sequence from a database that is part of a replication scheme after you exclude the table or sequence from the replication scheme. See "Dropping a table or sequence from a replication scheme".
The rest of this section includes the following topics:
To replicate the entire contents of the master database (masterds
) to the subscriber database (subscriberds
), the ELEMENT
description (named ds1
) might look like the following:
ELEMENT ds1 DATASTORE MASTER masterds ON "system1" SUBSCRIBER subscriberds ON "system2"
Identify a database host using the host name returned by the hostname
operating system command. It is good practice to surround a host name with double quotes.
You cannot replicate a temporary database.
You can choose to exclude certain tables and sequences from the DATASTORE
element by using the EXCLUDE TABLE
and EXCLUDE SEQUENCE
clauses of the CREATE REPLICATION
statement. When you use the EXCLUDE
clauses, the entire database is replicated to all subscribers in the element except for the objects that are specified in the EXCLUDE
clauses. Use only one EXCLUDE TABLE
and one EXCLUDE SEQUENCE
clause in an element description. For example, this element description excludes two tables and one sequence:
ELEMENT ds1 DATASTORE MASTER masterds ON "system1" SUBSCRIBER subscriberds ON "system2" EXCLUDE TABLE ttuser.tab1, ttuser.tab2 EXCLUDE SEQUENCE ttuser.seq1
You can choose to include only certain tables and sequences in the database by using the INCLUDE TABLE
and INCLUDE SEQUENCE
clauses of the CREATE REPLICATION
statement. When you use the INCLUDE
clauses, only the objects that are specified in the INCLUDE
clauses are replicated to each subscriber in the element. Use only one INCLUDE TABLE
and one INCLUDE SEQUENCE
clause in an element description. For example, this element description includes one table and two sequences:
ELEMENT ds1 DATASTORE MASTER masterds ON "system1" SUBSCRIBER subscriberds ON "system2" INCLUDE TABLE ttuser.tab3 INCLUDE SEQUENCE ttuser.seq2, ttuser.seq3
To replicate the ttuser.tab1
and ttuser.tab2
tables from a master database (named masterds
and located on a host named system1
) to a subscriber database (named subscriberds
on a host named system2
), the ELEMENT
descriptions (named a
and b
) might look like the following:
ELEMENT a TABLE ttuser.tab1 MASTER masterds ON "system1" SUBSCRIBER subscriberds ON "system2" ELEMENT b TABLE ttuser.tab2 MASTER masterds ON "system1" SUBSCRIBER subscriberds ON "system2"
For requirements for tables in replication schemes, see "Table requirements and restrictions for replication schemes".
You may choose to replicate all or a subset of tables that have foreign key relationships with one another. However, if the foreign key relationships have been configured with ON DELETE CASCADE
, then you must configure replication to replicate all of the tables, either by configuring the replication scheme with a DATASTORE
element that does not exclude any of the tables, or by configuring the scheme with a TABLE
element for every table that is involved in the relationship.
It is not possible to add a table with a foreign key relationship configured with ON DELETE CASCADE
to a pre-existing replication scheme using ALTER REPLICATION
. Instead, you must drop the replication scheme, create the new table with the foreign key relationship, and then create a new replication scheme replicating all of the related tables.
Sequences are replicated unless you exclude them from the replication scheme or unless they have the CYCLE
attribute. Replication of sequences is optimized by reserving a range of sequence numbers on the standby database each time a sequence is updated on the active database. Reserving a range of sequence numbers reduces the number of updates to the transaction log. The range of sequence numbers is called a cache. Sequence updates on the active database are replicated only when they are followed by or used in replicated transactions.
Consider a sequence my.seq
with a MINVALUE
of 1, an INCREMENT
of 1 and the default Cache
of 20. The very first time that you use my.seq.NEXTVAL
, the current value of the sequence on the master database is changed to 2, and a new current value of 21 (20+1) is replicated to the subscriber. The next 19 references to my.seq.NEXTVAL
on the master database result in no new current value being replicated, because the current value of 21 on the subscriber database is still ahead of the current value on the master. On the twenty-first reference to my.seq.NEXTVAL
, a new current value of 41 (21+20) is transmitted to the subscriber database because the subscriber's previous current value of 21 is now behind the value of 22 on the master.
Sequence replication has these restrictions:
Sequences with the CYCLE
attribute cannot be replicated.
The definition of the replicated sequence on each peer database must be identical.
No conflict checking is performed on sequences. If you make updates to sequences in both databases in a bidirectional replication configuration without using the RETURN TWOSAFE
service, it is possible for both sequences to return the identical NEXTVAL
.
If you need to use sequences in a bidirectional replication scheme where updates may occur on either peer, you may instead use a nonreplicated sequence with different MINVALUE
and MAXVALUE
attributes on each database to avoid conflicts. For example, you may create sequence my.seq
on database DS1
with a MINVALUE
of 1 and a MAXVALUE
of 100, and the same sequence on DS2
with a MINVALUE
of 101 and a MAXVALUE
of 200. Then, if you configure DS1
and DS2
with a bidirectional replication scheme, you can make updates to either database using the sequence my.seq
with the guarantee that the sequence values never conflict. Be aware that if you are planning to use ttRepAdmin
-duplicate
to recover from a failure in this configuration, you must drop and then re-create the sequence with a new MINVALUE
and MAXVALUE
after you have performed the duplicate operation.
Operations on sequences such as SELECT my.seq.NEXTVAL FROM sys.dual
, while incrementing the sequence value, are not replicated until they are followed by transactions on replicated tables. A side effect of this behavior is that these sequence updates are not purged from the log until followed by transactions on replicated tables. This causes ttRepSubscriberWait
and ttRepAdmin
-wait
to fail when only these sequence updates are present at the end of the log.
To replicate the ttuser.seq
sequence from a master database (named masterds
and located on a host named system1
) to a subscriber database (named subscriberds
on a host named system2
), the element description (named a
) might look like the following:
ELEMENT a SEQUENCE ttuser.seq MASTER masterds ON "system1" SUBSCRIBER subscriberds ON "system2"
A materialized view is a summary of data selected from one or more TimesTen tables, called detail tables. Although you cannot replicate materialized views directly, you can replicate their underlying detail tables in the same manner as you would replicate regular TimesTen tables.
The detail tables on the master and subscriber databases can be referenced by materialized views. However, TimesTen replication verifies only that the replicated detail tables have the same structure on both the master and subscriber. It does not enforce that the materialized views are the same on each database.
If you replicate an entire database containing a materialized or nonmaterialized view as a DATASTORE
element, only the detail tables associated with the view are replicated. The view itself is not replicated. A matching view can be defined on the subscriber database, but is not required. If detail tables are replicated, TimesTen automatically updates the corresponding view.
Materialized views defined on replicated tables may result in replication failures or inconsistencies if the materialized view is specified so that overflow or underflow conditions occur when the materialized view is updated.
When databases are configured for bidirectional replication, there is a potential for replication conflicts to occur if the same table row in two or more databases is independently updated at the same time.
Such conflicts can be detected and resolved on a table-by-table basis by including timestamps in the replicated tables and configuring the replication scheme with the optional CHECK CONFLICTS
clause in each table's element description.
See Chapter 14, "Resolving Replication Conflicts" for a complete discussion on replication conflicts and how to configure the CHECK CONFLICTS
clause in the CREATE REPLICATION
statement.
A master database configured for asynchronous or return receipt replication is durable by default. This means that log records are committed to disk when transactions are committed. The master database can be set to nondurable by including the TRANSMIT NONDURABLE
clause in the element description.
Transaction records in the master database log buffer are, by default, flushed to disk before they are forwarded to subscribers. If the entire master database is replicated (ELEMENT
is of type DATASTORE
), you can improve replication performance by eliminating the master's flush-log-to-disk operation from the replication cycle. This is done by including a TRANSMIT NONDURABLE
clause in the element description. The TRANSMIT
setting has no effect on the subscriber. The transaction records on the subscriber database are always flushed to disk.
Master databases configured for return twosafe replication are nondurable by default and cannot be made durable. Setting TRANSMIT DURABLE
on a database that is configured for return twosafe replication has no effect on return twosafe transactions.
Example 9-1 Replicating the entire master database with TRANSMIT NONDURABLE
To replicate the entire contents of the master database (masterds
) to the subscriber database (subscriberds
) and to eliminate the flush-log-to-disk operation, your element description (named a
) might look like the following:
ELEMENT a DATASTORE MASTER masterds ON "system1" TRANSMIT NONDURABLE SUBSCRIBER subscriberds ON "system2"
In general, if a master database fails, you have to initiate the ttRepAdmin
-duplicate
operation described in "Recovering a failed database" to recover the failed master from the subscriber database. This is always true for a master database configured with TRANSMIT DURABLE
.
A database configured as TRANSMIT NONDURABLE
is recovered automatically by the subscriber replication agent if it is configured in the specific type of bidirectional scheme described in "Automatic catch-up of a failed master database". Otherwise, you must follow the procedures described in "Recovering nondurable databases" to recover a failed nondurable database.
You can configure your replication scheme with a return service to ensure a higher level of confidence that replicated data is consistent on both the master and subscriber databases. This section describes how to configure and manage the return receipt and return twosafe services.
You can specify a return service for table elements and database elements for any subscriber defined in a CREATE REPLICATION
or ALTER REPLICATION
statement.
Example 9-2 shows separate SUBSCRIBER
clauses that can define different return service attributes for SubDatabase1
and SubDatabase2
.
Example 9-2 Different return services for each subscriber
CREATE REPLICATION Owner.SchemeName ELEMENT ElementNameElementType MASTER DatabaseName ON "HostName" SUBSCRIBER SubDatabase1 ON "HostName" ReturnServiceAttribute1 SUBSCRIBER SubDatabase2 ON "HostName" ReturnServiceAttribute2;
Alternatively, you can specify the same return service attribute for all of the subscribers defined in an element. Example 9-3 shows the use of a single SUBSCRIBER
clause that defines the same return service attributes for both SubDatabase1
and SubDatabase2
.
Example 9-3 Same return service for all subscribers
CREATE REPLICATION Owner.SchemeName ELEMENT ElementNameElementType MASTER DatabaseName ON "HostName" SUBSCRIBER SubDatabase1 ON "HostName", SubDatabase2 ON "HostName" ReturnServiceAttribute;
These sections describe the return service attributes:
TimesTen provides an optional return receipt service to loosely couple or synchronize your application with the replication mechanism.
Specify the RETURN RECEIPT
attribute to enable the return receipt service for the subscribers listed in the SUBSCRIBER
clause of an element description. With return receipt enabled, when the application commits a transaction for an element on the master database, the application remains blocked until the subscriber acknowledges receipt of the transaction update. If the master is replicating the element to multiple subscribers, the application remains blocked until all of the subscribers have acknowledged receipt of the transaction update.
For example replication schemes that use return receipt services, see Example 9-24 and Example 9-25.
To confirm that all transactions committed on the tab
table in the master database (masterds
) are received by the subscriber (subscriberds
), the element description (e
) might look like the following:
ELEMENT e TABLE tab MASTER masterds ON "system1" SUBSCRIBER subscriberds ON "system2" RETURN RECEIPT
If any of the subscribers are unable to acknowledge receipt of the transaction within a configurable timeout period, the application receives a tt_ErrRepReturnFailed
(8170) warning on its commit request. You can use the ttRepXactStatus
procedure to check on the status of a return receipt transaction. See "Checking the status of return service transactions" for more information on the return service timeout period.
You can also configure the replication agent to disable the return receipt service after a specific number of timeouts. See "Managing return service timeout errors and replication state changes" for details.
The return receipt service is disabled by default if replication is stopped. See "RETURN SERVICES {ON | OFF} WHEN REPLICATION STOPPED" for details.
RETURN RECEIPT
enables notification of receipt for all transactions. You can use RETURN RECEIPT
BY REQUEST
to enable receipt notification only for specific transactions identified by your application.
If you specify RETURN RECEIPT BY REQUEST
for a subscriber, you must use the ttRepSyncSet
built-in procedure to enable the return receipt service for a transaction. The call to enable the return receipt service must be part of the transaction (autocommit must be off).
Example 9-5 RETURN RECEIPT BY REQUEST
To enable confirmation that specific transactions committed on the tab
table in the master database (masterds
) are received by the subscriber (subscriberds
), the element description (e
) might look like:
ELEMENT e TABLE tab MASTER masterds ON "system1" SUBSCRIBER subscriberds ON "system2" RETURN RECEIPT BY REQUEST
Before committing a transaction that requires receipt notification, call the ttRepSyncSet
built-in procedure to request the return services and to set the timeout period to 45 seconds:
Command> CALL ttRepSyncSet(0x01, 45, NULL);
If any of the subscribers are unable to acknowledge receipt of the transaction update within a configurable timeout period, the application receives a tt_ErrRepReturnFailed
(8170) warning on its commit request. See "Setting the return service timeout period".
You can use the ttRepSyncGet
built-in procedure to check if a return service is enabled and obtain the timeout value. For example:
Command> CALL ttRepSyncGet(); < 01, 45, 1> 1 row found.
RETURN TWOSAFE
enables notification of commit on the subscriber for all transactions. You can use RETURN TWOSAFE
BY REQUEST
to enable notification of subscriber commit only for specific transactions identified by the application.
If you specify RETURN TWOSAFE BY REQUEST
for a subscriber, you must use the ttRepSyncSet
procedure to enable the return twosafe service for a transaction. The call to enable the return twosafe service must be part of the transaction (autocommit must be off).
The ALTER TABLE
statement cannot be used to alter a replicated table that is part of a RETURN TWOSAFE BY REQUEST
transaction. If DDLCommitBehavior
=0 (the default), the ALTER TABLE
operation succeeds because a commit is performed before the ALTER TABLE
operation, resulting in the ALTER TABLE
operation executing in a new transaction which is not part of the RETURN TWOSAFE BY REQUEST
transaction. If DDLCommitBehavior
=1, the ALTER TABLE
operation results in error 8051.
Example 9-6 RETURN TWOSAFE BY REQUEST
To enable confirmation that specific transactions committed on the master database (databaseA
) are also committed by the subscriber (databaseB
), the element description (a
) might look like:
ELEMENT a DATASTORE MASTER databaseA ON "system1" SUBSCRIBER databaseB ON "system2" RETURN TWOSAFE BY REQUEST;
Before calling commit for a transaction that requires confirmation of commit on the subscriber, call the ttRepSyncSet
built-in procedure to request the return service, set the timeout period to 45 seconds, and specify no action (1) in the event of a timeout error:
Command> CALL ttRepSyncSet(0x01, 45, 1);
In this example, if the subscriber is unable to acknowledge commit of the transaction within the timeout period, the application receives a tt_ErrRepReturnFailed
(8170) warning on its commit request. The application can then chose how to handle the timeout. See "Setting the return service timeout period".
You can use the ttRepSyncGet
built-in procedure to check if a return service is enabled and obtain the timeout value. For example:
Command> CALL ttRepSyncGet(); < 01, 45, 1> 1 row found.
The return twosafe service ensures that each replicated transaction is committed on the subscriber database before it is committed on the master database. If replication is unable to verify the transaction has been committed on the subscriber, it returns notification of the error. Upon receiving an error, the application can either take a unique action or fall back on preconfigured actions, depending on the type of failure.
The return twosafe service is intended to be used in replication schemes where two databases must stay synchronized. One database has an active role, while the other database has a standby role but must be ready to assume an active role at any moment. Use return twosafe with a bidirectional replication scheme with exactly two databases.
To enable the return twosafe service for the subscriber, specify the RETURN TWOSAFE
attribute in the SUBSCRIBER
clause in the CREATE REPLICATION
or ALTER REPLICATION
statement.
To confirm all transactions committed on the master database (databaseA
) are also committed by the subscriber (databaseB
), the element description (a
) might look like the following:
ELEMENT a DATASTORE MASTER databaseA ON "system1" SUBSCRIBER databaseB ON "system2" RETURN TWOSAFE
The entire CREATE REPLICATION
statement that specifies both databaseA
and databaseB
in a bidirectional configuration with RETURN TWOSAFE
might look like the following:
CREATE REPLICATION bidirect ELEMENT a DATASTORE MASTER databaseA ON "system1" SUBSCRIBER databaseB ON "system2" RETURN TWOSAFE ELEMENT b DATASTORE MASTER databaseB ON "system2" SUBSCRIBER databaseA ON "system1" RETURN TWOSAFE;
When replication is configured with RETURN TWOSAFE
, you must disable autocommit mode
When the application commits a transaction on the master database, the application remains blocked until the subscriber acknowledges it has successfully committed the transaction. Initiating identical updates or deletes on both databases can lead to deadlocks in commits that can be resolved only by stopping the processes.
If the subscriber is unable to acknowledge commit of the transaction update within a configurable timeout period, your application receives a tt_ErrRepReturnFailed
(8170) warning on its commit request. See "Setting the return service timeout period".
Use the NO RETURN
attribute to explicitly disable the return receipt or return twosafe service. NO RETURN
is the default condition. This attribute is typically set in ALTER REPLICATION
statements. See Example 13-13.
Table 9-3 lists the optional STORE
parameters for the CREATE REPLICATION
and ALTER REPLICATION
statements.
Table 9-3 STORE attribute descriptions
STORE attribute | Description |
---|---|
Set the return service policy so that return service blocking is disabled after the number of timeouts specified by See "Establishing return service failure/recovery policies". |
|
Set return services on or off when replication is disabled. See "Establishing return service failure/recovery policies". |
|
If See "Establishing return service failure/recovery policies". |
|
Specifies the number of seconds to wait for return service acknowledgement. A value of 0 means that there is no waiting. The default value is 10 seconds. The application can override this timeout setting by using the |
|
Overrides the See "DURABLE COMMIT". |
|
Specify the default action to be taken for a return service transaction in the event of a timeout. The options are:
This default setting can be overridden for specific transactions by using the |
|
Compress replicated traffic to reduce the amount of network bandwidth used. |
|
Set the port number used by subscriber databases to listen for updates from a master. If no See "Port assignments". |
|
Set the maximum number of seconds that the replication agent waits for a response from its database. |
|
Set the log failure threshold. |
|
Specify the number of replication conflicts per second at which conflict reporting is suspended, and the number of conflicts per second at which conflict reporting resumes. |
|
Specify the type of table definition checking: |
The FAILTHRESHOLD
and TIMEOUT
attributes can be unique to a specific replication scheme definition. This means these attribute settings can vary if you have applied different replication scheme definitions to your replicated databases. This is not true for any of the other attributes, which must be the same across all replication scheme definitions. For example, setting the PORT
attribute for one scheme sets it for all schemes.
For an example replication scheme that uses a STORE
clause to set the FAILTHRESHOLD
attribute, see Example 9-24.
If your replication scheme is configured with one of the return services described in "Using a return service", a timeout occurs if any of the subscribers are unable to send an acknowledgement back to the master within the time period specified by RETURN WAIT TIME
.
The default return service timeout period is 10 seconds. You can specify a different return service timeout period by:
Configuring RETURN WAIT TIME
in the CREATE REPLICATION
or ALTER REPLICATION
statement. A RETURN WAIT TIME
of 0
indicates no waiting.
Calling the ttRepSyncSet
procedure with a new returnWait
parameter
Once set, the timeout period applies to all subsequent return service transactions until you either reset the timeout period or terminate the application session. The timeout setting applies to all return services for all subscribers.
A return service may time out because of a replication failure or because replication is so far behind that the return service transaction times out before it is replicated. However, unless there is a simultaneous replication failure, failure to obtain a return service confirmation from the subscriber does not mean the transaction has not been or will not be replicated.
You can set other STORE
attributes to establish policies that automatically disable return service blocking in the event of excessive timeouts and re-enable return service blocking when conditions improve. See "Managing return service timeout errors and replication state changes".
Example 9-8 Setting the timeout period for both databases in bidirectional replication scheme
To set the timeout period to 30 seconds for both bidirectionally replicated databases, databaseA
and databaseB
, in the bidirect
replication scheme, the CREATE REPLICATION
statement might look like the following:
CREATE REPLICATION bidirect ELEMENT a DATASTORE MASTER databaseA ON "system1" SUBSCRIBER databaseB ON "system2" RETURN TWOSAFE ELEMENT b DATASTORE MASTER databaseB ON "system2" SUBSCRIBER databaseA ON "system1" RETURN TWOSAFE STORE databaseA RETURN WAIT TIME 30 STORE databaseB RETURN WAIT TIME 30;
The replication state can be reset to stop
by a user or by the master replication agent in the event of a subscriber failure. A subscriber may be unable to acknowledge a transaction that makes use of a return service and may time out with respect to the master. If any of the subscribers are unable to acknowledge the transaction update within the timeout period, the application receives an errRepReturnFailed
warning on its commit request.
The default return service timeout period is 10 seconds. You can specify a different return service timeout period by:
Configuring the RETURN WAIT TIME
attribute in the STORE
clause of the CREATE REPLICATION
or ALTER REPLICATION
statement
Calling ttRepSyncSet
procedure with a new returnWait
parameter
A return service may time out or fail because of a replication failure or because replication is so far behind that the return service transaction times out before it is replicated. However, unless there is a simultaneous replication failure, failure to obtain a return service confirmation from the subscriber does not necessarily mean the transaction has not been or will not be replicated.
This section describes how to detect and respond to timeouts on return service transactions. The main topics are:
You may want respond in some manner if replication is stopped or return service timeout failures begin to adversely impact the performance of the replicated system. Your "tolerance threshold" for return service timeouts may depend on the historical frequency of timeouts and the performance/availability equation for your particular application, both of which should be factored into your response to the problem.
When using the return receipt service, you can manually respond by:
Using ALTER REPLICATION
to make changes to the replication scheme to disable return receipt blocking for a particular subscriber. If you decide to disable return receipt blocking, your decision to re-enable it depends on your confidence level that the return receipt transaction is no longer likely to time out.
Calling the ttDurableCommit
procedure to durably commit transactions on the master that you can no longer verify as being received by the subscriber.
An alternative to manually responding to return service timeout failures is to establish return service failure and recovery policies in your replication scheme. These policies direct the replication agents to detect changes to the replication state and to keep track of return service timeouts and then automatically respond in some predefined manner.
An alternative to manually responding to return service timeout failures is to establish return service failure and recovery policies in your replication scheme. These policies direct the replication agents to detect changes to the replication state and to keep track of return service timeouts and then automatically respond in some predefined manner.
The following attributes in the CREATE REPLICATION
or ALTER REPLICATION
statement set the failure/recovery policies when using a RETURN RECEIPT
or RETURN TWOSAFE
service:
The policies set by these attributes are applicable for the life of the database or until changed. However, the replication agent must be running to enforce these policies.
The RETURN SERVICES {ON|OFF} WHEN REPLICATION STOPPED
attribute determines whether a return receipt or return twosafe service continues to be enabled or is disabled when replication is stopped. "Stopped" in this context means that either the master replication agent is stopped (for example, by ttAdmin
-repStop
master
) or the replication state of the subscriber database is set to stop
or pause
with respect to the master database (for example, by ttRepAdmin
-state stop
subscriber
). A failed subscriber that has exceeded the specified FAILTHRESHOLD
value is set to the failed
state, but is eventually set to the stop
state by the master replication agent.
Note:
A subscriber may become unavailable for a period of time that exceeds the timeout period specified byRETURN WAIT TIME
but still be considered by the master replication agent to be in the start
state. Failure policies related to timeouts are set by the DISABLE RETURN
attribute.RETURN SERVICES OFF WHEN REPLICATION STOPPED
disables the return service when replication is stopped and is the default when using the RETURN RECEIPT
service. RETURN SERVICES ON WHEN REPLICATION STOPPED
allows the return service to continue to be enabled when replication is stopped and is the default when using the RETURN TWOSAFE
service.
Example 9-10 RETURN SERVICES ON WHEN REPLICATION STOPPED
Configure the CREATE REPLICATION
statement to replicate updates from the masterds
database to the subscriber1
database. The CREATE REPLICATION
statement specifies the use of RETURN RECEIPT
and RETURN SERVICES ON WHEN REPLICATION STOPPED
.
CREATE REPLICATION myscheme ELEMENT e TABLE tab MASTER masterds ON "server1" SUBSCRIBER subscriber1 ON "server2" RETURN RECEIPT STORE masterds ON "server1" RETURN SERVICES ON WHEN REPLICATION STOPPED;
While the application is committing updates to the master, ttRepAdmin
is used to set subscriber1
to the stop
state:
ttRepAdmin -dsn masterds -receiver -name subscriber1 -state stop
The application continues to wait for return receipt acknowledgements from subscriber1
until the replication state is reset to start
and it receives the acknowledgment:
ttRepAdmin -dsn masterds -receiver -name subscriber1 -state start
When a DISABLE RETURN
value is set, the database keeps track of the number of return receipt or return twosafe transactions that have exceeded the timeout period set by RETURN WAIT TIME
. If the number of timeouts exceeds the maximum value set by DISABLE RETURN
, the applications revert to a default replication cycle in which they no longer wait for subscribers to acknowledge the replicated updates.
You can set DISABLE RETURN SUBSCRIBER
to establish a failure policy to disable return service blocking for only those subscribers that have timed out, or DISABLE RETURN ALL
to establish a policy to disable return service blocking for all subscribers. You can use the ttRepSyncSubscriberStatus
built-in procedure or the ttRepReturnTransitionTrap
SNMP trap to determine whether a particular subscriber has been disabled by the DISABLE RETURN
failure policy.
The DISABLE RETURN
failure policy is enabled only when the replication agent is running. If DISABLE RETURN
is specified but RESUME RETURN
is not specified, the return services remain off until the replication agent for the database has been restarted. You can cancel this failure policy by stopping the replication agent and specifying either DISABLE RETURN SUBSCRIBER
or DISABLE RETURN ALL
with a zero value for NumFailures
. The count of timeouts to trigger the failure policy is reset either when you restart the replication agent, when you set the DISABLE RETURN
value to 0, or when return service blocking is re-enabled by RESUME RETURN
.
DISABLE RETURN
maintains a cumulative timeout count for each subscriber. If there are multiple subscribers and you set DISABLE RETURN SUBSCRIBER
, the replication agent disables return service blocking for the first subscriber that reaches the timeout threshold. If one of the other subscribers later reaches the timeout threshold, the replication agent disables return service blocking for that subscriber also.
Example 9-11 DISABLE RETURN SUBSCRIBER
Configure the CREATE REPLICATION
statement to replicate updates from the masterds
database to the databases, subscriber1
and subscriber2
. The CREATE REPLICATION
statement specifies the use of RETURN RECEIPT
and DISABLE RETURN SUBSCRIBER
with a NumFailures
value of 5. The RETURN WAIT TIME
is set to 30 seconds.
CREATE REPLICATION myscheme ELEMENT e TABLE tab MASTER masterds ON "server1" SUBSCRIBER subscriber1 ON "server2", subscriber2 ON "server3" RETURN RECEIPT STORE masterds ON "server1" DISABLE RETURN SUBSCRIBER 5 RETURN WAIT TIME 30;
While the application is committing updates to the master, subscriber1
experiences problems and fails to acknowledge a replicated transaction update. The application is blocked 30 seconds after which it commits its next update to the master. Over the course of the application session, this commit/timeout cycle repeats 4 more times until DISABLE RETURN
disables return receipt blocking for subscriber1
. The application continues to wait for return-receipt acknowledgements from subscriber2
but not from subscriber1
.
RETURN SERVICES OFF WHEN REPLICATION STOPPED
is the default setting for the return receipt service. Therefore, return receipt is disabled under either one of the following conditions:
The subscriber is unable to acknowledge an update within the specified RETURN WAIT TIME
, as described above.
Replication is stopped, as described in "RETURN SERVICES {ON | OFF} WHEN REPLICATION STOPPED".
For another example that set the DISABLE RETURN
attribute, see Example 9-12.
When we say return service blocking is "disabled," we mean that the applications on the master database no longer block execution while waiting to receive acknowledgements from the subscribers that they received or committed the replicated updates. Note, however, that the master still listens for an acknowledgement of each batch of replicated updates from the subscribers.
You can establish a return service recovery policy by setting the RESUME RETURN
attribute and specifying a resume latency value. When this attribute is set and return service blocking has been disabled for a subscriber, the return receipt or return twosafe service is re-enabled when the commit-to-acknowledge time for a transaction falls below the value set by RESUME RETURN
. The commit-to-acknowledge time is the latency between when the application issues a commit and when the master receives acknowledgement of the update from the subscriber.
If return receipt blocking has been disabled for subscriber1
and if RESUME RETURN
is set to 8 milliseconds, then return receipt blocking is re-enabled for subscriber1
the instant it acknowledges an update in less than 8 milliseconds from when it was committed by the application on the master.
CREATE REPLICATION myscheme ELEMENT e TABLE ttuser.tab MASTER masterds ON "server1" SUBSCRIBER subscriber1 ON "server2", subscriber2 ON "server3" RETURN RECEIPT STORE masterds ON "server1" DISABLE RETURN SUBSCRIBER 5 RESUME RETURN 8;
The RESUME RETURN
policy is enabled only when the replication agent is running. You can cancel a return receipt resume policy by stopping the replication agent and then using ALTER REPLICATION
to set RESUME RETURN
to zero.
Set the DURABLE COMMIT
attribute to specify the durable commit policy for applications that have return service blocking disabled by DISABLE RETURN
. When DURABLE COMMIT
is set to ON
, it overrides the DurableCommits
general connection attribute on the master database and forces durable commits regardless of whether the replication agent is running or stopped.
DURABLE COMMIT
is useful if you have only one subscriber. However, if you are replicating the same data to two subscribers and you disable return service blocking to one subscriber, then you achieve better performance if you rely on the other subscriber than you would if you enable durable commits.
Example 9-13 DURABLE COMMIT ON
Set DURABLE COMMIT ON
when establishing a DISABLE RETURN ALL
policy to disable return-receipt blocking for all subscribers. If return-receipt blocking is disabled, commits are durably committed to disk to provide redundancy.
CREATE REPLICATION myscheme ELEMENT e TABLE tab MASTER masterds ON "server1" SUBSCRIBER subscriber ON "server2", subscriber2 ON "server3" RETURN RECEIPT STORE masterds ON "server1" DISABLE RETURN ALL 5 DURABLE COMMIT ON RESUME RETURN 8;
When using the return twosafe service, you can specify how the master replication agent responds to timeout errors by:
Setting the LOCAL COMMIT ACTION
attribute in the STORE
clause of the CREATE REPLICATION
statement
Calling the ttRepSyncSet
procedure with the localAction
parameter
The possible actions upon receiving a timeout during replication of a twosafe transaction are:
COMMIT
- On timeout, the commit function attempts to perform a commit to end the transaction locally. No more operations are possible on the same transaction.
NO ACTION
- On timeout, the commit function returns to the application, leaving the transaction in the same state it was in when it entered the commit call, with the exception that the application is not able to update any replicated tables. The application can reissue the commit. This is the default
If the call returns with an error, you can use the ttRepXactStatus
procedure described in "Checking the status of return service transactions" to check the status of the transaction. Depending on the error, your application can choose to:
Reissue the commit call - This repeats the entire return twosafe replication cycle, so that the commit call returns when the success or failure of the replicated commit on the subscriber is known or if the timeout period expires.
Roll back the transaction - If the call returns with an error related to applying the transaction on the subscriber, such as primary key lookup failure, you can roll back the transaction on the master.
If you are replicating over a low-bandwidth network, or if you are replicating massive amounts of data, you can set the COMPRESS TRAFFIC
attribute to reduce the amount of bandwidth required for replication. The COMPRESS TRAFFIC
attribute compresses the replicated data from the database specified by the STORE
parameter in your CREATE REPLICATION
or ALTER REPLICATION
statement. TimesTen does not compress traffic from other databases.
Although the compression algorithm is optimized for speed, enabling the COMPRESS TRAFFIC
attribute affects replication throughput and latency.
Example 9-14 Compressing traffic from one database
To compress replicated traffic from database dsn1
and leave the replicated traffic from dsn2
uncompressed, the CREATE REPLICATION
statement looks like:
CREATE REPLICATION repscheme ELEMENT d1 DATASTORE MASTER dsn1 ON host1 SUBSCRIBER dsn2 ON host2 ELEMENT d2 DATASTORE MASTER dsn2 ON host2 SUBSCRIBER dsn1 ON host1 STORE dsn1 ON host1 COMPRESS TRAFFIC ON;
Example 9-15 Compressing traffic between both databases
To compress the replicated traffic between both the dsn1
and dsn2
databases, use:
CREATE REPLICATION scheme ELEMENT d1 DATASTORE MASTER dsn1 ON host1 SUBSCRIBER dsn2 ON host2 ELEMENT d2 DATASTORE MASTER dsn2 ON host2 SUBSCRIBER dsn1 ON host1 STORE dsn1 ON host1 COMPRESS TRAFFIC ON STORE dsn2 ON host2 COMPRESS TRAFFIC ON;
Static port assignments are recommended. If you do not assign a PORT
attribute, the TimesTen daemon dynamically selects the port. When ports are assigned dynamically for the replication agents, then the ports of the TimesTen daemons have to match as well. Setting the PORT
attribute for one replication scheme sets it for all replication schemes.
You must assign static ports if you want to do online upgrades.
When statically assigning ports, it is important to specify the full host name, DSN and port in the STORE
attribute of the CREATE REPLICATION
statement.
You can establish a threshold value that, when exceeded, sets an unavailable subscriber to the failed
state before the available log space is exhausted. Use the FAILTHRESHOLD
attribute to set the log failure threshold. See Example 9-24.
The default threshold value is 0, which means "no limit." See "Setting connection attributes for logging" for details about log failure threshold values.
If a master sets a subscriber database to the failed
state, it drops all of the data for the failed subscriber from its log and transmits a message to the failed subscriber database. If the master replication agent can communicate with the subscriber replication agent, then the message is transmitted immediately. Otherwise, the message is transmitted when the connection is reestablished. After receiving the message from the master, if the subscriber is configured for bidirectional replication or to propagate updates to other subscribers, it does not transmit any further updates, because its replication state has been compromised.
Any application that connects to the failed subscriber receives a tt_ErrReplicationInvalid
(8025) warning indicating that the database has been marked failed
by a replication peer. Once the subscriber database has been informed of its failed status, its state on the master database is changed from failed
to stop
.
Applications can use the ODBC SQLGetInfo
function to check if the database it is connected to has been set to the failed
state, as described in "Subscriber failures".
Use the TABLE DEFINITION CHECKING RELAXED
attribute to enable replication of tables that are not identical. For example, if tables have columns in a different order or have a different number of partitions, you can replicate them using this clause. A table has multiple partitions if columns have been added after its initial creation.
Note:
See Example 9-18 and "Check partition counts for the tables" in Oracle TimesTen In-Memory Database Troubleshooting Guide for more information.Setting the TABLE DEFINITION CHECKING
attribute to RELAXED
requires that replicated tables have the same key definition, number of columns and column data types. Table definition checking occurs on the subscriber side. Setting this attribute to RELAXED
for both master and subscriber has the same effect as setting it for only the subscriber.
The RELAXED
setting can result in slightly slower performance. The change in performance depends on the workload and the number of partitions and columns in the tables. You can set table definition checking to RELAXED
temporarily while consolidating tables with multiple partitions and then reset it to EXACT
. There is no performance loss for tables with identical structures.
Example 9-17 Replicating tables with columns in different positions
Create table t1
in dsn1
database:
CREATE TABLE ttuser.t1 (a INT PRIMARY KEY, b INT, c INT);
Create table ttuser.t1
in dsn2
database with the columns in a different order than the columns in ttuser.t1
in dsn1
database. Note that the column names and data types are the same in both tables and a
is the primary key in both tables.
CREATE TABLE ttuser.t1 (c INT, a INT PRIMARY KEY, b INT);
Create replication scheme ttuser.rep1
. Set TABLE DEFINITION CHECKING
to RELAXED
for the subscriber, dsn2
.
CREATE REPLICATION ttuser.rep1 ELEMENT e1 TABLE ttuser.t1 MASTER dsn1 SUBSCRIBER dsn2 STORE dsn2 TABLE DEFINITION CHECKING RELAXED;
Start the replication agent for both databases. Insert a row into ttuser.t1
on dsn1
.
Command> INSERT INTO ttuser.t1 VALUES (4,5,6); 1 row inserted.
Verify the results on ttuser.t1
on dsn2
.
Command> SELECT * FROM ttuser.t1; < 5, 6, 4 > 1 row found.
Example 9-18 Replicating tables with a different number of partitions
When you alter a table to add columns, it increases the number of partitions in the table, even if you subsequently drop the new columns. You can use the RELAXED
setting for TABLE DEFINITION CHECKING
to replicate tables that have different number of partitions.
Create table ttuser.t3
on dsn1
with two columns.
CREATE TABLE ttuser.t3 (a INT PRIMARY KEY, b INT);
Create table ttuser.t3
on dsn2
with one column that is the primary key.
CREATE TABLE ttuser.t3 (a INT PRIMARY KEY);
Add a column to the table on dsn2
. This increases the number of partitions to two, while the table on dsn1
has one partition.
ALTER TABLE ttuser.t3 ADD COLUMN b INT;
Create the replication scheme on both databases.
CREATE REPLICATION reppart ELEMENT e2 TABLE ttuser.t3 MASTER dsn1 SUBSCRIBER dsn2 STORE dsn2 TABLE DEFINITION CHECKING RELAXED;
Start the replication agent for both databases. Insert a row into ttuser.t3
on dsn1
.
Command> INSERT INTO ttuser.t3 VALUES (1,2); 1 row inserted.
Verify the results in ttuser.t3
on dsn2
.
Command> SELECT * FROM ttuser.t3; < 1, 2 > 1 row found.
If your replication host has more than one network interface, you may wish to configure replication to use an interface other than the default interface. Although you must specify the host name returned by the operating system's hostname
command when you define a replication element, you may configure replication to send or receive traffic over a different interface using the ROUTE
clause.
The syntax of the ROUTE
clause is:
ROUTE MASTER FullDatabaseName SUBSCRIBER FullDatabaseName {{MASTERIP MasterHost | SUBSCRIBERIP SubscriberHost} PRIORITY Priority} [...]
In dual master replication schemes, each master database is a subscriber of the other master database. This means that the CREATE REPLICATION
statement should include ROUTE
clauses in multiples of two to specify a route in both directions.
Example 9-19 Configuring multiple network interfaces
If host host1
is configured with a second interface accessible by the host name host1fast
, and host2
is configured with a second interface at IP address 192.168.1.100, you may specify that the secondary interfaces are used with the replication scheme.
CREATE REPLICATION repscheme ELEMENT e1 TABLE ttuser.tab MASTER dsn1 ON host1 SUBSCRIBER dsn2 ON host2 ELEMENT e2 TABLE ttuser.tab MASTER dsn2 ON host2 SUBSCRIBER dsn1 ON host1 ROUTE MASTER dsn1 ON host1 SUBSCRIBER dsn2 ON host2 MASTERIP host1fast PRIORITY 1 SUBSCRIBERIP "192.168.1.100" PRIORITY 1 ROUTE MASTER dsn2 ON host2 SUBSCRIBER dsn1 ON host1 MASTERIP "192.168.1.100" PRIORITY 1 SUBSCRIBERIP host1fast PRIORITY 1;
Alternately, on a replication host with more than one interface, you may wish to configure replication to use one or more interfaces as backups, in case the primary interface fails or the connection from it to the receiving host is broken. You may use the ROUTE
clause to specify two or more interfaces for each master or subscriber that are used by replication in order of priority.
Example 9-20 Configuring network priority
If host host1
is configured with two network interfaces at IP addresses 192.168.1.100 and 192.168.1.101, and host host2
is configured with two interfaces at IP addresses 192.168.1.200 and 192.168.1.201, you may specify that replication use IP addresses 192.168.1.100 and 192.168.200 to transmit and receive traffic first, and to try IP addresses 192.168.1.101 or 192.168.1.201 if the first connection fails.
CREATE REPLICATION repscheme ELEMENT e TABLE ttuser.tab MASTER dsn1 ON host1 SUBSCRIBER dsn2 ON host2 ROUTE MASTER dsn1 ON host1 SUBSCRIBER dsn2 ON host2 MASTERIP "192.168.1.100" PRIORITY 1 MASTERIP "192.168.1.101" PRIORITY 2 SUBSCRIBERIP "192.168.1.200" PRIORITY 1 SUBSCRIBERIP "192.168.1.201" PRIORITY 2;
If replication on the master host is unable to bind to the MASTERIP
with the highest priority, it will try to connect using subsequent MASTERIP
addresses in order of priority immediately. However, if the connection to the subscriber fails for any other reason, replication will try to connect using each of the SUBSCRIBERIP
addresses in order of priority before it tries the MASTERIP
address with the next highest priority.
The examples in this section illustrate how to configure a variety of replication schemes. The replication schemes include:
The scheme shown in Example 9-21 is a single master and subscriber unidirectional replication scheme. The two databases are located on separate hosts, system1
and system2
. We use the RETURN RECEIPT
service to confirm that all transactions committed on the ttuser.tab
table in the master database are received by the subscriber.
Example 9-21 Replicating one table
CREATE REPLICATION repscheme ELEMENT e TABLE ttuser.tab MASTER masterds ON "system1" SUBSCRIBER subscriberds ON "system2" RETURN RECEIPT;
The scheme shown in Example 9-22 is a single master and subscriber unidirectional replication scheme. The two databases are located on separate hosts, server1
and server2
. The master database, named masterds
, replicates its entire contents to the subscriber database, named subscriberds
.
You can create a replication scheme that includes up to 128 subscriber databases. If you are configuring propagator databases, you can configure up to 128 propagators. Each propagator can have up to 128 subscriber databases. See "Propagation scheme" for an example of a replication scheme with propagator databases.
Example 9-23 Replicating to two subscribers
This example establishes a master database, named masterds
, that replicates the ttuser.tab
table to two subscriber databases, subscriber1ds
and subscriber2ds
, located on server2
and server3
, respectively. The name of the replication scheme is twosubscribers
. The name of the replication element is e
.
CREATE REPLICATION twosubscribers ELEMENT e TABLE ttuser.tab MASTER masterds ON "server1" SUBSCRIBER subscriber1ds ON "server2", subscriber2ds ON "server3";
Example 9-24 Replicating to two subscribers with RETURN RECEIPT
This example uses the basic example in Example 9-23 and adds a RETURN RECEIPT
attribute and a STORE
parameter. RETURN RECEIPT
enables the return receipt service for both databases. The STORE
parameter sets a FAILTHRESHOLD
value of 10 to establish the maximum number of transaction log files that can accumulate on masterds
for a subscriber before it assumes the subscriber has failed.
CREATE REPLICATION twosubscribers ELEMENT e TABLE ttuser.tab MASTER masterds ON "server1" SUBSCRIBER subscriber1ds ON "server2", subscriber2ds ON "server3" RETURN RECEIPT STORE masterds FAILTHRESHOLD 10;
Example 9-25 Enabling RETURN RECEIPT for only one subscriber
This example shows how to enable RETURN RECEIPT
for only subscriber2ds
. Note that there is no comma after the subscriber1ds
definition.
CREATE REPLICATION twosubscribers ELEMENT e TABLE ttuser.tab MASTER masterds ON "server1" SUBSCRIBER subscriber1ds ON "server2" SUBSCRIBER subscriber2ds ON "server3" RETURN RECEIPT STORE masterds FAILTHRESHOLD 10;
Example 9-26 Enabling different return services for subscribers
This example shows how to apply RETURN RECEIPT BY REQUEST
to subscriber1ds
and RETURN RECEIPT
to subscriber2ds
. In this scheme, applications accessing subscriber1ds
must use the ttRepSyncSet
procedure to enable the return services for a transaction, while subscriber2ds
unconditionally provides return services for all transactions.
CREATE REPLICATION twosubscribers ELEMENT e TABLE ttuser.tab MASTER masterds ON "server1" SUBSCRIBER subscriberds1 ON "server2" RETURN RECEIPT BY REQUEST SUBSCRIBER subscriber2ds ON "server3" RETURN RECEIPT STORE masterds FAILTHRESHOLD 10;
The replication scheme shown in Example 9-27 establishes a master database, named centralds
, that replicates four tables. ttuser.tab1
and ttuser.tab2
are replicated to the subscriber backup1ds
. ttuser.tab3
and ttuser.tab4
are replicated to backup2ds
. The master database is located on the finance
server. Both subscribers are located on the backupsystem
server.
Example 9-27 Replicating tables to different subscribers
CREATE REPLICATION twobackups ELEMENT a TABLE ttuser.tab1 MASTER centralds ON "finance" SUBSCRIBER backup1ds ON "backupsystem" ELEMENT b TABLE ttuser.tab2 MASTER centralds ON "finance" SUBSCRIBER backup1ds ON "backupsystem" ELEMENT d TABLE ttuser.tab3 MASTER centralds ON "finance" SUBSCRIBER backup2ds ON "backupsystem" ELEMENT d TABLE ttuser.tab4 MASTER centralds ON "finance" SUBSCRIBER backup2ds ON "backupsystem";
In Example 9-28, the master database sends updates on a table to a propagator that forwards the changes to two subscribers. The master database is centralds
on the finance
host. The propagator database is propds
on the nethandler
host. The subscribers are backup1ds
on backupsystem1
and backup2ds
on backupsystem2
.
The replication scheme has two elements. For element a
, the changes to the tab
table on centralds
are replicated to the propds
propagator database. For element b
, the changes to the tab
table received by propds
are replicated to the two subscribers, backup1ds
and backup2ds
.
In Example 9-29, there are two databases, westds
on the westcoast
host and eastds
on the eastcoast
host. Customers are represented in two tables: waccounts
contains data for customers in the Western region and eaccounts
has data for customers from the Eastern region. The westds
database updates the waccounts
table and replicates it to the eastds
database. The eaccounts
table is owned by the eastds
database and is replicated to the westds
database. The RETURN RECEIPT
attribute enables the return receipt service to guarantee that transactions on either master table are received by their subscriber.
Example 9-29 Bidirectional split workload
CREATE REPLICATION r1 ELEMENT elem_waccounts TABLE ttuser.waccounts MASTER westds ON "westcoast" SUBSCRIBER eastds ON "eastcoast" RETURN RECEIPT ELEMENT elem_eaccounts TABLE ttuser.eaccounts MASTER eastds ON "eastcoast" SUBSCRIBER westds ON "westcoast" RETURN RECEIPT;
Example 9-30 shows a bidirectional general workload replication scheme in which the ttuser.accounts
table can be updated on either the eastds
or westds
database. Each database is both a master and a subscriber for the accounts
table.
Note:
Do not use a bidirectional distributed workload replication scheme with return twosafe return service.Example 9-30 Bidirectional distributed workload scheme
CREATE REPLICATION r1 ELEMENT elem_accounts_1 TABLE ttuser.accounts MASTER westds ON "westcoast" SUBSCRIBER eastds ON "eastcoast" ELEMENT elem_accounts_2 TABLE ttuser.accounts MASTER eastds ON "eastcoast" SUBSCRIBER westds ON "westcoast";
When elements are replicated in this manner, the applications should write to each database in a coordinated manner to avoid simultaneous updates on the same data. To manage update conflicts, include a timestamp column of type BINARY(8)
in the replicated table and enable timestamp comparison by including the CHECK CONFLICTS
clause in the CREATE REPLICATION
statement. See Chapter 14, "Resolving Replication Conflicts" for a complete discussion on how to manage update conflicts.
Example 9-31 shows that the tstamp
timestamp column is included in the ttuser.accounts
table. The CREATE REPLICATION
statement has been modified to include the CHECK CONFLICTS
clause.
Example 9-31 Managing update conflicts
CREATE TABLE ttuser.accounts (custname VARCHAR2(30) NOT NULL, address VARCHAR2(80), curbalance DEC(15,2), tstamp BINARY(8), PRIMARY KEY (custname)); CREATE REPLICATION r1 ELEMENT elem_accounts_1 TABLE ttuser.accounts CHECK CONFLICTS BY ROW TIMESTAMP COLUMN tstamp UPDATE BY SYSTEM ON EXCEPTION ROLLBACK WORK MASTER westds ON "westcoast" SUBSCRIBER eastds ON "eastcoast" ELEMENT elem_accounts_2 TABLE ttuser.accounts CHECK CONFLICTS BY ROW TIMESTAMP COLUMN tstamp UPDATE BY SYSTEM ON EXCEPTION ROLLBACK WORK MASTER eastds ON "eastcoast" SUBSCRIBER westds ON "westcoast";
Creating your replication schemes with scripts can save you time and help you avoid mistakes. This section provides some suggestions for automating the creation of replication schemes using Perl.
Consider the general workload bidirectional scheme shown in Example 9-32. Entering the element description for the five tables, ttuser.accounts
, ttuser.sales
, ttuser.orders
, ttuser.inventory
, and ttuser.customers
, would be tedious and error-prone if done manually.
Example 9-32 General workload bidirectional replication scheme
CREATE REPLICATION bigscheme ELEMENT elem_accounts_1 TABLE ttuser.accounts MASTER westds ON "westcoast" SUBSCRIBER eastds ON "eastcoast" ELEMENT elem_accounts_2 TABLE ttuser.accounts MASTER eastds ON "eastcoast" SUBSCRIBER westds ON "westcoast" ELEMENT elem_sales_1 TABLE ttuser.sales MASTER westds ON "westcoast" SUBSCRIBER eastds ON "eastcoast" ELEMENT elem_sales_2 TABLE ttuser.sales MASTER eastds ON "eastcoast" SUBSCRIBER westds ON "westcoast" ELEMENT elem_orders_1 TABLE ttuser.orders MASTER westds ON "westcoast" SUBSCRIBER eastds ON "eastcoast" ELEMENT elem_orders_2 TABLE ttuser.orders MASTER eastds ON "eastcoast" SUBSCRIBER westds ON "westcoast" ELEMENT elem_inventory_1 TABLE ttuser.inventory MASTER westds ON "westcoast" SUBSCRIBER eastds ON "eastcoast" ELEMENT elem_inventory_2 TABLE ttuser.inventory MASTER eastds ON "eastcoast" SUBSCRIBER westds ON "westcoast" ELEMENT elem_customers_1 TABLE ttuser.customers MASTER westds ON "westcoast" SUBSCRIBER eastds ON "eastcoast" ELEMENT elem_customers_2 TABLE ttuser.customers MASTER eastds ON "eastcoast" SUBSCRIBER westds ON "westcoast";
It is often more convenient to automate the process of writing a replication scheme with scripting. For example, the perl script shown in Example 9-33 can be used to build the scheme shown in Example 9-32.
Example 9-33 Using a Perl script to create a replication scheme
@tables = qw( ttuser.accounts ttuser.sales ttuser.orders ttuser.inventory ttuser.customers ); print "CREATE REPLICATION bigscheme"; foreach $table (@tables) { $element = $table; $element =~ s/repl\./elem\_/; print "\n"; print " ELEMENT $element\_1 TABLE $table\n"; print " MASTER westds ON \"westcoast\"\n"; print " SUBSCRIBER eastds ON \"eastcoast\"\n"; print " ELEMENT $element\_2 TABLE $table\n"; print " MASTER eastds ON \"eastcoast\"\n"; print " SUBSCRIBER westds ON \"westcoast\""; } print ";\n";
The @tables
array shown in Example 9-33 can be obtained from some other source, such as a database. For example, you can use ttIsql
and f
in a Perl statement to generate a @tables
array for all of the tables in the WestDSN
database with the owner name repl
:
@tables = 'ttIsql -e "tables; quit" WestDSN | grep " REPL\."';
Example 9-34 shows a modified version of the script in Example 9-33 that creates a replication scheme for all of the repl
tables in the WestDSN
database. (Note that some substitution may be necessary to remove extra spaces and line feeds from the grep
output.)
Example 9-34 Perl script to create a replication scheme for all tables in WestDSN
@tables = 'ttIsql -e "tables; quit" WestDSN | grep " REPL\."'; print "CREATE REPLICATION bigscheme"; foreach $table (@tables) { $table =~ s/^\s*//; # Remove extra spaces $table =~ s/\n//; # Remove line feeds $element = $table; $element =~ s/repl\./elem\_/; print "\n"; print " ELEMENT $element\_1 TABLE $table\n"; print " MASTER westds ON \"westcoast\"\n"; print " SUBSCRIBER eastds ON \"eastcoast\"\n"; print " ELEMENT $element\_2 TABLE $table\n"; print " MASTER eastds ON \"eastcoast\"\n"; print " SUBSCRIBER westds ON \"westcoast\""; } print ";\n";