30
Fastrack to federated replication Skill Level: Introductory Kence Anderson ([email protected]) Information Developer IBM 11 May 2005 This tutorial shows you how to replicate data from a table in a DB2 database to a table in an Oracle database. Section 1. Before you start About this tutorial This tutorial shows you how to replicate data over WebSphere® MQ queues from a table in a DB2® Universal Database® (UDB) database to a table in an Oracle TM database on Windows®. Replication over WebSphere MQ queues is called Q replication. This tutorial is for people who are interested in learning about federated Q replication from a DB2 UDB source table to an Oracle target table. You should be familiar with relational database concepts, SQL, Oracle databases and DB2 UDB. About the graphics in this tutorial The overview panels of some sections provide graphics that describe the objects or programs that you will manipulate in that section. All the objects that you have created appear on each diagram, but the objects that you create in that section will be highlighted. The final graphic shows your complete federated replication setup. DB2 UDB objects are highlighted in green, WebSphere objects are highlighted in purple, and Oracle objects are highlighted in red. Fastrack to federated replication © Copyright IBM Corporation 1994, 2008. All rights reserved. Page 1 of 30

Fastrack to federated replication - IBM the Oracle SQLPlus command interface by running the sqlplus command from a Windows command prompt. Figure 1. Oracle sqlplus command line interface

Embed Size (px)

Citation preview

Fastrack to federated replicationSkill Level: Introductory

Kence Anderson ([email protected])Information DeveloperIBM

11 May 2005

This tutorial shows you how to replicate data from a table in a DB2 database to a tablein an Oracle database.

Section 1. Before you start

About this tutorial

This tutorial shows you how to replicate data over WebSphere® MQ queues from atable in a DB2® Universal Database® (UDB) database to a table in an OracleTM

database on Windows®. Replication over WebSphere MQ queues is called Qreplication.

This tutorial is for people who are interested in learning about federated Q replicationfrom a DB2 UDB source table to an Oracle target table. You should be familiar withrelational database concepts, SQL, Oracle databases and DB2 UDB.

About the graphics in this tutorial

The overview panels of some sections provide graphics that describe the objects orprograms that you will manipulate in that section. All the objects that you havecreated appear on each diagram, but the objects that you create in that section willbe highlighted. The final graphic shows your complete federated replication setup.DB2 UDB objects are highlighted in green, WebSphere objects are highlighted inpurple, and Oracle objects are highlighted in red.

Fastrack to federated replication© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 1 of 30

Overview of the products in this tutorial

Product Description

DB2 Universal Database (UDB) DB2 UDB manages the source database and thedatabase that connects to Oracle 10g

Oracle 10g Database Oracle 10g manages the database that containsthe target table where you replicate your data to.

WebSphere Information Integrator (II) WebSphere II facilitates communication betweenDB2 UDB and Oracle 10g.

WebSphere MQ WebSphere MQ transports data between DB2UDB databases during replication.

Prerequisites

Install the following software on your system if it is not already installed.

1. Oracle 10g

a. Create an Oracle Technology Network account. You need thisaccount to download Oracle 10g from the site.

b. Download the Oracle 10g database.

c. Clear the contents of the PERL5LIB environment variable.

d. Use the Oracle Universal Installer to install Oracle 10g and tocreate a general starter database. Use the default (orcl) as theglobal database name. See the Oracle Database Quick InstallationGuide 10g Release 1 (10.1.0.2.0) for Windows if you need morehelp installing Oracle 10g.

e. When the Oracle Universal Installer prompts you to create apassword, type oraclepassword.

2. DB2 Universal Database (UDB) Version 8.2

3. WebSphere Information Integrator Replication Edition Version 8.2You need the Oracle relational wrapper to complete this tutorial. Install allof the relational wrappers or you can install only the Oracle wrapper.There is no trial version available for WebSphere II.

developerWorks® ibm.com/developerWorks

Fastrack to federated replicationPage 2 of 30 © Copyright IBM Corporation 1994, 2008. All rights reserved.

4. DB2 UDB Version 8.2 Fix Pack 9

5. WebSphere MQ Version 5.3Download a trial version of WebSphere MQ version 5.3.

Section 2. Create the replication source and target

Overview of source and target objects

