title: django.db.utils.DatabaseError: out of shared memory
body: <p>I'm written a script to load some objects into a Django database using the Django ORM. The underlying database is Postgres. </p>
  
  <p>After running happily for a while, the script fails with this error: </p>
  
  <pre><code>django.db.utils.DatabaseError: out of shared memory
  HINT: You might need to increase max_locks_per_transaction.
  </code></pre>
  
  <p>I'm guessing this is a problem with my script's efficiency, rather than the database settings. </p>
  
  <p>The script iterates over a CSV file, and create a database object for every row in the CSV file. Typically there are a couple thousand objects to create. I've read <a href="http://www.slideshare.net/OReillyOSCON/unbreaking-your-django-application" rel="nofollow">some background material on database efficiency in Django</a>. I can rule out some mistakes - I'm not iterating over a queryset, or using <code>__in</code> queries or <code>OFFSET</code>.</p>
  
  <p>But I do have quite a lot of indexes on fields in my database, and I guess that each time I create and save an object, Django has to update all the indexes. I have six indexes on the <code>StoreItem</code> fields, for example. </p>
  
  <pre><code>for item in csv_rows: 
    s, created = StoreItem.objects.get_or_create(display_url=item['display_url'], \
           retailer_img_url=item['retailer_img_url'],store=store_obj)
    s.name = item['name']
    s.description = item['description']
    s.affiliate = item['affiliate']
    ... more stuff
    s.save()
  </code></pre>
  
  <p>Two questions: </p>
  
  <ol>
  <li>Is it possible that updating the database indexes could cause this error?</li>
  <li>How can I debug if this is the case?</li>
  </ol>