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

Instantiation


We mention instantiation as part of this chapter to stress its importance. Instantiation refers to the creation of the replicated object at target databases, based on the source object. It also provides Streams with the information needed to determine what transactions to apply at the destination site(s). You can think of it as an agreement (starting point) that needs to be established between the source and destination before any Streaming can be accomplished. The main purpose of instantiation is to prepare the object structure and data at the destination site to receive changes from the source.

Instantiation is a process composed of three steps:

  • Creating the object(s) at the destination Site

  • Updating the Streams data dictionary with metadata

  • Setting the Instantiation SCN for the object(s)

The database objects, which are either tables or other objects, need to exist on both the source and destination site. Table structures between a source and destination database can differ if there is a transformation or subsetting involved, though often the tables will have the same data and the same structure. If there is data that needs to be replicated in the table(s) then the data should be the same at the source and destination sites at the time of instantiation, unless there is some sort of transformation, subsetting, or other apply or error handler put in place to compensate for the data differences. This becomes apparent when an update or delete DML fails due to data NOT being at the destination site(s) or having different values in the replicated columns.

Once instantiation is complete, the instantiation SCN will be the same at both the source and destination site(s), indicating to Streams that it is from this SCN forward that changes should be captured, propagated, and applied for the destination. The following image demonstrates this concept as it shows the instantiated Inventory Table with the same instantiation SCN at both the Source and Destination site.

Instantiation Levels and Methods can be accomplished at different levels depending on your requirements. These instantiation levels include:

Instantiation Levels

Table Level

Schema Level

Database (Global) Level

Tablespace (this requires special steps)

Instantiation Methods

Data Pump

Transportable Tablespaces

RMAN for entire database

Manual method

The possible combinations of Instantiation Levels that can be used with Instantiation Methods can become confusing. So, with a handful of different methods to instantiate tables; How does one decide which method to use? In general, you can use Data Pump to instantiate all (or some) of the tables at Schema Level. You can also decide to move all tables to a particular tablespace and use transportable tablespaces. For now, we will focus on two methods that we use most often due to its ease of use and flexibility.

Using Data Pump to instantiate tables and schemas is fairly straightforward. The Data Pump export utility EXPDP will use Oracle Flashback to ensure that the export is consistent and at the same time capture the instantiation data. For greater control use the FLASHBACK_SCN or FLASHBACK_TIME parameters. On the import side, use the DataPump import utility IMPDP. If it is a full database import, use the parameter STREAMS_CONFIGURATION=y (the default value) to direct IMPDP to include any Streams related metadata that may be contained in the export.

Note

STREAMS_CONFIGURATION is only relevant for FULL database imports via IMPDP. All the other functionality of Data Pump can also be used. So using Data Pump to export/import the entire database, schema, or specific tables can be accomplished with ease, and is the recommended method of export/import based instantiation as of Oracle 11g.

If the replicated structures and data are the same on both sites, we recommend that you use DataPump Export/Import to instantiate (this can be done via DBMS_STREAMS_ADM.MAINTAIN_* scripts).

If the replicated structures are the same, but the data different between sites, we recommend instantiating objects via DataPump with CONTENT=METADATA_ONLY, and manual calls to necessary DBMS_STREAMS_ADM.ADD_RULE and DBMS_CAPTURE_ADM subprograms.

Note

CONTENT=METADATA_ONLY is not supported with TRANSPORTABLE TABLESPACE mode. Make sure to include handling expected data differences between sites in your Capture and/or Apply processes as necessary (see Chapter 6 for more information on data transformation and conflict resolution techniques that can be useful).

If the replicated structures and data are different between sites, we recommend that you create and populate the objects at each site manually, then call the necessary DBMS_STREAMS_ADM.ADD_RULE and DBMS_CAPTURE_ADM subprograms manually. Make sure to configure transformation rules for the structural differences, and handlers for the data differences. One important thing to remember is that if Capture, Propagation and Apply processes and rules are added, or modified, you will need to re-instantiate the SCN between the source and destination. You can do this by following the manual method.

What sets the instantiation SCN and when?

Any of the DBMS_STREAMS_ADM.MAINTAIN_*_SCRIPTS subprograms will automatically set both the Source and Target instantiation SCNs.

The DataPump or Transportable Tablespace instantiation methods will automatically set the Source and Target instantiation SCNs.

Creating the Capture process via DBMS_STREAMS_ADM.ADD_RULE will automatically set the Source instantiation SCN only. You will need to manually set the Target instantiation SCN using the DBMS_APPLY_ADM.SET_*_INSTANTIATION_SCN (covered in the next section).

Creating the Capture process via DBMS_CAPTURE_ADM.CREATE_CAPTURE will not set any instantiation SCNs. You must manually set the instantiation at both the Source and Target sites.

Setting the instantiation SCN manually using the DBMS_CAPTURE_ADM.PREPARE_*_INSTANTIATION and DBMS_APPLY_ADM SET_*_INSTANTIATION_SCN for the proper instantiation level is simple.

The DBMS_CAPTURE_ADM contains the following packages used to prepare the objects for instantiation at the source:

  • PREPARE_TABLE_INSTANTIATION

  • PREPARE_SCHEMA_INSTANTIATION

  • PREPARE_GLOBAL_INSTANTIATION

The DBMS_APPLY_ADM contains the following packages used to instantiate the object at the destination:

  • SET_TABLE_INSTANTIATION_SCN

  • SET_SCHEMA_INSTANTIATION_SCN

  • SET_GLOBAL_INSTANTIATION_SCN

The steps for setting the instantiation SCN are as follows:

  • Call the appropriate DBMS_CAPTURE_ADM. PREPARE_*_INSTANTIATION package at the source database

  • Determine the current SCN at the source database using DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER

  • Call the appropriate DBMS_APPLY_ADM SET_*_INSTANTIATION_SCN at the destination database, specifying the SCN value returned in step 2

To state the obvious, you want to make sure that you use the same level for setting the instantiation at the destination that you used to prepare instantiation at the source. Code examples for setting the Instantiation SCN manually are provided in Chapter 3, Prepare the Rafts and Secure Your Gear: The pre-work before configuring Oracle 11g Streams.

The following views can help you determine what instantiation levels have been prepared at the source database:

  • DBA/ALL_CAPTURE_PREPARED_TABLES

  • DBA/ALL_CAPTURE_PREPARED_SCHEMAS

  • DBA/ALL_CAPTURE_PREPARED_DATABASE