Fastrack to federated replication - Skill Level: Introductory

Fastrack to federated replication - Skill Level: Introductory

Fastrack to federated replication Skill Level: Introductory Kence Anderson (andersok@us.ibm.com) 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 OracleTM 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

Overview of the products in this tutorial Product Description DB2 Universal Database (UDB) DB2 UDB manages the source database and the database that connects to Oracle 10g Oracle 10g Database Oracle 10g manages the database that contains the target table where you replicate your data to. WebSphere Information Integrator (II) WebSphere II facilitates communication between DB2 UDB and Oracle 10g. WebSphere MQ WebSphere MQ transports data between DB2 UDB 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 this account 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 to create a general starter database. Use the default (orcl) as the global database name. See the Oracle Database Quick Installation Guide 10g Release 1 (10.1.0.2.0) for Windows if you need more help installing Oracle 10g.

e. When the Oracle Universal Installer prompts you to create a password, type oraclepassword. 2. DB2 Universal Database (UDB) Version 8.2 3. WebSphere Information Integrator Replication Edition Version 8.2 You need the Oracle relational wrapper to complete this tutorial. Install all of 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 replication Page 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.3 Download 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, the source table resides in a DB2 UDB database and the Oracle target table resides in an Oracle database. You use a DB2 UDB federated database to communicate with the 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 the federateddatabase The source for replication data in this tutorial is the DB2 UDB sample database. All replicated data originates from the employee table. The employee table is the source table and resides in the sample database. Data replicates from the source database (SAMPLE) to a DB2 UDB federated database (FEDERATED). The federated database is an intermediate stop for replicated data between the source database (DB2 UDB) and the target database (Oracle). The federated database communicates with the Oracle target database.

1. Create the DB2 UDB sample database by running the db2sampl command 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 replication Page 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 Create Database > Standard. The Create Database wizard opens. b. On the Name page of the Create Database wizard, type FEDERATED in the Database name field. c. Click Finish. d. Click No on the DB2 message window that appears. The message recommends that you run the Configuration Advisor on the new database that you created. The Configuration Advisor helps you set database parameters for features that you do not need for this tutorial.

Create a user ID for replication on the Oracle database (orcl) Before you can set up the infrastructure that connects the DB2 UDB database FEDERATED to the Oracle 10g database orcl, you need to create a user ID for replication.

You specify this Oracle user ID and password when you set up WebSphere Information Integrator, which will connect the federated server (FEDERATED) to the Oracle database (orcl). Create a user ID named tutorial_user with a password oraclepassword. 1. Open the Oracle SQLPlus command interface by running the sqlplus command 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 have entered. 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 the tutorial_user user ID: grant all privileges to tutorial_user; You need to grant all privileges to the tutorial_user user ID so that the Oracle database (orcl) will allow WebSphere Information Integrator to use this 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 DB2 UDB database to the Oracle 10g database. The Oracle wrapper enables communication between DB2 UDB and Oracle. The server definition coordinates connections between the federated database (FEDERATED) and the Oracle 10g database (orcl). The user mapping coordinates authorizations for both databases. Objects that you create in this section: developerWorks® ibm.com/developerWorks Fastrack to federated replication Page 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 that instance to act as federated servers. A federated server is a database that enables communication with a non-DB2 database through a wrapper, server definition, user mapping, and nickname. 1. Expand the DB2 UDB Control Center object tree to Instances > DB2 for your 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 group and 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 Configuration Parameters 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 Center object 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 communication between your federated database (FEDERATED) and your Oracle target database (orcl). Use the Create Federated Objects wizard. To start the wizard, right-click the Federated Database Objects folder under FEDERATED in the object tree, and click 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 Data Source Type field and select Oracle using OCL 8. Click Next. c. On the Wrappers page, click Create (Wrappers section), to create the 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 the wrapper 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 replication Page 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 select Alter.

The wrapper name appears in the Control Center object tree under Federated Objects. Click Set Variables on the Alter Wrapper notebook to open the Set Environment Variables window. g. Type C:\oracle\product\10.1.0\db_1 in the Value field of the Set Environment Variables window and click OK to specify your Oracle home directory. h. Accept the defaults on the Settings page and click OK. The Create Federated Objects wizard continues so that you can create 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 Create Server 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 the NODE variable. Click OK to save your save your changes and close the notebook. f. Click OK to save your changes and close the Create Server Definitions window.

g. Click Next in the wizard.

The wizard continues, to help you create a user mapping, which is covered 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 the database 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. Your node 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 to create a user mapping.

1. On the User Mappings page, click Create. 2. On the Users page of the Create User Mappings notebook, select your Windows 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 replication Page 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 click OK. 4. On the Settings page, type tutorial_user in the Value field next to REMOTE_AUTHID and type oraclepassword in the Value field next to REMOTE_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 when you 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 the Oracle targetdatabase Next, you test the connection between the DB2 UDB federated database (FEDERATED) and the Oracle target database (orcl) by using a pass-through session. A pass-through session connects DB2 UDB with Oracle and allows you to issue Oracle sqlplus commands from a DB2 UDB command window as if you were using 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 Universal Installer defined when you installed Oracle 10g).