When you replicate data from a DB2 UDB source table to an Oracle target table, thesource table resides in a DB2 UDB database and the Oracle target table resides inan Oracle database. You use a DB2 UDB federated database to communicate withthe Oracle database.

Objects that you create in this section:

• Source database (SAMPLE)

• Source table (employee)

• Federated server (FEDERATED)

ibm.com/developerWorks developerWorks®

Fastrack to federated replication© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 3 of 30

Create the source database, source table and thefederateddatabase

The source for replication data in this tutorial is the DB2 UDB sample database. Allreplicated data originates from the employee table. The employee table is the sourcetable and resides in the sample database. Data replicates from the source database(SAMPLE) to a DB2 UDB federated database (FEDERATED). The federateddatabase is an intermediate stop for replicated data between the source database(DB2 UDB) and the target database (Oracle). The federated databasecommunicates with the Oracle target database.

1. Create the DB2 UDB sample database by running the db2samplcommand from a DB2 command line.

Tip: Enter the db2cmd command from a Windows command prompt

to open a DB2 command line window.

2. Create the federated database in DB2 UDB using the Control Center.

developerWorks® ibm.com/developerWorks

Fastrack to federated replicationPage 4 of 30 © Copyright IBM Corporation 1994, 2008. All rights reserved.

Tip: Run the db2cc command from a Windows command prompt to

open the Control Center.

a. Right-click All Databases in the object tree and select CreateDatabase > Standard. The Create Database wizard opens.

b. On the Name page of the Create Database wizard, typeFEDERATED in the Database name field.

c. Click Finish.

d. Click No on the DB2 message window that appears. The messagerecommends that you run the Configuration Advisor on the newdatabase that you created. The Configuration Advisor helps youset database parameters for features that you do not need for thistutorial.

Create a user ID for replication on the Oracle database (orcl)

Before you can set up the infrastructure that connects the DB2 UDB databaseFEDERATED to the Oracle 10g database orcl, you need to create a user ID forreplication. You specify this Oracle user ID and password when you set upWebSphere Information Integrator, which will connect the federated server(FEDERATED) to the Oracle database (orcl). Create a user ID named tutorial_userwith a password oraclepassword.

1. Open the Oracle SQLPlus command interface by running the sqlpluscommand from a Windows command prompt.

Figure 1. Oracle sqlplus command line interface

ibm.com/developerWorks developerWorks®

Fastrack to federated replication© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 5 of 30

2. Log on to Oracle:

a. Type sysman as the user name.

b. Type oraclepassword as the password.Be careful as you type your password; the cursor will not move.This might make it difficult to track the characters that you haveentered.

3. Run the following command to create the user ID:

create user tutorial_user identified by oraclepassword;

4. Run the following command to grant the proper privileges to thetutorial_user user ID:

grant all privileges to tutorial_user;

You need to grant all privileges to the tutorial_user user ID so that theOracle database (orcl) will allow WebSphere Information Integrator to usethis username to connect to the Oracle target table.

Section 3. Connect DB2 UDB to Oracle

Overview of federated objects

WebSphere Information Integrator provides the infrastructure that connects the DB2UDB database to the Oracle 10g database. The Oracle wrapper enablescommunication between DB2 UDB and Oracle. The server definition coordinatesconnections between the federated database (FEDERATED) and the Oracle 10gdatabase (orcl). The user mapping coordinates authorizations for both databases.

Objects that you create in this section:

developerWorks® ibm.com/developerWorks

Fastrack to federated replicationPage 6 of 30 © Copyright IBM Corporation 1994, 2008. All rights reserved.

• Oracle wrapper

• Server definition

• User mapping

Configure the DB2 UDB instance as a federated server

In this step, you configure your DB2 UDB instance to allow databases inside thatinstance to act as federated servers. A federated server is a database that enablescommunication with a non-DB2 database through a wrapper, server definition, usermapping, and nickname.

1. Expand the DB2 UDB Control Center object tree to Instances > DB2 foryour system.

2. Right-click in the object tree on DB2 and select Configure Parameters.

3. In the DBM Configuration window, scroll down to the Environment groupand select Federated.

ibm.com/developerWorks developerWorks®

Fastrack to federated replication© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 7 of 30

4. Click the value listed in the Value column for the Federated keyword.Click the push button that appears next to the value. Select Yes. In

the Change DBM Configuration Parameters window select Yes.

