title: node-postgres with massive amount of queries
body: <p>I just started playing around with node.js with postgres, using node-postgres. One of the things I tried to do is to write a short js to populate my database, using a file with about 200,000 entries.</p>
  
  <p>I noticed that after sometime (less than 10 seconds), I start to get "Error: Connection terminated". I am not sure whether this is problem with how I use node-postgres, or if it's because I was spamming postgres. </p>
  
  <p>Anyway, here is a simple code that shows this behaviour:</p>
  
  <pre><code>var pg = require('pg');
  var connectionString = "postgres://xxxx:xxxx@localhost/xxxx";
  
  pg.connect(connectionString, function(err,client,done){
    if(err) {
      return console.error('could not connect to postgres', err);
    }
  
    client.query("DROP TABLE IF EXISTS testDB");
    client.query("CREATE TABLE IF NOT EXISTS testDB (id int, first int, second int)");
    done();
  
    for (i = 0; i &lt; 1000000; i++){
      client.query("INSERT INTO testDB VALUES (" + i.toString() + "," + (1000000-i).toString() + "," + (-i).toString() + ")",   function(err,result){
        if (err) {
           return console.error('Error inserting query', err);
        }
        done();
      });
    }
  });
  </code></pre>
  
  <p>It fails after about 18,000-20,000 queries. Is this the wrong way to use client.query? I tried changing the default client number, but it didn't seem to help. </p>
  
  <p>client.connect() doesn't seem to help either, but that was because I had too many clients, so I definitely think client pooling is the way to go. </p>
  
  <p>Thanks for any help!</p>