Skip Headers

Oracle9i Streams
Release 2 (9.2)

Part Number A96571-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to next page

4
Streams Apply Process

This chapter explains the concepts and architecture of the Streams apply process.

This chapter contains these topics:

Apply Process Overview

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 data manipulation language (DML) changes or data definition language (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.


Note:

An apply process can be associated only with a SYS.AnyData queue, not with a typed queue.


Apply Rules

An apply process applies changes based on rules that you define. Each rule specifies the database objects to which an apply process applies changes and the types of changes to apply. You can specify apply rules at the following levels:

For non-LCR events, you can create your own rules to control apply process behavior.

See Also:

Event Processing with an Apply Process

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. This section discusses the types of events that an apply process can apply and the ways that it can apply them.

Captured and User-Enqueued Events

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 events, then the destination database must have at least two apply processes to process the events.

When you create an apply process using a procedure in the DBMS_STREAMS_ADM package, the apply_captured parameter is set to true by default. Therefore, the apply process applies only captured events.

When you create an apply process using the CREATE_APPLY procedure in the DBMS_APPLY_ADM package, you use the apply_captured parameter to specify whether the apply process applies captured or user-enqueued events. By default, the apply_captured parameter is set to false for an apply process created with this procedure.

See Also:

Event Processing Options

Your options for event processing depend on whether or not the event received by an apply process is an LCR event. Figure 4-1 shows the event processing options for an apply process.

Figure 4-1 The Apply Process

Text description of strms013.gif follows
Text description of the illustration strms013.gif


LCR Event Processing

Each apply process can apply captured events from only one source database, because processing the LCRs in these events requires knowledge of the dependencies, meaningful transaction ordering, and transactional boundaries at the source database. Captured LCRs from multiple databases may be sent to a single destination queue. However, if a single queue contains captured LCRs from multiple databases, then there must be multiple apply processes retrieving these LCRs. Each of these apply processes should be configured to receive captured LCRs from exactly one source database using rules. If an event is a user-enqueued event containing LCRs (not a captured event), then an apply process can apply these user-enqueued events, even if they are from multiple source databases.

Also, each apply process can apply captured events from only one capture process. If there are multiple capture processes running on a source database, and LCRs from more than one of these capture processes are applied at a destination database, then there must be one apply process to apply changes from each capture process. In such an environment, Oracle Corporation recommends that each Streams queue used by a capture process or apply process have captured events from at most one capture process from a particular source database. A queue can contain LCRs from more than one capture process if each capture process is capturing changes at a different source database.

You can configure an apply process to process a captured or user-enqueued event that contains an LCR in the following ways: directly apply the LCR event or pass the LCR event as a parameter to a user procedure for processing. The following sections explain these options.

Apply the LCR Event Directly

If you use this option, then an apply process applies the LCR event 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 the 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.

Call a User Procedure to Process the LCR Event

If you use this option, then an apply process passes the LCR event as a parameter to a user procedure for processing. The user procedure can then process the LCR event 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 each insert into a particular table at the source database to result in inserts into multiple tables at the destination database, then you can create a user procedure that processes INSERT operations on the table to accomplish this. 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.

To associate a DML handler with an apply process, use the SET_DML_HANDLER procedure in the DBMS_APPLY_ADM package. To set a DDL handler, use the ddl_handler parameter in the CREATE_APPLY or the ALTER_APPLY procedure in the DBMS_APPLY_ADM package.

See Also:

Non-LCR User Message Processing

A user-enqueued event that does not contain an LCR is always processed by the message handler specified for an apply process. A message handler is a user-defined procedure that can process non-LCR user messages in a customized way for your environment.

The message handler offers advantages in any environment that has applications that need to update one or more remote databases or perform some other remote action. These applications can enqueue user messages into a queue at the local database, and Streams can propagate each user message to the appropriate queues at destination databases. If there are multiple destinations, then Streams provides the infrastructure for automatic propagation and processing of these messages at these destinations. If there is only one destination, then Streams still provides a layer between the application at the source database and the application at the destination database, so that, if the application at the remote database becomes unavailable, then the application at the source database can continue to function normally.

For example, a message handler may format a user message into an electronic mail message. In this case, the user message may contain the attributes you would expect in an electronic mail message, such as from, to, subject, text_of_message, and so on. A message handler could convert these user messages into electronic mail messages and send them out through an electronic mail gateway.

You can specify a message handler for an apply process using the message_handler parameter in the CREATE_APPLY or the ALTER_APPLY procedure in the DBMS_APPLY_ADM package. A Streams apply process always assumes that a non-LCR message has no dependencies on any other events in the queue. Therefore, if dependencies exist between these messages in your environment, then Oracle Corporation recommends that you set apply process parallelism to 1.

Summary of Event Processing Options

Table 4-1 summarizes the event processing options available when you are using one or more of the event handlers described in the previous sections. Event handlers are optional for row LCRs and DDL LCRs because an apply process can apply these events directly. However, a message handler is required for processing non-LCR user messages.

Table 4-1 Summary of Event Processing Options
Type of Event Default Apply Process Behavior User Procedure Scope of User Procedure

Row LCR

Execute DML

DML Handler

One operation on one table

DDL LCR

Execute DDL

DDL Handler

Entire apply process

Non-LCR User Message

Create error transaction (if no message handler exists)

Message Handler

Entire apply process


Note:
  • Apply handlers can execute an LCR by calling the LCR's EXECUTE member procedure.
  • All applied DDL LCRs commit automatically. Therefore, if a DDL handler calls the EXECUTE member procedure of a DDL LCR, then a commit is performed automatically.
  • If necessary, an apply handler can set a Streams session tag.

See Also:

Datatypes Applied

When applying row LCRs for data manipulation language (DML) changes to tables, an apply process applies changes made to columns of the following datatypes:

The apply process does not apply DML changes in columns of the following datatypes: NCLOB, LONG, LONG RAW, BFILE, ROWID, and UROWID, and user-defined type (including object types, REFs, varrays, and nested tables). The apply process raises an error if it attempts to apply a row LCR that contains information about a column of an unsupported datatype. Then, the apply process moves the transaction that includes the LCR into the error queue.

See Also:

Considerations for Applying DML Changes to Tables

The following sections discuss considerations for applying DML changes to tables:

Key Columns

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. Unique and foreign key columns at the destination database must be logged in the redo log at the source database only if a column in a multicolumn constraint is updated.

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 single-column unique key and foreign key constraints, no supplemental logging is required. However, for multicolumn constraints, you must create a conditional supplemental log group containing all the constraint columns at the source database.

See Also:

"Supplemental Logging"

Substitute Key Columns

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. When a table at a destination database does not have a primary key, or when you want to use columns other than the primary key 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 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.


Note:
  • Oracle Corporation recommends that each column you specify as a substitute key column be a NOT NULL column. You should also create a single index that includes all of the columns in a substitute key. Following these guidelines improves performance for updates, deletes, and piecewise updates to LOBs because the database can locate the relevant row more efficiently.
  • You should not permit applications to update the primary key or substitute key columns of a table. This ensures that the database can identify rows and preserve the integrity of the data.

See Also:

Row Subsetting

You can use the ADD_SUBSET_RULES procedure in the DBMS_STREAMS_ADM package to maintain a subset of the rows in a particular table. To do this, you specify a condition similar to the condition in the WHERE clause of a SELECT statement in the dml_condition parameter for this procedure. For a particular table, only one subset rule is allowed for a particular apply process.

See Also:

"Table and Subset Rules"

Row Migration

When you use subset rules, a captured update operation may be converted to an insert or delete operation when it is applied by an apply process. This automatic conversion is called row migration and is performed by an internal LCR transformation specified in a rule's action context.

For example, suppose you use a subset rule to specify that an apply process applies changes only to the hr.employees table when the employee's department_id is 50 with the following condition: department_id = 50. If a source database captures a change to an employee that changes the employee's department_id from 80 to 50, then the apply process with the subset rule applies this change by converting the update operation into an insert operation. This conversion is needed because the employee's row does not exist in the destination table. Similarly, if a captured update changes an employee's department_id from 50 to 20, then an apply process with this subset rule converts the update operation into a delete operation.

If an apply process may perform row migration when applying changes to a table and you allow local changes to the table, then the apply process cannot ensure that all rows in the table meet the subset condition. For example, suppose the condition is department_id = 50 for the hr.employees table. If a user or an application inserts a row for an employee whose department_id is 30, then this row remains in the table and is not removed by the apply process. Similarly, if a user or an application updates a row locally and changes the department_id to 30, then this row also remains in the table.

To avoid such errors, Oracle Corporation recommends that you ensure that all DML performed on a subset table satisfy the subset condition.

Supplemental Logging and Row Subsetting

If you specify a subset rule for a table at a destination database, then an unconditional supplemental log group must be specified at the source database for all of the columns in the table at the destination database and all the columns in the subset condition. In certain cases, when a subset rule is specified, an update may be converted to an insert by an apply process, and in these cases supplemental information may be needed for some or all of the columns.

For example, if you specify a subset rule at database dbs2.net on the postal_code column in the hr.locations table, and the source database for changes to this table is dbs1.net, then use supplemental logging at dbs1.net for all of the columns in the hr.locations table at dbs2.net, as well as the postal_code column, even if this column does not exist in the table at the destination database.

See Also:

"Supplemental Logging"

Apply Process Behavior for Column Discrepancies

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:

Missing Columns at the Destination Database

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.

Extra Columns at the Destination Database

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:

Column Datatype Mismatch

If 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.

Conflict Resolution

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 a conflict resolution 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 handlers cannot resolve, then you can build and use your own custom conflict resolution handlers in an error handler or DML handler.

See Also:

Chapter 7, "Streams Conflict Resolution"

Handlers and Row LCR Processing

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.

No Relevant Handlers

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 satisfy the apply process rule set are moved to the error queue.

Relevant Update Conflict Handler

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 satisfy the apply process rule set 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 satisfy the apply process rule set. 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 satisfy the apply process rule set are moved to the error queue.

DML Handler But No Relevant Update Conflict Handler

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 satisfy the apply process rule set.

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 satisfy the apply process rule set are moved to the error queue.

DML Handler And a Relevant Update Conflict Handler

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:

The conflict_resolution Parameter Is Set To true

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 satisfy the apply process rule set.

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 satisfy the apply process rule set. 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 satisfy the apply process rule set are moved to the error queue.

The conflict_resolution Parameter Is Set To false

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".

Error 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 satisfy the apply process rule set.

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 satisfy the apply process rule set are moved to the error queue.

Error Handler And a Relevant Update Conflict Handler

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:

Considerations for Applying DDL Changes

The following sections discuss considerations for applying DDL changes to tables:

Types of DDL Changes Ignored by an Apply Process

The following types of DDL changes are not supported by an apply process. These types of DDL changes are not applied:

Also, the following types of CREATE TABLE and ALTER TABLE statements are ignored by an apply process:

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 ignored:

Apply process ignored the following DDL:

An apply process applies all other types of DDL changes if the DDL LCRs containing the changes satisfy the rules in the apply process rule set.


Note:
  • An apply process applies ALTER object_type object_name RENAME changes, such as ALTER TABLE jobs RENAME. Therefore, if you want DDL changes that rename objects to be applied, then use ALTER object_type object_name RENAME statements instead of RENAME statements.
  • The name "materialized view" is synonymous with the name "snapshot". Snapshot equivalents of the statements on materialized views are ignored by an apply process.
  • An apply process only applies captured DDL LCRs. It ignores user-enqueued DDL LCRs.

Database Structures

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:

Current Schema User Must Exist at 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.

See Also:

System-Generated Names

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);