5. Click OK to save your changes and close the Change DBM ConfigurationParameters window.

6. Click OK to save your changes and close the DBM Configuration window.The federated function is enabled for your database.

7. Stop and restart the DB2 instance. Expand the DB2 UDB Control Centerobject tree to Instances > DB2. Right-click DB2 and select Stop.Right-click on DB2 again and select Start.

Create the Oracle wrapper and server definition

In this step you create a wrapper and server definition that enables communicationbetween your federated database (FEDERATED) and your Oracle target database(orcl). Use the Create Federated Objects wizard. To start the wizard, right-click theFederated Database Objects folder under FEDERATED in the object tree, andclick Create Federated Objects.

1. Create the Oracle wrapper.

a. On the Introduction page, click Next.

b. On the Wrappers page, use the pull-down menu for the DataSource Type field and select Oracle using OCL 8. Click Next.

c. On the Wrappers page, click Create (Wrappers section), to createthe wrapper that will access the Oracle data source. Click Next.The Create Wrapper notebook opens.

d. Click the Wrapper tab on the Create Wrapper notebook.

e. On the Wrapper page of the Create Wrapper notebook, type thewrapper name: oracle_wrapper in the Wrapper name field.

f. Click OK to create the oracle wrapper.The Action Output window shows that the wrapper was created(registered) successfully. The Set Environment Variables window

developerWorks® ibm.com/developerWorks

Fastrack to federated replicationPage 8 of 30 © Copyright IBM Corporation 1994, 2008. All rights reserved.

opens.

Tip: If the Set Environment Variables window does not open,

right-click the name of the wrapper that you created and selectAlter. The wrapper name appears in the Control Center object treeunder Federated Objects. Click Set Variables on the AlterWrapper notebook to open the Set Environment Variables window.

g. Type C:\oracle\product\10.1.0\db_1 in the Value field ofthe Set Environment Variables window and click OK to specify yourOracle home directory.

h. Accept the defaults on the Settings page and click OK.The Create Federated Objects wizard continues so that you cancreate a server definition.

2. Create the server definition.

a. On the Server Definitions page of the wizard, click Create.

b. In the Create Server Definitions window, click Add. The CreateServer Definition notebook opens.

c. On the Server Definition page of the notebook:

• Enter oracle_server in the Name field.

• Select 10g in the Version list.

d. Click the Settings tab.

e. On the Settings page, type orcl in the Value field next to theNODE variable. Click OK to save your save your changes andclose the notebook.

f. Click OK to save your changes and close the Create ServerDefinitions window.

g. Click Next in the wizard.The wizard continues, to help you create a user mapping, which iscovered on the next panel.

ibm.com/developerWorks developerWorks®

Fastrack to federated replication© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 9 of 30

Tip: You can find the node name in the tsnames.ora file. The Oracle

Universal Installer creates sample versions of the tsnames.ora file, but thedatabase configuration creates the complete version of this file that you should use.The node name appears in the tsnames.ora file above the Definition header. Yournode name should be orcl.

Create a user mapping

The user mapping matches the user ID and password for the federated database(FEDERATED) with the user ID and password for the Oracle database (orcl).Continue following the Create Federated Objects wizard from the previous step tocreate a user mapping.

1. On the User Mappings page, click Create.

2. On the Users page of the Create User Mappings notebook, select yourWindows user ID from the list of Available local user IDs. Click

to add the user ID to the list of Selected user IDs.

Figure 2. The Users page of the Create User Mappings notebook

developerWorks® ibm.com/developerWorks

Fastrack to federated replicationPage 10 of 30 © Copyright IBM Corporation 1994, 2008. All rights reserved.

3. Select your Windows user ID from the list of Selected user IDs, and clickOK.

4. On the Settings page, type tutorial_user in the Value field next toREMOTE_AUTHID and type oraclepassword in the Value field next toREMOTE_PASSWORD.

5. Click OK.

6. Select the user mapping that you created and click Next.

7. Click Cancel. The Replication Center will create the nickname later whenyou create replication objects.

Note: You cancel the wizard because you do not need the wizard to

create a nickname for you, but you have already created the wrapper,server definition, and user mapping.

Test the connection between the federated database and theOracle targetdatabase

