Re: Deadlock error in INSERT statements

From: Csaba Nagy <nagy(at)ecircle-ag(dot)com>
To: Gnanam <gnanam(at)zoniac(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Deadlock error in INSERT statements
Date: 2009-10-07 15:08:45
Message-ID: 1254928125.3372.435.camel@pcd12478
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, 2009-10-07 at 16:34 +0200, Gnanam wrote:
> NOTE: I've seen "deadlock" errors in UPDATE statement but why it is throwing
> in INSERT statements.

It is because of the foreign key. Inserting a child row will lock the
corresponding parent row, and if you insert multiple rows with different
parents in the same transaction, and do that in different concurrent
transactions but in different order of the parent rows, you can get a
deadlock. If you keep in mind that the parent row is locked on the
insert of a child row, you will figure out what's happening...

BTW, I don't think the "hackers" list is the right one for this kind of
question, better use the "general" list...

Cheers,
Csaba.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Joshua Tolley 2009-10-07 15:24:23 Re: Feature Suggestion: PL/Js
Previous Message Robert Haas 2009-10-07 14:56:55 Re: Deadlock error in INSERT statements