CREATE TABLE AS SELECT Statements

When applying a change resulting from a CREATE TABLE AS SELECT statement, an apply process performs two steps:

  1. The 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 autocommits, and the apply process performs Step 2.
  2. The apply process inserts the rows that were inserted at the source database as a result of the CREATE TABLE AS SELECT statement into the corresponding table at the destination database. It is possible that a capture process, a propagation job, 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.


    Note:

    A CREATE TABLE AS SELECT statement on a clustered table is not supported in a Streams environment.


Trigger Firing Property

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:

If 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:

If the update_job_history trigger is not set to fire once at dbs2.net in this scenario, then these actions result:

  1. The job_id column is updated for an employee in the employees table at dbs1.net.
  2. The update_job_history trigger fires at dbs1.net and adds a row to the job_history table that records the change.
  3. The capture process at dbs1.net captures the changes to both the employees table and the job_history table.
  4. A propagation job propagates these changes to the dbs2.net database.
  5. An apply process at the dbs2.net database applies both changes.
  6. The 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.


Note:

Only DML and DDL triggers can be set to fire once. All other types of triggers always fire.


See Also:

Oracle9i Supplied PL/SQL Packages and Types Reference for more information about setting a trigger's firing property with the SET_TRIGGER_FIRING_PROPERTY procedure

