title: Postgres - out of memory on looping insert
body: <p>I'm parsing an XML file with a few thousand elements in it for insertion into a sql database.  Everything works fine with sqlite, but postgres dies on me with this error:</p>
  
  <pre><code>PGError: ERROR:  out of shared memory
  </code></pre>
  
  <p>I was monitoring locks, and it looks like there's a lock for each insert statement, and although I'm just looping over activerecord "save" calls (which should have a transaction each) these locks seem to hang around such that I have a few thousand open at a time.</p>
  
  <p>As an experiment, I wrapped the save calls in a transaction:</p>
  
  <pre><code>Coupon.connection.transaction do  
    @coupon.save!
  end
  </code></pre>
  
  <p>And that appears to have resolved my locks issue.  However, it does seem there is something wrong here.  Anyone know what it might be? I am using the "pg" driver.</p>
  
  <p>Thanks,
  Tom</p>