Book Image

Oracle 11g Streams Implementer's Guide

Book Image

Oracle 11g Streams Implementer's Guide

Overview of this book

From smaller businesses through to huge enterprises ñ users all over the world often require access to data 24 hours a day. Distributed database systems proliferate the world of data sharing providing an ability to access real-time data anywhere, anytime. Oracle Streams, a built-in feature of the Oracle database, is a data replication and integration feature critical to the success and wellbeing of enterprises in today's fast moving economy. This book provides the reader with solid techniques to master Oracle Streams technology and successfully deploy distributed database systems. This book quickly goes over the basics and gets you up and running with a simple Oracle 11g Streams environment. It will serve as an excellent companion to the Oracle Streams Administration Guide. It is intended for Oracle database architects and administrators, and provides in-depth discussion on must-know information for the design, implementation, and maintenance of an Oracle Streams environment. The book does not attempt to regurgitate all the information in the Oracle Streams Administration Guides, but rather provides additional clarification and explanation of design, implementation, and troubleshooting concepts that are often elusive in Streams documentation. It also identifies helpful tools and Oracle resources to add to your knowledge base, as well as tried and tested tricks and tips to help you tame Oracle Streams. The book starts by introducing and explaining the components of Oracle Streams and how they work together. It then moves on logically, helping you to determine your distributed environment requirements and design your Streams implementation to meet those requirements. Once these concepts are discussed, the book moves to configuration and basic implementation examples to help solidify those concepts. It then addresses advanced features such as tags, down-stream capture, and conflict resolution. You then move on to maintenance techniques such as documenting the environment, effectively planning and implementing changes to the environment, and monitoring and troubleshooting the environment. When you have studied the techniques and completed the hands-on examples, you will have an understanding of Oracle Streams' core concepts and functionally that will allow you to successfully design, implement, and maintain an Oracle Streamed environment.
Table of Contents (14 chapters)
Oracle 11g Streams Implementer's Guide
Credits
About the Authors
About the Reviewers
Preface

SCN Coordination keeps it flowing smoothly


All of the Streams processes use SCNs to keep track of what change transactions they have processed and they share this information to coordinate who gets what, who still needs what, and what can be ignored (because it has already processed). This is why coordinating the Instigation SCN at the start is so important.

Capture and Apply object instantiation are not the only components of Streams that rely on SCN synchronization. The Capture process must also coordinate it's SCNs with the LogMiner process and available archived logs to ensure data integrity over time. This is done via FIRST_SCN, START_SCN and REQUIRED_CHECKPOINT_SCN.

