DB2 configuration

The minimum supported level of DB2 is DB2 Universal Database(R), Version 5.0.

You need to do the following:

Checking the environment variable settings

Ensure that your DB2 environment variables are set for queue manager processes as well as in your application processes. In particular, you must always set the DB2INSTANCE environment variable before you start the queue manager. The DB2INSTANCE environment variable identifies the DB2 instance containing the DB2 databases that are being updated.

Creating the DB2 switch load file

The easiest way to create the DB2 switch load file is to use the sample file xaswit.mak. The source code used to create the DB2 switch on most platforms is shown in Figure 11. The source for db2swit.c for Windows systems is different; it is shown in Figure 12.

Figure 11. Source code for db2swit.c for UNIX systems


#include <cmqc.h>
#include "xa.h"
 
extern struct xa_switch_t db2xa_switch;
 
struct xa_switch_t * MQENTRY MQStart(void)
{
   return(&db2xa_switch);
}

Figure 12. Source code for db2swit.c on Windows systems (Microsoft Visual C++-specific)


#include <cmqc.h>
#include "xa.h"
 
extern __declspec(dllimport) struct xa_switch_t db2xa_switch;
 
struct xa_switch_t * MQENTRY MQStart(void)
{
   return(&db2xa_switch);
}

The xa.h header file supplied with WebSphere MQ is installed (for WebSphere MQ for Windows) in the C:\Program Files\IBM\WebSphere MQ\tools\c\samples\xatm directory, or (for WebSphere MQ for UNIX systems) in the /opt/mqm/samp/xatm directory (/usr/mqm/samp/xatm for AIX).

Creating the DB2 switch load file on Windows systems

To create the DB2 switch load file on Windows systems, compile db2swit.c and link it against db2api.lib. The DEF file shown in Figure 13 is needed to produce the DLL:

Figure 13. Source code for db2swit.def on Windows systems


LIBRARY DB2SWIT
 
EXPORTS
   MQStart

To create the DLL:

  1. Create a directory into which you want to build the switch file. Define the switch file to WebSphere MQ as a fully-qualified name so the DLL does not need to be built into a directory within PATH.
  2. Copy the following files from C:\Program Files\IBM\WebSphere MQ\tools\c\samples\xatm into your new directory:
  3. Use the source code shown in Figure 14, which forms part of xaswit.mak on Windows systems, to build the switch load file:

    Figure 14. Makefile for DB2 switch on Windows systems


    !include <ntwin32.mak>
     
    db2swit.lib db2swit.exp: $*.obj $*.def
                             $(implib) -machine:$(CPU) \
                             -def:$*.def $*.obj
     
    db2swit.dll: $*.obj $*.def $*.exp
                 $(link) $(dlllflags)    \
                 -base:0x1C000000        \
                 $*.exp $*.obj           \
                 $(conlibsdll) db2api.lib
     
    .c.obj:
        $(cc) $(cflags) $(cvarsdll) $*.c
    
  4. Make the DB2 switch load file:

Creating the DB2 switch load file on UNIX systems

WebSphere MQ provides a sample makefile, xaswit.mak, to build the switch files for a variety of database products. You can find xaswit.mak in the directory /usr/mqm/samp/xatm, with the source files you need to build the switch.

Edit xaswit.mak to uncomment the lines appropriate to the version of DB2 you are using. Then execute the makefile using the command:

make -f xaswit.mak db2swit

The generated switch file is placed in your current directory.

Adding resource manager configuration information for DB2

The next step is to modify the configuration information for the queue manager to define DB2 as a participant in global units of work. On Windows systems, use the Resources page of the properties for the queue manager (accessed from the WebSphere MQ Services snap-in). On WebSphere MQ for UNIX systems, use the XAResourceManager stanza of the qm.ini configuration file.

See XA resource managers for a more detailed description of XA resource manager configuration information.

Name=name
This attribute is mandatory. Choose a suitable name for this participant; you could include the name of the database being updated.

SwitchFile=name
This attribute is mandatory. Specify the fully-qualified name of the DB2 switch load file.

XAOpenString=string
The XA open string for DB2, which must be in the following format:
database_alias<,username,password>

where database_alias is the name of the database, unless you have explicitly cataloged an alias name after creating the database, in which case specify the alias instead.

The other parameters are optional. They provide alternative authentication information to the database if it was set up with authentication=server.

XACloseString=string
DB2 does not require an XA close string.

ThreadOfControl=THREAD|PROCESS
DB2 is thread-aware, so always specify THREAD.

For fuller descriptions of each of these attributes, see "XA resource managers".

Figure 15 shows some sample XAResourceManager entries where the database to be updated is called MQBankDB, this name being specified as the XAOpenString.

Figure 15. Sample XAResourceManager entry for DB2 on Windows systems


XAResourceManager:
  Name=DB2 MQBankDB
  SwitchFile=c:\user\dll\db2swit.dll
  XAOpenString=MQBankDB
  ThreadOfControl=PROCESS

Figure 16 is a UNIX sample. It assumes that the DB2 switch load file is copied to the /usr/bin directory being created:

Figure 16. Sample XAResourceManager entry for DB2 on UNIX platforms


XAResourceManager:
  Name=DB2 MQBankDB
  SwitchFile=/usr/bin/db2swit
  XAOpenString=MQBankDB

Changing DB2 configuration parameters

For each DB2 database that the queue manager is coordinating, you need to:

Authorize the mqm user ID to connect
Authorize the mqm user ID to connect to the DB2 database so that the queue manager can connect to DB2 from within its own processes.

For example, to give the mqm user ID connect authority to the MQBankDB database, use the following commands:

Figure 17. Sample commands to give connect user ID authority to MQBANKDB


db2 connect to MQBankDB
 
db2 grant connect on database to user mqm

See Security considerations for more information about security.

Change the tp_mon_name parameter
For DB2 for Windows systems only, change the TP_MON_NAME configuration parameter to name the DLL that DB2 uses to call the queue manager for dynamic registration.

Use the command db2 update dbm cfg using TP_MON_NAME mqmax to name MQMAX.DLL as the library that DB2 uses to call the queue manager. This must be present in a directory within PATH.

Reset the maxappls parameter
You might need to review your setting for the maxappls parameter, which limits the maximum number of applications that can be connected to a database. Refer to Database connections.

Using WebSphere MQ services with DB2

DB2 does not allow user names of more than eight characters. This means that you cannot use WebSphere MQ services (for example, the WebSphere MQ Services snap-in) to start a queue manager that has DB2 defined as a resource manager if WebSphere MQ services is using the default user name set up by WebSphere MQ (MUSR_MQADMIN). This might cause message AMQ7604 to be written to the queue manager error log and SQLCODEs -1046 and -998 (reason code 2) to be written to the DB2 log file db2diag.log

If you want to use WebSphere MQ services in these circumstances, you must either:

Alternatively, you can start the queue manager from the command line, using the strmqm command with a user name of eight characters or fewer.



© IBM Corporation 1994, 2002. All Rights Reserved