The Oldest SCN for an Apply Process

If an apply process is running, then the oldest SCN is the earliest SCN of the transactions currently being applied. For a stopped apply process, the oldest SCN is the earliest 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. Then, 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 LCR events when you reset the start SCN for the capture process. In this case, the other apply processes automatically discard the duplicate LCR events.

See Also:

"The Start SCN for a Capture Process"

Streams Apply Process and Oracle Real Application Clusters

You can configure a Streams apply process to apply changes in a Real Application Clusters environment. If you use an apply process to apply captured LCRs in a Real Application Clusters environment, then any call to the START_APPLY procedure in the DBMS_APPLY_ADM package must be run on owner instance of the queue that is used by the apply process.

Calls to other procedures and functions that operate on an apply process can be performed from any instance. Also, an apply process that applies user-enqueued events can start in any instance.

If the owner instance for a queue table containing a queue used by an apply process becomes unavailable, then queue ownership is transferred automatically to another instance in the cluster. If this happens, then, to restart the apply process, connect to the owner instance for the queue and run the START_APPLY procedure. The DBA_QUEUE_TABLES data dictionary view contains information about the owner instance for a queue table. The apply process maintains a persistent start/stop state in a Real Application Clusters environment only if the owner instance for its queue does not change before the database instance owning the queue is restarted.