Next, you test the connection between the DB2 UDB federated database(FEDERATED) and the Oracle target database (orcl) by using a pass-throughsession. A pass-through session connects DB2 UDB with Oracle and allows you toissue Oracle sqlplus commands from a DB2 UDB command window as if you wereusing sqlplus directly in the Oracle database.

1. Start the oracle database:

a. Open a browser window and type http://localhost:5500/em(5500 is the manager port number that the Oracle UniversalInstaller defined when you installed Oracle 10g). The OracleEnterprise Manager tool opens.

b. Log in using the user ID sysman and the passwordoraclepassword.

c. If the database is not running, start the database.

2. Start and connect to the DB2 UDB FEDERATED database. Run the

ibm.com/developerWorks developerWorks®

Fastrack to federated replication© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 11 of 30

following commands from a DB2 command line tool:

db2startdb2 connect to federated

3. Use a pass-through session to test your connection. Run the followingcommands from a DB2 command line tool:

db2 set passthru oracle_serverdb2 select count(*) from sys.all_tables

4. A count that represents the number of tables in your orcl database shouldappear. If your count returns, your federated database (FEDERATED)connected successfully to your target database (orcl).If the database does not return a count, check the pass-throughcommands that you entered for errors. Then check your user mapping tomake sure that you entered your Oracle user id (tutorial_user) andpassword (oraclepassword) correctly. If you received an Oracle error,consult the Oracle 10g documentation to fix the error.

5. After the database successfully returns the count, run the followingcommand to end the pass-through session:

db2 set passthru reset

Section 4. Set up the infrastructure for replication

Overview of WebSphere MQ objects

WebSphere MQ provides the infrastructure that data will move across between theDB2 UDB databases during replication. Queue managers act as the brain of themessaging system, queues store the data messages, channels transmit messagesbetween queue managers, and listeners monitor channels for incoming messages.

Objects that you create in this section:

developerWorks® ibm.com/developerWorks

Fastrack to federated replicationPage 12 of 30 © Copyright IBM Corporation 1994, 2008. All rights reserved.

• Queue managers

• Queues

• Channels

• Listeners

Create your WebSphere MQ objects and start your queuemanagers

You will use two prepared WebSphere MQ scripts to create your queues andchannels. First you modify the script with information that is specific to yourcomputer, then you run the scripts from a Windows command prompt.

1. Download the following scripts and save them in the c:\ directory of yourcomputer:

• uni_source.mqs

• uni_target.mqs

ibm.com/developerWorks developerWorks®

Fastrack to federated replication© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 13 of 30

2. Open the services file that is located in theC:\WINDOWS\system32\drivers\etc directory with a text editor.Search the file for 1450 and 1451 to see if the ports 1450 and 1451 areallocated. If the ports are not found, they are available and you can skip tostep 3. If ports 1450 and 1451 exist in the file and are allocated, you canuse any two unused ports for this tutorial. If you choose two availableports other than 1450 and 1451, replace ports 1450 and 1451 with theports that you chose for the remainder of this tutorial.

3. Make the following modifications to the uni_source.mqs script:

a. Replace ip address of source (port) with the IP address of yourcomputer.

Tip: You can find the IP address of your computer by running

the ipconfig command from a Windows command prompt.

b. Type 1450 as the port number.

c. Save and close the file.

4. Make the following modifications to the uni_target.mqs script.

a. Replace ip address of target (port) with IP address of yourcomputer.

b. Type 1451 as the port number.

c. Save and close the file.

5. Create a queue manager named QM1 and a queue manager named QM2by running the following commands from a Windows command prompt:

crtmqm QM1crtmqm QM2

6. Start the queue managers by running the following commands from aWindows command prompt:

strmqm QM1strmqm QM2

developerWorks® ibm.com/developerWorks

Fastrack to federated replicationPage 14 of 30 © Copyright IBM Corporation 1994, 2008. All rights reserved.

7. Create the queues and channels by running the following scripts from aWindows command prompt:

a. Run the unidirectional source script:

runmqsc QM1 < c:\uni_source.mqs

b. Run the unidirectional target script:

runmqsc QM2 < c:\uni_target.mqs

Start your WebSphere MQ channels and listeners

Use the commands identified in each step to start your WebSphere MQ channelsand listeners. Run the commands from a Windows command prompt. You run thestart channel command and the end command from an interactive session thatbegins when you run the runmqsc command.

