Parallel insert to postgresql with thread

Erik Jones erik at myemma.com
Thu Oct 25 14:06:41 EDT 2007


On Oct 25, 2007, at 10:12 AM, Jean-Paul Calderone wrote:

> On Thu, 25 Oct 2007 09:46:54 -0500, Erik Jones <erik at myemma.com>  
> wrote:
>>
>> [snip]
>>
>> Fortunately, in his case, that's not necessarily true.  If they do
>> all their work with the same connection then, yes, but there are
>> other problems with that as mention wrt thread safety and psycopg2.
>> If he goes the recommended route with a separate connection for each
>> thread, then Postgres will not serialize multiple inserts coming from
>> separate connections unless there is something like and ALTER TABLE
>> or REINDEX concurrently happening on the table.  The whole serialized
>> inserts thing is strictly something popularized by MySQL and is by no
>> means necessary or standard (as with a lot of MySQL).
>
> PostgreSQL won't serialize inserts to the same table with a sequence
> column?  Wow. :)

No, because sequences are separate relations that are transaction- 
safe, which is Postgres multi-process/session version of thread  
safe.  To be more specific, there's really no such thing as a  
"sequence column" in Postgres.  I wan't go into more detail here  
since this is a Python list, but if you want more info check out the  
Postges site and manual, the mailing lists, or respond directly to me  
if you just want to know how this particular bit works better.

Erik Jones

Software Developer | Emma®
erik at myemma.com
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com





More information about the Python-list mailing list