Also, in a Real Application Clusters environment, an apply coordinator process, its corresponding apply reader server, and all of its apply server processes use run on a single instance.

See Also:

Apply Process Architecture

You can create, alter, start, stop, and drop an apply process, and you can define apply rules that control which events an apply process dequeues from the queue. The user who creates an apply process is, by default, the user who applies changes. This user must have the necessary privileges to apply changes.

See Also:

"Setting Up Users and Creating Queues and Database Links" for information about the required privileges. In the example in this section, the privileges are granted to the strmadmin user.

This section discusses the following topics:

Apply Process Components

An apply process consists of the following components:

If a transaction being handled by an apply server has a dependency with another transaction that is not known to have been applied, then the apply server contacts the coordinator and waits for instructions. The coordinator monitors all of the apply servers to ensure that transactions are applied and committed in the correct order.

For example, consider these two transactions:

  1. A row is inserted into a table.
  2. The same row is updated to change certain column values.

In this case, transaction 2 is dependent on transaction 1, because the row cannot be updated until after it is inserted into the table. Suppose these transactions are captured from the redo log at a source database, propagated to a destination database, and applied at the destination database. Apply server A handles the insert transaction, and apply server B handles the update transaction.

If apply server B is ready to apply the update transaction before apply server A has applied the insert transaction, then apply server B waits for instructions from the coordinator. After apply server A has applied the insert transaction, the coordinator process instructs apply server B to apply the update transaction.