1. Start the listener for QM1 by running the following command. Thecommand opens a window for the listener. Do not close the window.

start runmqlsr -t tcp -m QM1 -p 1451

2. Start an interactive session with QM1.

runmqsc QM1

3. Start the sender channel by running the following command:

start channel (QM1_TO_QM2)

4. Run the end command to complete the interactive session with QM1.

5. Start the listener for QM2 by running the following command. Thecommand opens a window for the listener. Do not close the window.

ibm.com/developerWorks developerWorks®

Fastrack to federated replication© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 15 of 30

start runmqlsr -t tcp -m QM2 -p 1450

6. Start an interactive session with QM2 by running the following command:

runmqsc QM2

7. Start the receiver channel by running the following command:

start channel (QM2_TO _QM1)

8. Run the end command to complete the interactive session with QM2

Reference list of WebSphere MQ objects that you created

Use the following tables as a reference. You need to specify the names of theseWebSphere MQ objects when you create replication objects.

You created the following WebSphere MQ objects by running the uni_source.mqsscript:

WebSphere MQ object Name

Send queue ASN.QM1_TO_QM2.DATAQ

Administration queue ASN.QM1.ADMINQ

Restart queue ASN.QM1.RESTARTQ

Transmission queue QM2

Sender channel QM1_TO_QM2

Receiver channel QM2_TO_QM1

You created the following WebSphere MQ objects by running the uni_target.mqsscript:

WebSphere MQ object Name

Receive queue ASN.QM1_TO_QM2.DATAQ

Administration queue (pointer) ASN.QM1.ADMINQ

Queue definition for spill queues IBMQREP.SPILL.MODELQ

Transmission queue QM1

developerWorks® ibm.com/developerWorks

Fastrack to federated replicationPage 16 of 30 © Copyright IBM Corporation 1994, 2008. All rights reserved.

Sender channel QM2_TO_QM1

Receiver channel QM1_TO_QM2

Verify your WebSphere MQ setup by using the WebSphere MQExplorer

On Windows, you can use WebSphere MQ Explorer to view the status of yourqueues and channels to verify that the object are running.

1. Open the WebSphere MQ Explorer by selecting: All Programs > IBMWebSphere MQ Explorer > WebSphere MQ Explorer from theWindows Start menu.

2. Verify that the queue managers are running by expanding the QueueManagers folder.

Figure 3. WebSphere MQ Explorer showing that the queue managersQM1 and QM2 are running

3. Verify that the channels are running by selecting the Channels folder.

a. Expand the object tree by clicking Console Root > QueueManagers > QM1 > Advanced > Channels

b. Expand the object tree by clicking Console Root > QueueManagers > QM2 > Advanced > Channels

Figure 4. WebSphere MQ Explorer showing that both channels forqueue manager QM1 are running

ibm.com/developerWorks developerWorks®

Fastrack to federated replication© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 17 of 30

4. If the queue managers and channels are running, skip to the next section.If either of the queue managers or either of the channels are not running,complete the following steps:

a. Stop the queue managers (QM1 and QM2) by right-clicking on thequeue manager in the object tree and selecting Stop.

b. Delete the queue managers by selecting the name of the queuemanager in the object tree and clicking the push button. By

deleting the queue managers, you also delete the queues,channels, and listeners in each queue manager.

c. Return to the topic: Create your WebSphere MQ objects andcreate your queue managers and repeat the WebSphere MQ setupprocedure.

Section 5. Create the replication objects

Overview of replication objects

Control tables store replication object definitions, settings, and status information.The replication queue map identifies the WebSphere MQ queues that the replicationprograms use to transport data and communicate. The Q subscription defines howdata replicates from the source table to the target table. The target table nickname isthe interface between Q replication and WebSphere II for replicated data.

Objects that you create in this section:

developerWorks® ibm.com/developerWorks

Fastrack to federated replicationPage 18 of 30 © Copyright IBM Corporation 1994, 2008. All rights reserved.

• Q Capture control tables

• Q Apply control tables

• Replication queue map

• Q subscription

• Nicknames

Create Q Capture control tables

