Example of enabling Db2 automatic client reroute support in non-Java clients

You can fine-tune non-Java™ client setup for Db2 automatic client reroute (acr) support by setting values for several keywords in the db2dsdriver.cfg configuration file.

Note that if you do not define a list of alternate servers in the db2dsdriver.cfg configuration file, at the first successful connection to the server, the client obtains from the server a list of all available alternate servers. The client stores the list in memory and also creates a local cache file, srvrlst.xml that contains the server's list of alternate servers. This file is refreshed whenever a new connection is made and the server's list differs from the contents of the client srvrlst.xml file.

Suppose that database sample is a Db2 pureScale® instance with two members, at server db2luwa and port 446, and server db2luwb and port 446. The database has alternate server db2luwc and port 446 defined.

You want to fine-tune default automatic client reroute support by modifying these items:

Automatic client reroute characteristic db2dsdriver.cfg configuration keyword Desired value
Number of times to retry the connection to the alternate server maxAcrRetries 10
Number of seconds to wait between retries acrRetryInterval 5
Whether to try another server if the initial connection to the database fails enableAlternateServerListFirstConnect true
The host names and port numbers of the servers to try if the initial connection to the database fails <alternateserverlist>

Note that if you do not define a list of alternate servers in the db2dsdriver.cfg configuration file, at the first successful connection to the server, the client obtains from the server a list of all available alternate servers. The client stores the list in memory and also creates a local cache file, srvrlst.xml that contains the server's list of alternate servers. This file is refreshed whenever a new connection is made and the server's list differs from the contents of the client srvrlst.xml file. The srvrlst.xml file is located under CLIENT_CONFIG_DIR in the cfgcache directory.

Host names and port numbers:
  • db2luwa.luw.ibm.com, 446
  • db2luwb.luw.ibm.com, 446
  • db2luwc.luw.ibm.com, 446

Use the following db2dsdriver.cfg configuration file to implement these changes to automatic reroute behavior:

<configuration>  
  <dsncollection>    
    <dsn alias="sample" name="sample" host="db2luw.luw.ibm.com" port="446">    
    </dsn> 
  </dsncollection>  
  <databases>    
    <database name="sample" host="db2luw.luw.ibm.com" port="446">      
      <acr>        
        <parameter name="enableAcr" value="true"/>        
        <parameter name="maxAcrRetries" value="10"/>       
        <parameter name="acrRetryInterval" value="5"/>        
        <parameter name="enableAlternateServerListFirstConnect" value="true"/>       
        <alternateserverlist>           
          <server name="server1" hostname="db2luwa.luw.ibm.com" port="446"/>           
          <server name="server2" hostname="db2luwb.luw.ibm.com" port="446"/>           
          <server name="server3" hostname="db2luwc.luw.ibm.com" port="446"/>        
        </alternateserverlist>   
      </acr>    
    </database>  
  </databases>
</configuration>
Note:
  1. Db2 CLP is not affected by db2dsdriver.cfg.
  2. The db2cli validate command can be used to validate db2dsdriver.cfg to ensure the syntax is correct.