Apply Process Creation

You can create an apply process using the DBMS_STREAMS_ADM package or the DBMS_APPLY_ADM package. Using the DBMS_STREAMS_ADM package to create an apply process is simpler because defaults are used automatically for some configuration options. In addition, when you use the DBMS_STREAMS_ADM package, a rule set is created for the apply process and rules are added to the rule set automatically. The DBMS_STREAMS_ADM package was designed for use in replication environments. Alternatively, using the DBMS_APPLY_ADM package to create an apply process is more flexible, and you create a rule set and rules for the apply process either before or after it is created.

An apply process created by the procedures in the DBMS_STREAMS_ADM package can apply events only at the local database and can apply only captured events. To create an apply process that applies events at a remote database or an apply process that applies user-enqueued events, use the CREATE_APPLY procedure in the DBMS_APPLY_ADM package.

Changes applied by an apply process created by the DBMS_STREAMS_ADM package generate tags in the redo log at the destination database with a value of 00 (double zero), but you can set the tag value if you use the CREATE_APPLY procedure. Alternatively, you can set the tag using the ALTER_APPLY procedure in the DBMS_APPLY_ADM package.

When you create an apply process by running the CREATE_APPLY procedure in the DBMS_APPLY_ADM package, you can specify nondefault values for the apply_captured, apply_database_link, and apply_tag parameters. Then you can use the procedures in the DBMS_STREAMS_ADM package or the DBMS_RULE_ADM package to add rules to the rule set for the apply process.

If you create more than one apply process in a database, then the apply processes are completely independent of each other. These apply processes do not synchronize with each other, even if they apply LCRs from the same source database.

See Also:

Oracle9i Supplied PL/SQL Packages and Types Reference for more information about the following procedures, which can be used to create an apply process.

Streams Data Dictionary for an Apply Process

When a capture process is created, a duplicate data dictionary called the Streams data dictionary is populated automatically. The Streams data dictionary is a multiversioned copy of some of the information in the primary data dictionary at a source database. The Streams data dictionary maps object numbers, object version information, and internal column numbers from the source database into table names, column names, and column datatypes when a capture process evaluates rules and creates LCRs. This mapping keeps each captured event as small as possible because a captured event can often use numbers rather than names internally.

Unless a captured event is passed as a parameter to a user transformation during capture or propagation, the mapping information in the Streams data dictionary at the source database is needed to interpret the contents of the LCR at any database that applies the captured events. To make this mapping information available to an apply process, Oracle automatically populates a multiversioned Streams data dictionary at each destination database that has a Streams apply process. Oracle automatically propagates relevant information from the Streams data dictionary at the source database to all other databases that apply captured events from the source database.

See Also:

"Data Dictionary Duplication During Capture Process Creation"

Apply Process Parameters

After creation, an apply process is disabled so that you can set the apply process parameters for your environment before starting the process for the first time. Apply process parameters control the way an apply process operates. For example, the time_limit apply process parameter can be used to specify the amount of time an apply process runs before it is shut down automatically. After you set the apply process parameters, you can start the apply process.

See Also:

Apply Process Parallelism

The parallelism apply process parameter specifies the number of apply servers that may concurrently apply transactions. For example, if parallelism is set to 5, then an apply process uses a total of five apply servers. In addition, the reader server is a parallel execution server. So, if parallelism is set to 5, then an apply process uses a total of six parallel execution servers, assuming six parallel execution servers are available in the database. An apply process always uses one or more parallel execution servers.


Note:
  • Resetting the parallelism parameter automatically stops and restarts the apply process when the currently executing transactions are applied, which may take some time depending on the size of the transactions.
  • Setting the parallelism parameter to a number higher than the number of available parallel execution servers may disable the apply process. Make sure the PROCESSES and PARALLEL_MAX_SERVERS initialization parameters are set appropriately when you set the parallelism apply process parameter.