In this step you create Q Capture control tables that store replication objectdefinitions, settings, and status information for the Q Capture program. The QCapture program will capture data from the employee table in the SOURCEdatabase and place it on WebSphere MQ queues for transport. Each instance of theQ Capture program (you use only one instance of the Q Capture program for thistutorial) requires one set of Q Capture control tables. The Q Capture control tablesreside in the SOURCE database. The names of the Q Capture control tables beginwith the prefix IBMQREP.

ibm.com/developerWorks developerWorks®

Fastrack to federated replication© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 19 of 30

1. Open the Replication Center by running the db2rc command from aWindows command prompt.

2. On the Replication Center Launchpad, select Q replication from theSelect launchpad view field.

3. Select 1. Create Q Capture Control Tables from the launchpad. TheCreate Q Capture Control Tables wizard opens.

4. On the Start page of the Create Q Capture Control Tables wizard, clickNext.

5. Click the push button and select SAMPLE in the Q Capture server

field.

6. Make sure that you enter your Windows user ID in the User ID field andyour Windows password in the Password field.

7. Place your cursor in the Q Capture Schema field. ASN automaticallyappears. Click Next.

8. On the Enter queues page, enter QM1 in the Queue Manager field,ASN.QM1.ADMINQ as the Administration Queue field, andASN.QM1.RESTARTQ in the Restart queue field. Click Next.

9. On the Summary page, click Finish.

10. The Run Now or Save SQL window opens, Click OK to accept thedefaults and run the script that creates the Q Capture control tables.

Create Q Apply control tables

Create Q Apply control tables that store replication object definitions, settings, andstatus information for the Q Apply program. The Q Apply program receives data fromWebSphere MQ queues and applies that data to a nickname in the FEDERATEDdatabase. Each instance of the Q Apply program requires one set of Q Apply controltables. Some of the Q Apply control tables reside in the federated databaseFEDERATED and some of the Q Apply control tables reside in your orcl targetdatabase. The names of the Q Capture control tables begin with the prefixIBMQREP.

The Replication Center creates nicknames when it creates the Q Apply control

developerWorks® ibm.com/developerWorks

Fastrack to federated replicationPage 20 of 30 © Copyright IBM Corporation 1994, 2008. All rights reserved.

tables. Q replication applies replicated data to the target table nickname. Thereplicated data propagates from the target table nickname to the Oracle target tablethrough WebSphere II. The Q Apply nickname updates the Q Apply control tablesthat reside on the Oracle target database (orcl).

Use the Create Q Apply Control Tables wizard.

1. In the Replication Center, select Launchpad from the ReplicationCenter menu.

2. Select 2. Create Q Apply Control Tables.

3. On the Start page, click Next.

4. On the Server page complete the following steps:

a. Click the push button and select FEDERATED as the target

server for Q replication.Note: Remember, Q replication moves data between the DB2

UDB databases SAMPLE and FEDERATED. So, the sourcedatabase for Q replication is SAMPLE and the target database forQ replication is FEDERATED. However, the orcl target database isthe final destination for your data.

b. Place your cursor in the Q Apply Schema field and ASN willautomatically appear.

c. Type your user id and password.

d. Click Next.

5. On the Location of Target Tables page, select the In the non-DB2relational server that is mapped to the DB2 federated server radiobutton.

6. On the Queue manager page, specify QM2 as the queue manager, thenclick Next.

7. On the summary page, click Finish.

8. On the Run Now or Save SQL window that opens, type your Windows

ibm.com/developerWorks developerWorks®

Fastrack to federated replication© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 21 of 30

user ID and password. Your Windows user ID has the authority toconnect to Oracle through the user mapping that you created earlier inthis tutorial. Click OK to run the script that creates the Q Apply controltables in the FEDERATED database and in the orcl database.

Create a replication queue map

Create a Replication queue map that identifies which WebSphere MQ queues thatthe Q Capture and Q Apply programs will use to transport data and communicate.

1. In the Replication Center object tree under Q replication, navigate toDefinitions > Q Capture servers > SAMPLE > Q Capture schemas >ASN > Replication Queue Maps. Right-click the folder and selectCreate.

2. Type ASN.QM1_TO_QM2.DATAQ in the Send queue field.

3. Click the push button on the Q Apply server field and select

ORACLE_SERVER (FEDERATED).

4. Type ASN.QM1_TO_QM2.DATAQ in the Receive queue field.Note: The receive queue has the same name as the send queue

