title: Using the db2 variable "DB2DBDFT" to connect to default schema with user / using
body: <p>I am trying to write a bash script that does some db2 work. I am facing the issue whereby subshells require db2 connections to be reconnected.</p>
  
  <p>Unfortunately, reconnecting every time is dog slow, as around 1000 new connections will need to be made, each taking around a second. Thus I'm looking to avoid these subshell reconnections.</p>
  
  <p>Googling around this situation, I have found that there is a way to set the default connection schema using the variable DB2DBDFT. Unfortunately, with this set it takes the linux logged in user name to be the DB schema name you are running as, whereas our system has a different DB user name to the user logged in to bash.</p>
  
  <p>1) Is there a way to set the DB2DBDFT variable, but make it so that it can use a "user abc using 123" style syntax, or if there are other variables where you can set these (I have searched but not found them).</p>
  
  <p>2) If there is, will this actually save me any time? Obviously if I find a solution I will benchmark, but I'm not sure that even if I find this, it will be quicker, and surely it will slow down all other subshell spawns.</p>
  
  <p>3) I'm very open to other suggestions, I've tried piping to while statements rather than calling subshells but then remembered this has the same issues.</p>
  
  <p>e.g.</p>
  
  <pre><code>    result=$(call_procedure "$get_sell_price_old_sql")
  </code></pre>
  
  <p>versus</p>
  
  <pre><code>    call_procedure "$get_sell_price_old_sql" | while read result_
      do
              result=$result_
      done
  </code></pre>
  
  <p>4) I'm sure there are other avenues I've not considered, any advice and suggestions greatly appreciated.</p>
  
  <p>Many thanks,
  Mitch.</p>