title: Database connection pooling for R parallel process
body: <p>I have a database connection to <code>PostgreSQL</code> using the package <code>RPostgreSQL</code>. Currently I do the following:</p>
  
  <ol>
  <li>retrieve a list from my database</li>
  <li>run the list through a for loop, doing a calculation and writing the value back to the database</li>
  </ol>
  
  <p>I am interested in parallelising this process. The obvious is to use the <code>foreach</code> functionality in the package of the same name. However, we need to use connection pooling: In this case I am interested if anyone knows a parallel backend which I can use to share my database connection. Here is a specific unresolved example:</p>
  
  <p><a href="https://stackoverflow.com/questions/3902796/foreach-dopar-rpostgresql">foreach %dopar% + RPostgreSQL</a></p>
  
  <p>In the above case there is no connection pooling in the <code>registerDoMC</code> parallel backend, with the work around to open and close the connection within each <code>dopar</code> worker. Looking at the <code>registerDoSnow</code> parallel backend from the <code>snow</code> package also does not give this functionality.</p>
  
  <p>The alternative would be to use <code>mclapply</code> instead of <code>dopar</code>. In this case, does anyone know whether or how to share the database connection with each <code>mclapply</code> worker?</p>