because the send queue is a remote queue and is typically named for thelocal queue that it points to. In this example the receive queue is a localqueue.

5. Type ASN.QM1.ADMINQ in the Administration queue field.

6. Click OK.Note: The Replication queue map name field is filled in

automatically.

7. Click OK on the Run Now or Save SQL window that opens to accept thedefaults and run the script that creates the replication queue map.

Create a Q subscription

developerWorks® ibm.com/developerWorks

Fastrack to federated replicationPage 22 of 30 © Copyright IBM Corporation 1994, 2008. All rights reserved.

Create a Q subscription that defines how to replicate data from the employee tableto the nickname. Q subscriptions tell the replication programs which changes tocapture from the source table, what queues to use for sending and receiving changemessages, and how to process the messages.

1. In the Q replication launchpad, click 3. Create a Q Subscription in the Qreplication launchpad. You can also right-click the Q Subscriptions folderin the object tree directly above Replication Queue Maps, and clickCreate.

2. On the Start page of the Create Q Subscriptions wizard, click Next.

3. On the Replication page, accept the default of Unidirectional, then clickNext.

4. On the Servers page under Target , click the push button next to the

Server field and select ORACLE_SERVER (FEDERATED) from the QApply Servers list. Click OK to dismiss the Q Apply Servers window, thenand click Next on the Servers page of the wizard.

5. On the Source Tables page, click Add.

6. In the Select Source tables page, scroll down the list and select theEMPLOYEE table. Click OK.

7. On the Source Tables page, accept the defaults and click Next.

8. On the Target page, accept the defaults and click Next.

9. On the Rows and Columns page, click the pushbutton next to the

Index or primary key field.

10. Select the columns empno, lastname, and salary and click OK.

11. On the Rows and Columns page, accept the defaults and click Next

12. On the Unexpected Conditions page, accept the defaults and click Next.

13. On the Loading Target Tables page, accept the default of Automatic andclick Next.

14. On the Review Q Subscriptions page, click Next.

ibm.com/developerWorks developerWorks®

Fastrack to federated replication© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 23 of 30

15. On the Summary page, click Finish.

16. On the Run Now or Save SQL window that opens, accept the defaultsand click OK to run the script that creates the Q subscription.

Section 6. Replicate data and check results

Overview of replication programs

You must start the replication programs before you can replicate data. The QCapture program captures data and places the data on WebSphere MQ queues.The Apply program applies the data from the queues to the nickname.

Programs that you start in this section:

• Q Capture program

• Q Apply program

developerWorks® ibm.com/developerWorks

Fastrack to federated replicationPage 24 of 30 © Copyright IBM Corporation 1994, 2008. All rights reserved.

Prepare the SAMPLE and FEDERATED servers for Qreplication

Configure your DB2 UDB databases SAMPLE and FEDERATED to work with the Qreplication programs. Remember, SAMPLE is the database that contains yoursource table (employee), and FEDERATED is the federated server that containsyour nickname. Q replication moves data from SAMPLE to FEDERATED.

Run the following commands from a DB2 UDB command line tool to perform thefollowing actions.

1. Make sure that the logretain parameter is set to recovery. Run thefollowing commands to check the current setting:

db2 connect to sampledb2 get database configuration for sample

The command returns a list of database configuration parameters andtheir values. Find logretain. If the value of the logretain parameter is setto recovery, then skip to step two in this section. If the logretain

ibm.com/developerWorks developerWorks®

Fastrack to federated replication© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 25 of 30

parameter is not set to recovery, run the following command to set theparameter:

db2 update database configuration for sample using logretain recovery

2. Create a password file on the federated server (FEDERATED) in DB2UDB by running the following commands:

db2 connect to federatedasnpwd initasnpwd ADD ALIAS target ID windowlsogon password windowspassword using asnpwd.aut

Tip: windowslogon is your Windows user id and windowspassword

is your Windows password.

Start the Q Capture program

Next, you start the Q Capture program by completing the following steps:

1. Expand the Operations folder under Q replication in the object tree.

2. Select Q Capture servers in the object tree. Right-click SAMPLE in thecontents pane and select Start Q Capture program from the menu.

3. Click OK in the Start Q Capture window.

4. On the Run Now or Save Command window, click the push button

and select your system name.

5. Click OK on the Run Now or Save Command window to run the script thatstarts the Q Capture program.

