Configure Db2

Db2 support and configuration information.

The supported levels of Db2 are defined at the System Requirements for IBM MQ page.

Note: 32-bit instances of Db2 are not supported on platforms where the queue manager is 64-bit. Do the following:
  1. Check the environment variable settings.
  2. Create the Db2 switch load file.
  3. Add resource manager configuration information.
  4. Change Db2 configuration parameters if necessary.

Read this information in conjunction with the general information provided in Configure the system for database coordination. Warning: If you run db2profile on UNIX and Linux platforms, the environment variable LIBPATH and LD_LIBRARY_PATH are set. It is advisable to unset these environment variables. See crtmqenv or setmqenv for more information.


Check the Db2 environment variable settings

Ensure that your Db2 environment variables are set for queue manager processes as well as in the application processes. In particular, we 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. For example:

  • On UNIX and Linux systems, use:
    export DB2INSTANCE=db2inst1
    
  • On Windows systems, use:
    set DB2INSTANCE=Db2
    

On Windows with a Db2 database, we must add the user MUSR_MQADMIN to the DB2USERS group, to enable the queue manager to start.


Create the Db2 switch load file

The easiest way to create the Db2 switch load file is to use the sample file xaswit.mak, which IBM MQ provides to build the switch load files for a variety of database products.

On Windows systems, we can find xaswit.mak in the directory MQ_INSTALLATION_PATH\tools\c\samples\xatm. MQ_INSTALLATION_PATH represents the high-level directory in which IBM MQ is installed. To create the Db2 switch load file with Microsoft Visual C++, use:
nmake /f xaswit.mak db2swit.dll
The generated switch file is placed in C:\Program Files\IBM\MQ\exits.

We can find xaswit.mak in the directory MQ_INSTALLATION_PATH/samp/xatm. MQ_INSTALLATION_PATH represents the high-level directory in which IBM MQ is installed.

Edit xaswit.mak to uncomment the lines appropriate to the version of Db2 we are using. Then execute the makefile using the command:
make -f xaswit.mak db2swit

The generated 32-bit switch load file is placed in /var/mqm/exits.

The generated 64-bit switch load file is placed in /var/mqm/exits64.


Adding resource manager configuration information for Db2

We must modify the configuration information for the queue manager to declare Db2 as a participant in global units of work. Modifying configuration information in this way is described in more details in Adding configuration information to the queue manager.

  • On Windows and Linux (x86 and x86-64 platforms) systems, use the IBM MQ Explorer. Specify the details of the switch load file in the queue manager properties panel, under XA resource manager.
  • On all other systems specify the details of the switch load file in the XAResourceManager stanza in the queue manager's qm.ini file.

Figure 1 is a UNIX sample, showing an XAResourceManager entry where the database to be coordinated is called mydbname, this name being specified in the XAOpenString:

Figure 1. Sample XAResourceManager entry for Db2 on UNIX
XAResourceManager:
  Name=mydb2
  SwitchFile=db2swit
  XAOpenString=mydbname,myuser,mypasswd,toc=t
  ThreadOfControl=THREAD
Note:
  1. ThreadOfControl=THREAD cannot be used with Db2 versions earlier than version 8. Set ThreadOfControl and the XAOpenString parameter toc to one of the following combinations:

    • ThreadOfControl=THREAD and toc=t
    • ThreadOfControl=PROCESS and toc=p

    If we are using the jdbcdb2 XA switch load file to enable JDBC/JTA coordination, we must use ThreadOfControl=PROCESS and toc=p.


Change Db2 configuration parameters

For each Db2 database that the queue manager is coordinating, we must set database privileges, change the tp_mon_name parameter, and reset the maxappls parameter. To do this, perform the following steps:

    Set database privileges
    The queue manager processes run with effective user and group mqm on UNIX and Linux systems. On Windows systems, they run as the user that started the queue manager. This can be one of:
    1. The user who issued the strmqm command, or
    2. The user under which the IBM MQ Service COM server runs

    By default, this user is called MUSR_MQADMIN.

    If we have not specified a user name and password on the xa_open string, the user under which the queue manager is running is used by Db2 to authenticate the xa_open call. If this user (for example, user mqm on UNIX and Linux systems) does not have minimal privileges in the database, the database refuses to authenticate the xa_open call.

    The same considerations apply to the application process. If we have not specified a user name and password on the xa_open string, the user under which the application is running is used by Db2 to authenticate the xa_open call that is made during the first MQBEGIN. Again, this user must have minimal privileges in the database for this to work.

    For example, give the mqm user connect authority in the mydbname database by issuing the following Db2 commands:
    db2 connect to mydbname
    db2 grant connect on database to user mqm
    
    See Security considerations for more information about security.

    Change the TP_MON_NAME parameter
    For Db2 on 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
    We 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 Installing and configuring the database product.

Parent topic: Scenario 1: Queue manager performs the coordination