Oracle® Streams Replication Administrator's Guide 10g Release 1 (10.1) Part Number B10728-01 |
|
|
View PDF |
This chapter contains conceptual information about Streams replication. This chapter contains these topics:
See Also:
Oracle Streams Concepts and Administration for general information about Oracle Streams. This document assumes that you understand the concepts described in Oracle Streams Concepts and Administration. |
Replication is the process of sharing database objects and data at multiple databases. To maintain replicated database objects and data at multiple databases, a change to one of these database objects at a database is shared with the other databases. In this way, the database objects and data are kept in sync at all of the databases in the replication environment. In a Streams replication environment, the database where a change originates is called the source database, and a database where a change is shared is called a destination database.
When you use Streams, replication of a DML or DDL change typically includes three steps:
Step 1 and Step 3 are required, but Step 2 is optional because, in some cases, an application may enqueue an LCR directly into a queue at a destination database. In addition, in a heterogeneous replication environment in which an Oracle database shares information with a non-Oracle database, an apply process may apply changes directly to a non-Oracle database without propagating LCRs.
Figure 1-1 illustrates the information flow in a Streams replication environment.
Text description of the illustration strep022.gif
This document describes how to use Streams for replication and includes the following information:
Replication is one form of information sharing. Oracle Streams enables replication, and it also enables other forms of information sharing, such as messaging, event management and notification, data warehouse loading, and data protection.
See Also:
Oracle Streams Concepts and Administration for more information about the other information sharing capabilities of Streams |
A rule is a database object that enables a client to perform an action when an event occurs and a condition is satisfied. Rules are evaluated by a rules engine, which is a built-in part of Oracle. You use rules to control the information flow in a Streams replication environment. Each of the following mechanisms is a client of the rules engine:
You control the behavior of each of these Streams clients using rules. A rule set contains a collection of rules, and you can associate a positive and a negative rule set with a Streams client. A Streams client performs an action if an event satisfies its rule sets. In general, a change satisfies the rule sets for a Streams client if no rules in the negative rule set evaluate to TRUE
for the event, and at least one rule in the positive rule set evaluates to TRUE
for the event. If a Streams client is associated with both a positive and negative rule set, then the negative rule set is always evaluated first.
Specifically, you control the information flow in a Streams replication environment in the following ways:
You can use the Oracle-supplied DBMS_STREAMS_ADM
PL/SQL package to create rules for a Streams replication environment. You can specify these system-created rules at the following levels:
TRUE
for changes made to a particular tableTRUE
for changes made to a particular schemaTRUE
for all changes made to a databaseIn addition, a single system-created rule may evaluate to TRUE
for DML changes or for DDL changes, but not both. So, for example, if you want to replicate both DML and DDL changes to a particular table, then you need both a table-level DML rule and a table-level DDL rule for the table.
See Also:
Oracle Streams Concepts and Administration for more information about how rules are used in Streams |
Streams replication supports sharing database objects that are not identical at multiple databases. Different databases in the Streams environment can contain shared database objects with different structures. You can configure rule-based transformations during capture, propagation, or apply to make any necessary changes to LCRs so that they can be applied at a destination database. In Streams replication, a rule-based transformation is any user-defined modification to an LCR that results when a rule in a positive rule set evaluates to TRUE
. A rule-based transformation must be defined as a PL/SQL function that takes a SYS.AnyData
object as input and returns a SYS.AnyData
object.
For example, a table at a source database may have the same data as a table at a destination database, but some of the column names may be different. In this case, a rule-based transformation can change the names of the columns in LCRs from the source database so that they can be applied successfully at the destination database.
Rule-based transformations can be done at any point in the Streams information flow. That is, a capture process may perform a rule-based transformation on a change when a rule in its positive rule set evaluates to TRUE
for the change. Similarly, a propagation or an apply process may perform a rule-based transformation on an LCR when a rule in its positive rule set evaluates to TRUE
for the LCR.
See Also:
Oracle Streams Concepts and Administration for more information about rule-based transformations |
Streams also supports subsetting of table data through the use of subset rules. If a shared table in a database in a Streams replication environment contains only a subset of data, then you can configure Streams to manage changes to a table so that only the appropriate subset of data is shared with the subset table. For example, a particular database may maintain data for employees in a particular department only. In this case, you can use subset rules to share changes to the data for employees in that department with the subset table, but not changes to employees in other departments.
Subsetting can be done at any point in the Streams information flow. That is, a capture process may use a subset rule to capture a subset of changes to a particular table, a propagation may use a subset rule to propagate a subset of changes to a particular table, and an apply process may use a subset rule to apply only a subset of changes to a particular table.
See Also:
Oracle Streams Concepts and Administration for more information subset rules |
To maintain replicated database objects and data, you must capture changes made to these database objects and their data. Next, you must share these changes with the databases in the replication environment. In a Streams replication environment, you can capture changes in either of the following ways:
This section contains a brief overview of the capture process and conceptual information that is important for a capture process in a replication environment.
See Also:
Oracle Streams Concepts and Administration for general conceptual information about a capture process |
Changes made to database objects in an Oracle database are logged in the redo log to guarantee recoverability in the event of user error or media failure. A capture process is an Oracle background process that reads the database redo log to capture DML and DDL changes made to database objects. The source database for a change that was captured by a capture process is always the database where the change was generated in the redo log. A capture process formats these changes into events called LCRs and enqueues them into a queue. Because a running capture process automatically captures changes based on its rules, change capture using a capture process is sometimes called implicit capture.
There are two types of LCRs: a row LCR contains information about a change to a row in a table resulting from a DML operation, and a DDL LCR contains information about a DDL change to a database object. You use rules to specify which changes are captured. A single DML operation may change more than one row in a table. Therefore, a single DML operation may result in more than one row LCR, and a single transaction may consist of multiple DML operations.
Changes are captured by a capture user. The capture user captures all DML changes and DDL changes that satisfy the capture process rule sets.
A capture process may capture changes locally at the source database, or it may capture changes remotely at a downstream database. Figure 1-2 illustrates a local capture process.
Text description of the illustration strep037.gif
Downstream capture means that a capture process runs on a database other than the source database. The archived redo log files from the source database are copied to the downstream database, and the capture process captures changes in these files at the downstream database. You can copy the archived redo log files to the downstream database using log transport services, the DBMS_FILE_TRANSFER
package, file transfer protocol (FTP), or some other mechanism. Figure 1-3 illustrates a downstream capture process.
Text description of the illustration strep012.gif
A local capture process reads the online redo log whenever possible and archived redo log files otherwise. A downstream capture process always reads archived redo log files from the source database.
Note: As illustrated in Figure 1-3, the source database for a change captured by a downstream capture process is the database where the change was recorded in the redo log, not the database running the downstream capture process. |
Supplemental logging places additional column data into a redo log whenever an operation is performed. The capture process captures this additional information and places it in LCRs. Supplemental logging is always configured at a source database, regardless of the location of the capture process that captures changes to the source database.
There are two types of supplemental logging: database supplemental logging and table supplemental logging. Database supplemental logging specifies supplemental logging for an entire database, while table supplemental logging enables you to specify log groups for supplemental logging of a particular table. If you use table supplemental logging, then you can choose between two types of log groups: unconditional log groups and conditional log groups.
Unconditional log groups log the before images of specified columns when the table is changed, regardless of whether the change affected any of the specified columns. Unconditional log groups are sometimes referred to as always log groups. Conditional log groups log the before images of all specified columns only if at least one of the columns in the log group is changed.
Supplementing logging at the database level, unconditional log groups at the table level, and conditional log groups at the table level together determine which old values are logged for a change.
If you plan to use one or more apply processes to apply LCRs captured by a capture process, then you must enable supplemental logging at the source database for the following types of columns in tables at the destination database:
SET_KEY_COLUMNS
procedure in the DBMS_APPLY_ADM
package.dml_condition
parameter in the ADD_SUBSET_RULES
procedure in the DBMS_STREAMS_ADM
package.If you do not use supplemental logging for these types of columns at a source database, then changes involving these columns might not apply properly at a destination database.
Note: LOB, |
See Also:
|
A custom application may capture the changes made to a Oracle database by reading from transaction logs, by using triggers, or by some other method. The application must assemble and order the transactions and must convert each change into an LCR. Next, the application must enqueue the LCRs into a queue in an Oracle database using the DBMS_STREAMS_MESSAGING
package or the DBMS_AQ
package. The application must commit after enqueuing all LCRs in each transaction.
Because the LCRs are constructed and enqueued manually by a user or application, change capture that manually enqueues constructed LCRs is sometimes called explicit capture. If you have a heterogeneous replication environment where you must capture changes at a non-Oracle database and share these changes with an Oracle database, then you can create a custom application to capture changes made to the non-Oracle database.
In a Streams replication environment, propagations propagate captured changes to the appropriate databases so that changes to replicated database objects can be shared. You use SYS.AnyData
queues to stage LCRs, and propagations to propagate these LCRs to the appropriate databases. The following sections describe staging and propagation in a Streams replication environment:
See Also:
Oracle Streams Concepts and Administration for more information about staging and propagation in Streams |
Captured events are staged in a staging area. In Streams, the staging area is a SYS.AnyData
queue that can store row LCRs and DDL LCRs, as well as other types of events. Captured events are staged in a buffered queue, which is System Global Area (SGA) memory associated with a SYS.AnyData
queue that contains only captured events.
Staged LCRs can be propagated by a propagation or applied by an apply process, and a particular staged LCR may be both propagated and applied. A running propagation automatically propagates LCRs based on the rules in its rule sets, and a running apply process automatically applies LCRs based on the rules in its rule sets.
See Also:
Oracle Streams Concepts and Administration for more information about buffered queues |
In a Streams replication environment, a propagation typically propagates LCRs from a queue in the local database to a queue in a remote database. The queue from which the LCRs are propagated is called the source queue, and the queue that receives the LCRs is called the destination queue. There can be a one-to-many, many-to-one, or many-to-many relationship between source and destination queues.
Text description of the illustration strep008.gif
Even after an LCR is propagated by a propagation or applied by an apply process, it may remain in the source queue if you have also configured Streams to propagate the LCR to one or more other queues. Also, notice that a SYS.AnyData
queue may store non-LCR user messages as well as LCRs. Typically, non-LCR user messages are used for messaging applications, not for replication.
You may configure a Streams replication environment to propagate LCRs through one or more intermediate databases before arriving at a destination database. Such a propagation environment is called a directed network. An LCR may or may not be processed by an apply process at an intermediate database. Rules determine which LCRs are propagated to each destination database, and you can specify the route that events will traverse on their way to a destination database.
The advantage of using a directed network is that a source database does not need to have a physical network connection with the destination database. So, if you want LCRs to propagate from one database to another, but there is no direct network connection between the computers running these databases, then you can still propagate the LCRs without reconfiguring your network, as long as one or more intermediate databases connect the source database to the destination database. If you use directed networks, and an intermediate site goes down for an extended period of time or is removed, then you may need to reconfigure the network and the Streams environment.
See Also:
Oracle Streams Concepts and Administration for more information about directed networks |
In a Streams replication environment, changes made to shared database objects are captured and propagated to destination databases where they are applied. You configure one or more apply processes at each destination database to apply these changes. The following sections describe the concepts related to change apply in a Streams replication environment:
See Also:
Oracle Streams Concepts and Administration for more information about change apply with an apply process |
An apply process is an optional Oracle background process that dequeues logical change records (LCRs) and user messages from a specific queue and either applies each one directly or passes it as a parameter to a user-defined procedure. The LCRs dequeued by an apply process contain the results of DML changes or DDL changes that an apply process can apply to database objects in a destination database. A user-defined message dequeued by an apply process is of type SYS.AnyData
and can contain any user message, including a user-created LCR.
Events are applied by an apply user. The apply user applies all row changes resulting from DML operations and all DDL changes. The apply user also runs user-defined apply handlers.
An apply process is a flexible mechanism for processing the events in a queue. You have options to consider when you configure one or more apply processes for your environment. Typically, to accomplish replication in a Streams environment, an apply process applies LCRs, not non-LCR user messages. This section discusses the LCR processing options available to you with an apply process.
A single apply process can apply either captured events or user-enqueued events, but not both. If a queue at a destination database contains both captured and user-enqueued LCRs, then the destination database must have at least two apply processes to process the events. You can use the DBMS_STREAMS_ADM
package or the DBMS_APPLY_ADM
package to create an apply process that applies captured LCRs, but only the CREATE_APPLY
procedure in the DBMS_APPLY_ADM
package can create an apply process that applies user-enqueued LCRs.
Direct apply means that an apply process applies an LCR without running a user procedure. The apply process either successfully applies the change in the LCR to a database object or, if a conflict or an apply error is encountered, tries to resolve the error with a conflict handler or a user-specified procedure called an error handler.
If a conflict handler can resolve the conflict, then it either applies the LCR or it discards the change in the LCR. If an error handler can resolve the error, then it should apply the LCR, if appropriate. An error handler may resolve an error by modifying the LCR before applying it. If the error handler cannot resolve the error, then the apply process places the transaction, and all LCRs associated with the transaction, into the error queue.
Custom apply means that an apply process passes the LCR as a parameter to a user procedure for processing. The user procedure can then process the LCR in a customized way.
A user procedure that processes row LCRs resulting from DML statements is called a DML handler, while a user procedure that processes DDL LCRs resulting from DDL statements is called a DDL handler. An apply process can have many DML handlers but only one DDL handler, which processes all DDL LCRs dequeued by the apply process.
For each table associated with an apply process, you can set a separate DML handler to process each of the following types of operations in row LCRs:
For example, the hr.employees
table may have one DML handler to process INSERT
operations and a different DML handler to process UPDATE
operations.
A user procedure can be used for any customized processing of LCRs. For example, if you want to skip DELETE
operations for the hr.employees
table at a certain destination database, then you can specify a DML handler for DELETE
operations on this table to accomplish this goal. Such a handler is not invoked for INSERT
, UPDATE
, or LOB_UPDATE
operations on the table. Or, if you want to log DDL changes before applying them, then you can create a user procedure that processes DDL operations to accomplish this.
A DML handler should never commit and never roll back, except to a named savepoint that the user procedure has established. To execute DDL inside a DDL handler, invoke the EXECUTE
member procedure for the LCR.
In addition to DML handlers and DDL handlers, you can specify a precommit handler for an apply process. A precommit handler is a PL/SQL procedure that takes the commit SCN from an internal commit directive in the queue used by the apply process. The precommit handler may process the commit information in any customized way. For example, it may record the commit information for an apply process in an audit table.
Attention: Do not modify |
See Also:
|
The following sections discuss considerations for applying DML changes to tables:
You must ensure that the primary key columns at the destination database are logged in the redo log at the source database for every update. A unique or foreign key constraint at a destination database that contains data from more that one column at the source database requires additional logging at the source database.
There are various ways to ensure that a column is logged at the source database. For example, whenever the value of a column is updated, the column is logged. Also, Oracle has a feature called supplemental logging that automates the logging of specified columns.
For a unique key and foreign key constraint at a destination database that contains data from only one column at a source database, no supplemental logging is required. However, for a constraint that contains data from multiple columns at the source database, you must create a conditional supplemental log group containing all the columns at the source database that are used by the constraint at the destination database.
Typically, unique key and foreign key constraints include the same columns at the source database and destination database. However, in some cases, an apply handler or rule-based transformation may combine a multi-column constraint from the source database into a single key column at the destination database. Also, an apply handler or rule-based transformation may separate a single key column from the source database into a multi-column constraint at the destination database. In such cases, the number of columns in the constraint at the source database determines whether a conditional supplemental log group is required. If there is more than one column in the constraint at the source database, then a conditional supplemental log group containing all the constraint columns is required at the source database. If there is only one column in the constraint at the source database, then no supplemental logging is required for the key column.
If possible, each table for which changes are applied by an apply process should have a primary key. When a primary key is not possible, Oracle Corporation recommends that each table have a set of columns that can be used as a unique identifier for each row of the table. If the tables that you plan to use in your Streams environment do not have a primary key or a set of unique columns, then consider altering these tables accordingly.
To detect conflicts and handle errors accurately, Oracle must be able to identify uniquely and match corresponding rows at different databases. By default, Streams uses the primary key of a table to identify rows in the table, and if a primary key does not exist, Streams uses the smallest unique index that has at least one NOT
NULL
column to identify rows in the table. When a table at a destination database does not have a primary key or a unique index with at least one NOT
NULL
column, or when you want to use columns other than the primary key or unique index for the key, you can designate a substitute key at the destination database. A substitute key is a column or set of columns that Oracle can use to identify rows in the table during apply.
You can specify the substitute primary key for a table using the SET_KEY_COLUMNS
procedure in the DBMS_APPLY_ADM
package. Unlike true primary keys, the substitute key columns may contain nulls. Also, the substitute key columns take precedence over any existing primary key or unique indexes for the specified table for all apply processes at the destination database.
If you specify a substitute key for a table in a destination database, and these columns are not a primary key for the same table at the source database, then you must create an unconditional supplemental log group containing the substitute key columns at the source database.
In the absence of substitute key columns, primary key constraints, and unique indexes, an apply process uses all of the columns in the table as the key columns, excluding LOB, LONG
, and LONG
RAW
columns. In this case, you must create an unconditional supplemental log group containing these columns at the source database. Using substitute key columns is preferable when there is no primary key constraint for a table because fewer columns are needed in the row LCR.
See Also:
|
A column discrepancy is any difference in the columns in a table at a source database and the columns in the same table at a destination database. If there are column discrepancies in your Streams environment, then use rule-based transformations or DML handlers to make the columns in row LCRs being applied by an apply process match the columns in the relevant tables at a destination database. The following sections describe apply process behavior for common column discrepancies.
See Also:
|
If the table at the destination database is missing one or more columns that are in the table at the source database, then an apply process raises an error and moves the transaction that caused the error into the error queue. You can avoid such an error by creating a rule-based transformation or DML handler that eliminates the missing columns from the LCRs before they are applied. Specifically, the transformation or handler can remove the extra columns using the DELETE_COLUMN
member procedure on the row LCR.
If the table at the destination database has more columns than the table at the source database, then apply process behavior depends on whether the extra columns are required for dependency computations. If the extra columns are not used for dependency computations, then an apply process applies changes to the destination table. In this case, if column defaults exist for the extra columns at the destination database, then these defaults are used for these columns for all inserts. Otherwise, these inserted columns are NULL
.
If, however, the extra columns are used for dependency computations, then an apply process places the transactions that include these changes in the error queue. The following types of columns are required for dependency computations:
INSERT
and DELETE
statements, all columns involved with constraintsUPDATE
statements, if a constraint column is changed, such as a unique key constraint column or a foreign key constraint column, then all columns involved in the constraintIf the datatype for a column in a table at the destination database does not match the datatype for the same column at the source database, then an apply process places transactions containing the changes to the mismatched column into the error queue. To avoid such an error, you can create a rule-based transformation or DML handler that converts the datatype.
An apply process can apply changes made to an index-organized table only if the index-organized table meets the following conditions:
OVERFLOW
clause.LONG
, LONG
RAW
, CLOB
, NCLOB
, BLOB
, BFILE
, ROWID
, UROWID
, and user-defined types (including object types, REF
s, varrays, and nested tables).If an index-organized table does not satisfy these requirements, then an apply process raises an error if it tries to apply LCRs that contain changes to it.
See Also:
Oracle Streams Concepts and Administration for information about the datatypes supported by an apply process |
Conflicts are possible in a Streams configuration where data is shared between multiple databases. A conflict can occur if DML changes are allowed to a table for which changes are captured and to a table where these changes are applied.
For example, a transaction at the source database may update a row at nearly the same time as a different transaction that updates the same row at a destination database. In this case, if data consistency between the two databases is important, then when the change is propagated to the destination database, an apply process must be instructed either to keep the change at the destination database or replace it with the change from the source database. When data conflicts occur, you need a mechanism to ensure that the conflict is resolved in accordance with your business rules.
Streams automatically detects conflicts and, for update conflicts, tries to use an update conflict handler to resolve them if one is configured. Streams offers a variety of prebuilt handlers that enable you to define a conflict resolution system for your database that resolves conflicts in accordance with your business rules. If you have a unique situation that a prebuilt conflict resolution handler cannot resolve, then you can build and use your own custom conflict resolution handlers in an error handler or DML handler. Conflict detection may be disabled for nonkey columns.
Any of the following handlers may process a row LCR:
The following sections describe the possible scenarios involving these handlers:
You cannot have a DML handler and an error handler simultaneously for the same operation on the same table. Therefore, there is no scenario in which they could both be invoked.
If there are no relevant handlers for a row LCR, then an apply process tries to apply the change specified in the row LCR directly. If the apply process can apply the row LCR, then the change is made to the row in the table. If there is a conflict or an error during apply, then the transaction containing the row LCR is rolled back, and all of the LCRs in the transaction that should be applied according to the apply process rule sets are moved to the error queue.
Consider a case where there is a relevant update conflict handler configured, but no other relevant handlers are configured. An apply process tries to apply the change specified in a row LCR directly. If the apply process can apply the row LCR, then the change is made to the row in the table.
If there is an error during apply that is caused by a condition other than an update conflict, including a uniqueness conflict or a delete conflict, then the transaction containing the row LCR is rolled back, and all of the LCRs in the transaction that should be applied according to the apply process rule sets are moved to the error queue.
If there is an update conflict during apply, then the relevant update conflict handler is invoked. If the update conflict handler resolves the conflict successfully, then the apply process either applies the LCR or discards the LCR, depending on the resolution of the update conflict, and the apply process continues applying the other LCRs in the transaction that should be applied according to the apply process rule sets. If the update conflict handler cannot resolve the conflict, then the transaction containing the row LCR is rolled back, and all of the LCRs in the transaction that should be applied according to the apply process rule sets are moved to the error queue.
Consider a case where an apply process passes a row LCR to a DML handler, and there is no relevant update conflict handler configured.
The DML handler processes the row LCR. The designer of the DML handler has complete control over this processing. Some DML handlers may perform SQL operations or run the EXECUTE
member procedure of the row LCR. If the DML handler runs the EXECUTE
member procedure of the row LCR, then the apply process tries to apply the row LCR. This row LCR may have been modified by the DML handler.
If any SQL operation performed by the DML handler fails, or if an attempt to run the EXECUTE
member procedure fails, then the DML handler can try to handle the exception. If the DML handler does not raise an exception, then the apply process assumes the DML handler has performed the appropriate action with the row LCR, and the apply process continues applying the other LCRs in the transaction that should be applied according to the apply process rule sets.
If the DML handler cannot handle the exception, then the DML handler should raise an exception. In this case, the transaction containing the row LCR is rolled back, and all of the LCRs in the transaction that should be applied according to the apply process rule sets are moved to the error queue.
Consider a case where an apply process passes a row LCR to a DML handler and there is a relevant update conflict handler configured.
The DML handler processes the row LCR. The designer of the DML handler has complete control over this processing. Some DML handlers may perform SQL operations or run the EXECUTE
member procedure of the row LCR. If the DML handler runs the EXECUTE
member procedure of the row LCR, then the apply process tries to apply the row LCR. This row LCR may have been modified by the DML handler.
If any SQL operation performed by the DML handler fails, or if an attempt to run the EXECUTE
member procedure fails for any reason other than an update conflict, then the behavior is the same as that described in "DML Handler But No Relevant Update Conflict Handler". Note that uniqueness conflicts and delete conflicts are not update conflicts.
If an attempt to run the EXECUTE
member procedure fails because of an update conflict, then the behavior depends on the setting of the conflict_resolution
parameter in the EXECUTE
member procedure:
If the conflict_resolution
parameter is set to true
, then the relevant update conflict handler is invoked. If the update conflict handler resolves the conflict successfully, and all other operations performed by the DML handler succeed, then the DML handler finishes without raising an exception, and the apply process continues applying the other LCRs in the transaction that should be applied according to the apply process rule sets.
If the update conflict handler cannot resolve the conflict, then the DML handler can try to handle the exception. If the DML handler does not raise an exception, then the apply process assumes the DML handler has performed the appropriate action with the row LCR, and the apply process continues applying the other LCRs in the transaction that should be applied according to the apply process rule sets. If the DML handler cannot handle the exception, then the DML handler should raise an exception. In this case, the transaction containing the row LCR is rolled back, and all of the LCRs in the transaction that should be applied according to the apply process rule sets are moved to the error queue.
If the conflict_resolution
parameter is set to false
, then the relevant update conflict handler is not invoked. In this case, the behavior is the same as that described in "DML Handler But No Relevant Update Conflict Handler".
Consider a case where an apply process encounters an error when it tries to apply a row LCR. This error may be caused by a conflict or by some other condition. There is an error handler for the table operation but no relevant update conflict handler configured.
The row LCR is passed to the error handler. The error handler processes the row LCR. The designer of the error handler has complete control over this processing. Some error handlers may perform SQL operations or run the EXECUTE
member procedure of the row LCR. If the error handler runs the EXECUTE
member procedure of the row LCR, then the apply process tries to apply the row LCR. This row LCR may have been modified by the error handler.
If any SQL operation performed by the error handler fails, or if an attempt to run the EXECUTE
member procedure fails, then the error handler can try to handle the exception. If the error handler does not raise an exception, then the apply process assumes the error handler has performed the appropriate action with the row LCR, and the apply process continues applying the other LCRs in the transaction that should be applied according to the apply process rule sets.
If the error handler cannot handle the exception, then the error handler should raise an exception. In this case, the transaction containing the row LCR is rolled back, and all of the LCRs in the transaction that should be applied according to the apply process rule sets are moved to the error queue.
Consider a case where an apply process encounters an error when it tries to apply a row LCR. There is an error handler for the table operation, and there is a relevant update conflict handler configured.
The handler that is invoked to handle the error depends on the type of error it is:
If the update conflict handler cannot resolve the conflict, then the error handler is invoked. If the error handler does not raise an exception, then the apply process assumes the error handler has performed the appropriate action with the row LCR, and the apply process continues applying the other LCRs in the transaction that should be applied according to the apply process rule sets. If the error handler cannot process the LCR, then the error handler should raise an exception. In this case, the transaction containing the row LCR is rolled back, and all of the LCRs in the transaction that should be applied according to the apply process rule sets are moved to the error queue.
See Also:
|
The following sections discuss considerations for applying DDL changes to tables:
The following types of DDL changes are not supported by an apply process. These types of DDL changes are not applied:
ALTER
MATERIALIZED
VIEW
ALTER
MATERIALIZED
VIEW
LOG
CREATE
DATABASE
LINK
CREATE
SCHEMA
AUTHORIZATION
CREATE
MATERIALIZED
VIEW
CREATE
MATERIALIZED
VIEW
LOG
DROP
DATABASE
LINK
DROP
MATERIALIZED
VIEW
DROP
MATERIALIZED
VIEW
LOG
RENAME
If an apply process receives a DDL LCR that specifies an operation that cannot be applied, then the apply process ignores the DDL LCR and records the following message in the apply process trace file, followed by the DDL text that was ignored:
Apply process ignored the following DDL:
An apply process applies all other types of DDL changes if the DDL LCRs containing the changes should be applied according to the apply process rule sets. Also, an apply process can apply valid, user-enqueued DDL LCRs.
See Also:
Oracle Streams Concepts and Administration for more information about how rules are used in Streams |
For captured DDL changes to be applied properly at a destination database, either the destination database must have the same database structures as the source database, or the non-identical database structural information must not be specified in the DDL statement. Database structures include data files, tablespaces, rollback segments, and other physical and logical structures that support database objects.
For example, for captured DDL changes to tables to be applied properly at a destination database, the following conditions must be met:
CREATE
TABLE
statement at the source database and destination database.However, if the tablespaces and rollback segments are not specified in the DDL statement, then the default tablespaces and rollback segments are used. In this case, the tablespaces and rollback segments can differ at the source database and destination database.
For a DDL LCR to be applied at a destination database successfully, the user specified as the current_schema
in the DDL LCR must exist at the destination database. The current schema is the schema that is used if no schema is specified for an object in the DDL text.
See Also:
|
If you plan to capture DDL changes at a source database and apply these DDL changes at a destination database, then avoid using system-generated names. If a DDL statement results in a system-generated name for an object, then the name of the object typically will be different at the source database and each destination database applying the DDL change from this source database. Different names for objects can result in apply errors for future DDL changes.
For example, suppose the following DDL statement is run at a source database:
CREATE TABLE sys_gen_name (n1 NUMBER NOT NULL);
This statement results in a NOT
NULL
constraint with a system-generated name. For example, the NOT
NULL
constraint may be named sys_001500
. When this change is applied at a destination database, the system-generated name for this constraint may be sys_c1000
.
Suppose the following DDL statement is run at the source database:
ALTER TABLE sys_gen_name DROP CONSTRAINT sys_001500;
This DDL statement succeeds at the source database, but it fails at the destination database and results in an apply error.
To avoid such an error, explicitly name all objects resulting from DDL statements. For example, to name a NOT
NULL
constraint explicitly, run the following DDL statement:
CREATE TABLE sys_gen_name (n1 NUMBER CONSTRAINT sys_gen_name_nn NOT NULL);
When applying a change resulting from a CREATE
TABLE
AS
SELECT
statement, an apply process performs two steps:
CREATE
TABLE
AS
SELECT
statement is executed at the destination database, but it creates only the structure of the table. It does not insert any rows into the table. If the CREATE
TABLE
AS
SELECT
statement fails, then an apply process error results. Otherwise, the statement auto commits, and the apply process performs Step 2.CREATE
TABLE
AS
SELECT
statement into the corresponding table at the destination database. It is possible that a capture process, a propagation, or an apply process will discard all of the row LCRs with these inserts based on their rule sets. In this case, the table remains empty at the destination database.
See Also:
Oracle Streams Concepts and Administration for more information about how rules are used in Streams |
In a Streams environment that shares information within a single database or between multiple databases, a source database is the database where changes are generated in the redo log. Suppose an environment has the following characteristics:
In such an environment, for the each table, only changes that committed after a specific system change number (SCN) at the source database are applied. An instantiation SCN specifies this value for each table.
An instantiation SCN may be set during instantiation, or an instantiation SCN may be set using a procedure in the DBMS_APPLY_ADM
package. If the tables do not exist at the destination database before the Streams replication environment is configured, then these table are physically created (instantiated) using copies from the source database, and the instantiation SCN is set for each table during instantiation. If the tables already exist at the destination database before the Streams replication environment is configured, then these table are not instantiated using copies from the source database. Instead, the instantiation SCN must be set manually for each table using one of the following procedures in the DBMS_APPLY_ADM
package: SET_TABLE_INSTANTIATION_SCN
, SET_SCHEMA_INSTANATIATION_SCN
, or SET_GLOBAL_INSTANTIATION_SCN
.
The instantiation SCN for a database object controls which LCRs that contain changes to the database object are ignored by an apply process and which LCRs are applied by an apply process. If the commit SCN of an LCR for a database object from a source database is less than or equal to the instantiation SCN for that database object at a destination database, then the apply process at the destination database discards the LCR. Otherwise, the apply process applies the LCR.
Also, if there are multiple source databases for a shared database object at a destination database, then an instantiation SCN must be set for each source database, and the instantiation SCN may be different for each source database. You can set instantiation SCNs by using export/import or transportable tablespaces. You also can set an instantiation SCN by using a procedure in the DBMS_APPLY_ADM
package.
Streams also records the ignore SCN for each database object. The ignore SCN is the SCN below which changes to the database object cannot be applied. The instantiation SCN for an object cannot be set lower than the ignore SCN for the object. This value corresponds to the SCN value at the source database at the time when the object was prepared for instantiation. An ignore SCN is set for a database object only when the database object is instantiated using Export/Import.
You can view the instantiation SCN and ignore SCN for database objects by querying the DBA_APPLY_INSTANTIATED_OBJECTS
data dictionary view.
If an apply process is running, then the oldest SCN is the first SCN of the transactions currently being dequeued and applied. For a stopped apply process, the oldest SCN is the first SCN of the transactions that were being applied when the apply process was stopped.
The following are two common scenarios in which the oldest SCN is important:
In both cases, you should determine the oldest SCN for the apply process by querying the DBA_APPLY_PROGRESS
data dictionary view. The OLDEST_MESSAGE_NUMBER
column in this view contains the oldest SCN. Next, set the start SCN for the capture process that is capturing changes for the apply process to the same value as the oldest SCN value. If the capture process is capturing changes for other apply processes, then these other apply processes may receive duplicate LCRs when you reset the start SCN for the capture process. In this case, the other apply processes automatically discard the duplicate LCRs.
See Also:
|
The low-watermark for an apply process is the system change number (SCN) up to which all events have been applied. That is, events that were committed at an SCN less than or equal to the low-watermark number have definitely been applied, but some events that were committed with a higher SCN also may have been applied. The low-watermark SCN for an apply process is equivalent to the applied SCN for a capture process.
The high-watermark for an apply process is the SCN beyond which no events have been applied. That is, no events that were committed with an SCN greater than the high-watermark have been applied.
You can view the low-watermark and high-watermark for one or more apply processes by querying the V$STREAMS_APPLY_COORDINATOR and
ALL_APPLY_PROGRESS data dictionary views.
You can control a DML or DDL trigger's firing property using the SET_TRIGGER_FIRING_PROPERTY
procedure in the DBMS_DDL
package. This procedure lets you specify whether a trigger's firing property is set to fire once.
If a trigger's firing property is set to fire once, then it does not fire in the following cases:
EXECUTE_ERROR
or EXECUTE_ALL_ERRORS
procedure in the DBMS_APPLY_ADM
packageIf a trigger is not set to fire once, then it fires in both of these cases.
By default, DML and DDL triggers are set to fire once. You can check a trigger's firing property by using the IS_TRIGGER_FIRE_ONCE
function in the DBMS_DDL
package.
For example, in the hr
schema, the update_job_history
trigger adds a row to the job_history
table when data is updated in the job_id
or department_id
column in the employees
table. Suppose, in a Streams environment, the following configuration exists:
dbs1.net
database.dbs2.net
database.dbs2.net
database.update_job_history
trigger exists in the hr
schema in both databases.If the update_job_history
trigger is not set to fire once at dbs2.net
in this scenario, then these actions result:
job_id
column is updated for an employee in the employees
table at dbs1.net
.update_job_history
trigger fires at dbs1.net
and adds a row to the job_history
table that records the change.dbs1.net
captures the changes to both the employees
table and the job_history
table.dbs2.net
database.dbs2.net
database applies both changes.update_job_history
trigger fires at dbs2.net
when the apply process updates the employees
table.In this case, the change to the employees
table is recorded twice at the dbs2.net
database: when the apply process applies the change to the job_history
table and when the update_job_history
trigger fires to record the change made to the employees
table by the apply process.
As you can see, the database administrator may not want the update_job_history
trigger to fire at the dbs2.net
database when a change is made by the apply process. Similarly, a database administrator may not want a trigger to fire because of the execution of an apply error transaction. If the update_job_history
trigger's firing property is set to fire once, then it does not fire at dbs2.net
when the apply process applies a change to the employees
table, and it does not fire when an executed error transaction updates the employees
table.
Also, if you use the ON
SCHEMA
clause to create a schema trigger, then the schema trigger fires only if the schema performs a relevant change. Therefore, when an apply process is applying changes, a schema trigger that is set to fire always fires only if the apply user is the same as the schema specified in the schema trigger. If the schema trigger is set to fire once, then it never fires when an apply process applies changes, regardless of whether the apply user is the same as the schema specified in the schema trigger.
For example, if you specify a schema trigger that always fires on the hr
schema at a source database and destination database, but the apply user at a destination database is strmadmin
, then the trigger fires when the hr
user performs a relevant change on the source database, but the trigger does not fire when this change is applied at the destination database. However, if you specify a schema trigger that always fires on the strmadmin
schema at the destination database, then this trigger fires whenever a relevant change is made by the apply process, regardless of any trigger specifications at the source database.
See Also:
PL/SQL Packages and Types Reference for more information about setting a trigger's firing property with the |