The Oracle Enterprise Manager tool opens.

b. Log in using the user ID sysman and the password oraclepassword. 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: db2start db2 connect to federated 3. Use a pass-through session to test your connection. Run the following commands from a DB2 command line tool: db2 set passthru oracle_server db2 select count(*) from sys.all_tables 4.

A count that represents the number of tables in your orcl database should appear. 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-through commands that you entered for errors. Then check your user mapping to make sure that you entered your Oracle user id (tutorial_user) and password (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 following command 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 the DB2 UDB databases during replication. Queue managers act as the brain of the messaging system, queues store the data messages, channels transmit messages between queue managers, and listeners monitor channels for incoming messages. Objects that you create in this section: developerWorks® ibm.com/developerWorks Fastrack to federated replication Page 12 of 30 © Copyright IBM Corporation 1994, 2008. All rights reserved.

• Queue managers • Queues • Channels • Listeners Create your WebSphere MQ objects and start your queue managers You will use two prepared WebSphere MQ scripts to create your queues and channels. First you modify the script with information that is specific to your computer, then you run the scripts from a Windows command prompt. 1. Download the following scripts and save them in the c:\ directory of your computer: • 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 the C:\WINDOWS\system32\drivers\etc directory with a text editor. Search the file for 1450 and 1451 to see if the ports 1450 and 1451 are allocated. If the ports are not found, they are available and you can skip to step 3. If ports 1450 and 1451 exist in the file and are allocated, you can use any two unused ports for this tutorial. If you choose two available ports other than 1450 and 1451, replace ports 1450 and 1451 with the ports 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 your computer.

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 your computer. 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 QM2 by running the following commands from a Windows command prompt: crtmqm QM1 crtmqm QM2 6. Start the queue managers by running the following commands from a Windows command prompt: strmqm QM1 strmqm QM2 developerWorks® ibm.com/developerWorks Fastrack to federated replication Page 14 of 30 © Copyright IBM Corporation 1994, 2008.

All rights reserved.

7. Create the queues and channels by running the following scripts from a Windows 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 channels and listeners. Run the commands from a Windows command prompt. You run the start channel command and the end command from an interactive session that begins when you run the runmqsc command.

1. Start the listener for QM1 by running the following command.

The command 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. The command 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 these WebSphere MQ objects when you create replication objects. You created the following WebSphere MQ objects by running the uni_source.mqs script: 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.mqs script: 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 replication Page 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 MQ Explorer On Windows, you can use WebSphere MQ Explorer to view the status of your queues and channels to verify that the object are running. 1. Open the WebSphere MQ Explorer by selecting: All Programs > IBM WebSphere MQ Explorer > WebSphere MQ Explorer from the Windows Start menu. 2. Verify that the queue managers are running by expanding the Queue Managers folder. Figure 3. WebSphere MQ Explorer showing that the queue managers QM1 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 > Queue Managers > QM1 > Advanced > Channels b. Expand the object tree by clicking Console Root > Queue Managers > QM2 > Advanced > Channels Figure 4. WebSphere MQ Explorer showing that both channels for queue 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 the queue manager in the object tree and selecting Stop. b. Delete the queue managers by selecting the name of the queue manager 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 and create your queue managers and repeat the WebSphere MQ setup procedure.

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 replication programs use to transport data and communicate. The Q subscription defines how data replicates from the source table to the target table. The target table nickname is the interface between Q replication and WebSphere II for replicated data. Objects that you create in this section: developerWorks® ibm.com/developerWorks Fastrack to federated replication Page 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 object definitions, settings, and status information for the Q Capture program. The Q Capture program will capture data from the employee table in the SOURCE database and place it on WebSphere MQ queues for transport. Each instance of the Q Capture program (you use only one instance of the Q Capture program for this tutorial) requires one set of Q Capture control tables. The Q Capture control tables reside in the SOURCE database.

The names of the Q Capture control tables begin with 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 a Windows command prompt. 2. On the Replication Center Launchpad, select Q replication from the Select launchpad view field. 3. Select 1. Create Q Capture Control Tables from the launchpad. The Create Q Capture Control Tables wizard opens. 4. On the Start page of the Create Q Capture Control Tables wizard, click Next. 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 and your Windows password in the Password field.

7. Place your cursor in the Q Capture Schema field. ASN automatically appears. Click Next. 8. On the Enter queues page, enter QM1 in the Queue Manager field, ASN.QM1.ADMINQ as the Administration Queue field, and ASN.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 the defaults 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, and status information for the Q Apply program.

The Q Apply program receives data from WebSphere MQ queues and applies that data to a nickname in the FEDERATED database. Each instance of the Q Apply program requires one set of Q Apply control tables. Some of the Q Apply control tables reside in the federated database FEDERATED and some of the Q Apply control tables reside in your orcl target database. The names of the Q Capture control tables begin with the prefix IBMQREP.

The Replication Center creates nicknames when it creates the Q Apply control developerWorks® ibm.com/developerWorks Fastrack to federated replication Page 20 of 30 © Copyright IBM Corporation 1994, 2008. All rights reserved.

tables. Q replication applies replicated data to the target table nickname. The replicated data propagates from the target table nickname to the Oracle target table through WebSphere II. The Q Apply nickname updates the Q Apply control tables that reside on the Oracle target database (orcl). Use the Create Q Apply Control Tables wizard.

1. In the Replication Center, select Launchpad from the Replication Center 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 source database for Q replication is SAMPLE and the target database for Q replication is FEDERATED. However, the orcl target database is the final destination for your data. b. Place your cursor in the Q Apply Schema field and ASN will automatically appear. c. Type your user id and password. d. Click Next. 5. On the Location of Target Tables page, select the In the non-DB2 relational server that is mapped to the DB2 federated server radio button.

6. On the Queue manager page, specify QM2 as the queue manager, then click 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 to connect to Oracle through the user mapping that you created earlier in this tutorial. Click OK to run the script that creates the Q Apply control tables 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 that the Q Capture and Q Apply programs will use to transport data and communicate. 1. In the Replication Center object tree under Q replication, navigate to Definitions > Q Capture servers > SAMPLE > Q Capture schemas > ASN > Replication Queue Maps.

Right-click the folder and select Create.

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 the local queue that it points to. In this example the receive queue is a local queue. 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 the defaults and run the script that creates the replication queue map.

Create a Q subscription developerWorks® ibm.com/developerWorks Fastrack to federated replication Page 22 of 30 © Copyright IBM Corporation 1994, 2008. All rights reserved.

Create a Q subscription that defines how to replicate data from the employee table to the nickname. Q subscriptions tell the replication programs which changes to capture from the source table, what queues to use for sending and receiving change messages, and how to process the messages. 1. In the Q replication launchpad, click 3. Create a Q Subscription in the Q replication launchpad. You can also right-click the Q Subscriptions folder in the object tree directly above Replication Queue Maps, and click Create.

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

On the Replication page, accept the default of Unidirectional, then click Next. 4. On the Servers page under Target , click the push button next to the Server field and select ORACLE_SERVER (FEDERATED) from the Q Apply Servers list. Click OK to dismiss the Q Apply Servers window, then and 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 the EMPLOYEE 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 and click 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 defaults and 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 Q Capture 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 replication Page 24 of 30 © Copyright IBM Corporation 1994, 2008.

All rights reserved.

Prepare the SAMPLE and FEDERATED servers for Q replication Configure your DB2 UDB databases SAMPLE and FEDERATED to work with the Q replication programs. Remember, SAMPLE is the database that contains your source table (employee), and FEDERATED is the federated server that contains your nickname. Q replication moves data from SAMPLE to FEDERATED. Run the following commands from a DB2 UDB command line tool to perform the following actions. 1. Make sure that the logretain parameter is set to recovery. Run the following commands to check the current setting: db2 connect to sample db2 get database configuration for sample The command returns a list of database configuration parameters and their values.

Find logretain. If the value of the logretain parameter is set to 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 the parameter: db2 update database configuration for sample using logretain recovery 2. Create a password file on the federated server (FEDERATED) in DB2 UDB by running the following commands: db2 connect to federated asnpwd init asnpwd 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 the contents 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 that starts 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 replication Page 26 of 30 © Copyright IBM Corporation 1994, 2008. All rights reserved.

2. Select Q Apply servers in the object tree. Right-click FEDERATED in the contents 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 that starts the Q Apply program. Check replication results You can use SQL to insert a row into the source table and check that the data replicates to your Oracle target table (orcl).

1. Make sure that the Q Capture program is running by using the Check Status window. a. Expand the Operations folder under Q replication in the Replication Center object tree. b. Select Q Capture servers in the object tree. Right-click SAMPLE in the contents pane and select Check Status. The Check Status window 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 status window. a. Expand the Operations folder under Q replication in the Replication Center object tree.

b.

Select Q Apply servers in the object tree. Right-click FEDERATED in the contents pane and select Check Status. The Check 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 the following steps: a. Use the Control Center to view the employee nickname to see if it is populated by navigating to All Databases > FEDERATED > Nicknames in the Replication Center object tree and double-clicking the EMPLOYEE nickname in the contents pane. If the nickname has rows in it, the load was successful. b. Run the following commands from a DB2 command line: db2 connect to target db2 select * from windowslogon.employee The result set should contain 32 rows.

4. Insert a row into the source table by running the following command from a 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 following commands: db2 connect to target db2 set passthru oracle_server db2 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 replication Page 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 WebSphere Information 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 to the 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 you through the setup of unidirectional replication from a DB2 table to another DB2 table. • The "Q Replication Version 8.2 Information Roadmap" can guide you to resources on how to install, configure, administer, monitor, tune, and troubleshoot Q replication. • The DB2 Information Center contains documentation on Q replication, DB2 UDB, and WebSphere Information Integrator. About the author Kence Anderson Kence Anderson is an information developer for the IBM WebSphere Information Integrator replication team.

He develops product documentation for replication and event publishing.

developerWorks® ibm.com/developerWorks Fastrack to federated replication Page 30 of 30 © Copyright IBM Corporation 1994, 2008. All rights reserved.