The Capture process relies on a valid LogMiner Data Dictionary to access database object structure for redo capture to build LCRs. This LogMiner Data Dictionary is separate from the Database Data Dictionary, but is a "picture" of the Database Data Dictionary at the time the Capture process is created. Each Capture process either builds a new LogMiner Data Dictionary or accesses an existing one when it first starts. To build a LogMiner Data Dictionary, the Capture process must have access to the "picture" of the Database Data Dictionary from the redo logs at the time of the SCN from which it must first start capturing. This picture of the Database Data Dictionary is created in the redo logs by running the DBMS_CAPTURE_ADM.BUILD procedure. This procedure must be one at least once in the database before a Capture process can be created. The BUILD creates a picture of the Database Data Dictionary in the current redo log and records an entry in the V$ARCHVIED_LOG view indicating that the redo log contains a Data Dictionary information (DICTIONARY_BEGIN='YES') as of the SCN (FIRST_CHANGE#) at the time of the BUILD. The FIRST_SCN of the Capture process must correspond to a FIRST_CHANGE# for a BUILD. For the Capture process to start for the first time, the redo log for that FIRST_CHANGE# must be available to the database instance. The BUILD procedure can be run multiple times, and different Capture processes can use any one of these builds when it is created by specifying one of the FIRST_CHANGE# values for a build for the Capture process FIRST_SCN parameter (as long as the necessary redo logs are available to the instance). The Capture process will access the redo log containing the Dictionary information, and build its LogMiner Data Dictionary if needed. You can find eligible FIRST_SCN values by querying V$ARCHIVED_LOGS for FIRST_CHANGE# values generated by a build.

select distinct NAME, FIRST_CHANGE# from V$ARCHIVED_LOG where DICTIONARY_BEGIN = 'YES';

The NAME column has the name of the redo log(s) in which the BUILD resides. All redo logs from this redo log forward, must be available for the Capture process to first start.

If you specify a FIRST_SCN for a new Capture process from a BUILD for which another Capture process has already built a LogMiner Data Dictionary, the new Capture process will use the existing LogMiner Data Dictionary.

If you do not specify a FIRST_SCN (default is NULL) when creating a Capture process, the creation will call DBMS_CAPTURE_ADM.BUILD procedure, and set the FIRST_SCN for the Capture process to the FIRST_CHANGE# generated by the build. If you create a Capture process using one of the procedures in the DBMS_STREAMS_ADM package, the FIRST_SCN parameter is automatically set to NULL, forcing the capture creation to do a BUILD.

The SCNs of Capture

The following synopsizes the SCNs of a Capture process; how they are used, and rules of usage.

FIRST_SCN

  • The lowest SCN at which the Capture process can begin capturing

  • Must correspond to a FIRST_CHANGE# value in V$ARCHVIED_LOG for a Data Dictionary BUILD in the redo logs

  • Points the Capture process to the redo log(s) that hold the Data Dictionary information from which to build its LogMiner Data Dictionary if necessary, and begin scanning redo for changes on the Capture process first startup

  • If REQUIRED_CHECKPOINT_SCN is 0, the Capture process will begin scanning at FIRST_SCN on subsequent capture startups

  • It can be changed by the following:

    • Manually using DBMS_CAPTURE_ADM.ALTER_CAPTURE

    • Automatically by CHECKPOINT_RETENTION_TIME purge process

  • Change can only be to a value greater than the current FIRST_SCN value

  • FIRST_SCN cannot be greater than REQUIRED_CHECKPOINT_SCN when REQUIRED_CHECKPIONT_SCN is greater than 0

START_SCN

  • The SCN at which the Capture process will actually begin capturing changes on startup

  • START_SCN must be greater than or equal to FIRST_SCN

  • If a Capture process's FIRST_SCN is changed (either manually or via CHECKPOINT_RETENTION_TIME purge process) to a value greater than its START_SCN, the START_SCN is automatically increased to the new FIRST_SCN value

  • START_SCN can be changed manually using DBMS_CAPTURE_ADM.ALTER_CAPTURE

  • START_SCN can be set to a value lower than its current value, as long as the new value is not less than the FIRST_SCN value for the Capture process

  • START_SCN is usually only manually changed if a point-in-time recovery has been performed at a destination site, and the point-in-time recovered to requires changes to be resent to the destination site

Note

If the point-in-time recovery requires an SCN before the Capture process FIRST_SCN, that process cannot be used to send changes to the recovered site. If a Data Dictionary BUILD is available in the archived logs with a FIRST_CHANGE# less than or equal to the SCN required for the point-in-time recovery, a new Capture process can be created specifying the appropriate FIRST_CHANGE# for the FIRST_SCN. Otherwise, the Streamed objects must be re-instantiated from the source at the destination.

REQUIRED_CHECKPOINT_SCN

  • Set to 0 (zero, zed) when the Capture process is created

  • Incremented by the Capture process LogMiner checkpoint process

  • Value determined by the lowest APPLIED_SCN for all destination sites for the Capture process queue

  • The lowest SCN that the Capture process must be able to access from the redo logs to be able to restart

  • The redo log that includes this SCN and all subsequent redo logs must be available to the Capture process database instance, for the Capture process to successfully start

  • If value > 0 (zero, zed), the Capture process starts scanning from this SCN when restarted

  • The REQUIRED_CHECKPOINT_SCN is only changed when a checkpoint is completed. This happens either by:

    • Automated by LogMiner Checkpoint process

    • Manually via command

      DBMS_CAPTURE_ADM.SET_PARAMETER('<capture_name>', '_checkpoint_force','Y')
      

CAPTURED_SCN

The most recent SCN scanned by the Capture process.

APPLIED_SCN

  • The most recent SCN dequeued and processed by any Apply process that receives changes from the Capture processes queue

  • Corresponds with the low-watermark SCN for an Apply process

MAXIMUM_SCN

  • The SCN at which a Capture process must stop capturing changes and disable

  • The Capture process will disable when it reaches this upper limit SCN

  • Changes with and SCN greater than or equal to the MAXIMUM_SCN are not captured by the Capture process

  • If the value is infinite (default), the Capture process captures changes without upper limit

LAST_ENQUEUED_SCN

  • This is the last SCN enqueued by the Capture process

  • This value is dynamic and will increase as the Capture process captures and enqueues LCR

  • Can be used to gauge latency of Propagation and Apply

SOURCE_RESETLOGS_SCN

The SCN at the last RESETLOGS action.

MAX_CHECKPOINT_SCN

The SCN at which the latest checkpoint was taken.

Note

For more detailed information on how FIRST_SCN, START_SCN and REQUIRED_CHECKPOINT_SCN are used by the Capture process, please refer to the The LogMiner Data Dictionary for a Capture Process, Capture Process Checkpoints, and Multiple Capture Processes for the Same Source Database sections in Chapter 2: Oracle Streams Information Capture of the Oracle Streams Concepts and Administration guide 11g.

The SCNs of Propagation

A Propagation process really only tracks one SCN value. This is the ACKED_SCN which is the SCN sent to the Propagation process from the destination for which the Apply process has acknowledged by all Apply queue subscribers as successful dequeued and processed. This means the dequeued LCR was either successfully applied or successfully committed to the Apply error queue. This value is used by the Capture checkpoint to help determine its REQUIRED_CHECKPOINT_SCN.

The SCNs of Apply

The following synopsizes the SCN's of an Apply process; how they are used, and rules of usage.

IGNORE_SCN

  • The SCN below which changes received should not be applied

  • Only set when instantiation is accomplished via Export/Import

  • Corresponds with the SCN set at the source database when the object was prepared for instantiation

  • The instantiation SCN must be equal to or greater than this SCN

MAXIMUM_SCN

  • The SCN at which an Apply process must stop applying changes and disable

  • The Apply process will disable when it reaches this upper limit SCN

  • Changes with and SNC greater than or equal to the MAXIMUM_SCN are not applied by the Apply process

  • If the value is infinite (default), the Apply process applies changes without upper limit

OLDEST_SCN_NUM

  • This is the latest SCN of a received LCR that was successfully dequeued and applied

  • In the case where a point-in-time recovery is performed on the destination, this value should be used to reset the START_SCN for the associated Capture process at the source site to recapture changes

  • Does not pertain to synchronously captured changes received

Low-watermark SCN

  • The lowest SCN that can be guaranteed dequeued and applied by an Apply process

  • Corresponds to the APPLIED_SCN of the Capture process

There are a myriad other SCNs that have used the Apply process internally. The SCNs listed above are the ones you gain the most for understanding. You can find detailed information on Apply SCN and transaction tracking in the Oracle Streams Replication Administrators' Guide.

SCN SYNC-hronization

As you can see, if your SCNs are out of sync between the LogMiner Dictionary, Capture, and Apply processes your Streams may not work as expected; or even not at all. Obeying the following formula when implementing your Streams environment will keep you out of SCN SYNC-hole.

Note

Apply SCN >= OI SCN >= CP START_SCN >= CP FIRST_SCN

Where OI = Object Instantiation and CP = Capture

Once you have implemented Streams, avoid changes to SCNs unless it is necessary to compensate for a destination site point-in-time recovery or an unrecoverable archive log.

Capture checkpointing

The Capture process keeps track of the lowest SCN that has been recorded by its Propagation processes as greatest SCN that has been acknowledged by its Apply destination as being applied. The Capture process cannot set its REQUIRED_CHECKPIONT_SCN great than this SCN or there is a potential for data loss. This is controlled by checkpointing.

The Capture process will conduct checkpoints in which it coordinates its SCNs. By default these checkpoints happen with the capture of 10 MB of redo and the checkpoint metadata is retained in the database for 60 days. You can also force a checkpoint if the need arises. These checkpointing options are all controlled by the following capture parameters:

  • _CHECKPOINT_FREQUENCY: The number of megabytes captured which will trigger a checkpoint. Default value is 10 but can be changed with DBMS_CAPTURE_ADM.SET_PARAMETER().

  • CHECKPOINT_RETENTION_TIME: Number of days to retain checkpoint metadata. Default 60 but can be changed with DBMS_CAPTURE_ADM.ALTER_CAPTURE() procedure.

  • _CHECKPOINT_FORCE: This will force a Capture checkpoint. Accomplished via DBMS_CAPTURE_ADM.SET_PARAMETER, pass in Y for the value. It will set itself back to N when the checkpoint is complete.

You can determine the current values for these parameters by querying the DBA_CAPTURE_PARAMETERS view.

The following lists captures views that contain helpful information concerning your Capture processes:

  • DBA/ALL_CAPTURE

  • DBA/ALL_CAPTURE_PARAMETERS

  • DBA/ALL_CAPTURE_EXTRA_ATTRIBUTES

  • V$STREAMS_CAPTURE

  • V$STREAMS_TRANSACTION

  • DBA/ALL_STREAMS_RULES

Archive Log availability

When a Capture process starts up, it will check its REQUIRED_CHECKPOINT_SCN (if it's 0, it will use the FIRST_SCN) and look for the redo log that contains that SCN and begin scanning at the redo log forward. If the SCN is in an archived log that is no longer available; or if any subsequent redo logs (archived or online) from that SCN forward are no longer available, the Capture process will not start. You can overcome this by either of the following:

  • Restoring the required archive logs

  • Dropping and recreating the Capture process

This leads to the obvious question of "what happens when my archive logs are in my flash_recovery_area and are aged out?" The obvious answer here is, "It will break your Capture process if/when the archive log containing your Capture FIRST_SCN/REQUIRED_CHECKPOINT_SCN is aged out". This would be why Oracle documentation specifically and highly recommends that you do not use the flash_recovery_area as your only archive log repository if you are using Streams. If you use the flash_recovery_area, configure a separate archive log destination to accommodate the archive redo logs needed by Streams. Now, if you really want to only have archive logs in the flash_recovery_area, take pity on the on-call DBA and make sure that your Capture process checkpoint_retention_time intervals are set within the archive log retention period of the flash_recovery_area.

  • The following views can be used to help determine what archived redo logs are required by the Capture process and which can be purged:V$ARCHVIED_LOG

  • DBA_REGISTERED_ARCHIVED_LOG

  • DBA_LOGMNR_PURGED_LOG

Note

For more detailed information on flash_recovery_area and Streams, please refer to Are Required Redo Log Files Missing? section of Chapter 20 of the Oracle Streams Concepts and Administration guide.