Start the Q Apply program

Start the Q Apply program by completing the following steps:

1. Expand the Operations folder under Q replication in the object tree.

developerWorks® ibm.com/developerWorks

Fastrack to federated replicationPage 26 of 30 © Copyright IBM Corporation 1994, 2008. All rights reserved.

2. Select Q Apply servers in the object tree. Right-click FEDERATED in thecontents pane and select Start Q Apply program from the menu.

3. Click OK to close the Start Q Apply window.

4. On the Run Now or Save Command window, click the push button

and select your system name. Type DB2 in the Instance Name field.

5. Click OK on the Run Now or Save Command window to run the script thatstarts the Q Apply program.

Check replication results

You can use SQL to insert a row into the source table and check that the datareplicates to your Oracle target table (orcl).

1. Make sure that the Q Capture program is running by using the CheckStatus window.

a. Expand the Operations folder under Q replication in theReplication Center object tree.

b. Select Q Capture servers in the object tree. Right-click SAMPLEin the contents pane and select Check Status. The Check Statuswindow opens.

c. Click the push button to refresh the view and receive the

status of the Q Capture program.

2. Make sure that the Q Apply program is running by using the Check statuswindow.

a. Expand the Operations folder under Q replication in theReplication Center object tree.

b. Select Q Apply servers in the object tree. Right-clickFEDERATED in the contents pane and select Check Status. TheCheck Status window opens.

c.

ibm.com/developerWorks developerWorks®

Fastrack to federated replication© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 27 of 30

push button to refresh the view and receive the status of the

Q Apply program.

3. Check to see if the target table loaded successfully by completing thefollowing steps:

a. Use the Control Center to view the employee nickname to see if itis populated by navigating to All Databases > FEDERATED >Nicknames in the Replication Center object tree anddouble-clicking the EMPLOYEE nickname in the contents pane. Ifthe nickname has rows in it, the load was successful.

b. Run the following commands from a DB2 command line:

db2 connect to targetdb2 select * from windowslogon.employee

The result set should contain 32 rows.

4. Insert a row into the source table by running the following command froma DB2 command line:

INSERT INTO WINDOWSLOGON.EMPLOYEE (EMPNO, FIRSTNME, MIDINIT, LASTNAME, WORKDEPT,PHONENO, SEX, HIREDATE, JOB, EDLEVEL, BIRTHDATE, SALARY, BONUS, COMM) VALUES ('123456','KENCE', 'M','ANDERSON', 'J35', '9999', 'M', '2003-06-11', 'CEO', 20, '1978-10-21', 52750.00, 1000.00,4220.00)

5. Check for the inserted row in the target table by running the followingcommands:

db2 connect to targetdb2 set passthru oracle_serverdb2 select * from employee where lastname = 'ANDERSON'db2 set passthru reset

The result set should contain 33 rows. Look for kence.

Section 7. Summary and resources

developerWorks® ibm.com/developerWorks

Fastrack to federated replicationPage 28 of 30 © Copyright IBM Corporation 1994, 2008. All rights reserved.

Summary

Congratulations! You have completed the following actions:

• Created sources and targets for replication in DB2 Universal Database

• Connected the DB2 source to the Oracle target using WebSphereInformation Integrator

• Created the WebSphere MQ infrastructure for replication

• Created all of the necessary replication objects

• Replicated data

You also checked your results to make sure that the data successfully replicated tothe Oracle target database (orcl).

ibm.com/developerWorks developerWorks®

Fastrack to federated replication© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 29 of 30

Resources

• "Replicate Data in the Fast Lane" is a developerWorks tutorial that will guide youthrough the setup of unidirectional replication from a DB2 table to another DB2table.

• The "Q Replication Version 8.2 Information Roadmap" can guide you toresources on how to install, configure, administer, monitor, tune, and troubleshootQ replication.

• The DB2 Information Center contains documentation on Q replication, DB2 UDB,and WebSphere Information Integrator.

About the author

Kence AndersonKence Anderson is an information developer for the IBM WebSphere InformationIntegrator replication team. He develops product documentation for replication andevent publishing.

developerWorks® ibm.com/developerWorks

Fastrack to federated replicationPage 30 of 30 © Copyright IBM Corporation 1994, 2008. All rights reserved.