See Also:

Commit Serialization

Apply servers may apply transactions at the destination database in an order that is different from the commit order at the source database. Only nondependent transactions can be applied in a different order from the commit order at the source database. Dependent transactions are always applied at the destination database in the same order as they were committed at the source database.

You control whether the apply servers can apply nondependent transactions in a different order at the destination database than the source database using the commit_serialization apply parameter. This parameter has the following settings:

If you specify none, then it is possible that a destination database may contain commit changes in a different order from the source database. For example, suppose two nondependent transactions are committed at the source database in the following order:

  1. Transaction A
  2. Transaction B

At the destination database, these transactions may be committed in the opposite order:

  1. Transaction B
  2. Transaction A

Automatic Restart of an Apply Process

You can configure an apply process to stop automatically when it reaches certain predefined limits. The time_limit apply process parameter specifies the amount of time an apply process runs, and the transaction_limit apply process parameter specifies the number of transactions an apply process can apply. The apply process stops automatically when it reaches these limits.

The disable_on_limit parameter controls whether an apply process becomes disabled or restarts when it reaches a limit. If you set the disable_on_limit parameter to y, then the apply process is disabled when it reaches a limit and does not restart until you restart it explicitly. If, however, you set the disable_on_limit parameter to n, then the apply process stops and restarts automatically when it reaches a limit.

When an apply process is restarted, it gets a new session identifier, and the parallel execution servers associated with the apply process also get new session identifiers. However, the coordinator process number (apnn) remains the same.

Stop or Continue on Error

Using the disable_on_error apply process parameter, you can either instruct an apply process to become disabled when it encounters an error, or you can allow the apply process to continue applying transactions after it encounters an error.

See Also:

"The Error Queue"

The Persistent State of an Apply Process

An apply process maintains a persistent state. That is, an apply process maintains its current state when the database is shut down and restarted. For example, if an apply process is running when the database is shut down, then the apply process automatically starts when the database is restarted, but, if an apply process is stopped when a database is shut down, then the apply process remains stopped when the database is restarted.

The Error Queue

The error queue stores information about transactions that could not be applied successfully at the local destination site. A transaction may include many events, and when an unhandled error occurs during apply, the apply process automatically copies all of the events in the transaction that satisfy the apply process rule set to the error queue. The error queue contains information only about errors encountered at the local destination database. It does not contain information about errors at other databases in a Streams environment.

You can correct the condition that caused an error and then reexecute the error transaction. For example, you might modify a row in a table to correct the condition that caused an error. When the condition that caused the error has been corrected, you can either reexecute the transaction in the error queue using the EXECUTE_ERROR and EXECUTE_ALL_ERRORS procedures or delete the transaction from the error queue using the DELETE_ERROR and DELETE_ALL_ERRORS procedures. Both of these procedures are in the DBMS_APPLY_ADM package.

When you reexecute a transaction in the error queue, you can specify that the transaction be executed either by the user who originally placed the error in the error queue or by the user who is reexecuting the transaction. Also, the current Streams tag for the apply process is used when you reexecute a transaction in the error queue.

A reexecuted transaction uses any relevant apply handlers and conflict resolution handlers. If, to resolve the error, the LCR inside the error queue needs to be modified before it is executed, then you can configure a DML handler to process the LCR that caused the error in the error queue. In this case, the DML handler may modify the LCR in some way to avoid a repeat of the same error. The LCR is passed to the DML handler when you reexecute the error containing the LCR using the EXECUTE_ERROR or EXECUTE_ALL_ERRORS procedure in the DBMS_APPLY_ADM package.

An error queue is created automatically when you create a Streams queue, and each Streams queue has its own error queue. To view information about transactions in the error queue, query the DBA_APPLY_ERROR data dictionary view.

See Also:

Go to previous page Go to next page
Oracle
Copyright © 2002 Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback