From: | Bill Moran <wmoran(at)potentialtech(dot)com> |
---|---|
To: | <tom(at)tacocat(dot)net> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: DeadLocks..., DeadLocks... |
Date: | 2007-06-14 16:30:59 |
Message-ID: | 20070614123059.838a116d.wmoran@potentialtech.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
In response to <tom(at)tacocat(dot)net>:
>
> On 6/14/2007, "Gregory Stark" <stark(at)enterprisedb(dot)com> wrote:
>
> >
> >
> ><tom(at)tacocat(dot)net> writes:
> >
> >> But everyone once in a long while it seems that I hit simultaneaous
> >> execute() statements that deadlock on the insertion.
> >
> >What version of Postgres is this and do you have any foreign key constraints
> >or triggers on the table you're inserting into?
>
> Version 8.2
> This table does not have foreign key constraints on it, but it is the
> source of foreign key constraints on other tables.
> No triggers.
>
> Is that insert the *only* DML
> >you're executing? No updates or deletes?
>
> At the time of the failure, no other DML.
> There are other's but they are on different tables.
> >
> >What do you mean by saying it deadlocks? Do you get a transaction abort with
> >an error about a deadlock detected? Or do you just mean it freezes?
>
> "deadlock detected"
> And the corresponding error I get is a primary key violation on the same
> table.
>
>
> The problem occurs when I have multiple processes acting on what appears
> to be the exact same set of information. I can't really control the
> issue of simultaneous/parallel processing
Put an "ORDER BY" in your SELECT.
I believe the problem is that when this runs from two different places,
the DB may order the returned values in a different order for each one,
which leads to the possibility of two similar inserts deadlocking. Unless
I misunderstand your schema, you should be able to guarantee against
deadlocking by guaranteeing that the SELECT portion will always return
rows in the same order.
--
Bill Moran
http://www.potentialtech.com
From | Date | Subject | |
---|---|---|---|
Next Message | Rikard Pavelic | 2007-06-14 16:44:42 | explain analyze on a function |
Previous Message | Greg Smith | 2007-06-14 16:05:26 | Re: pg_xlog - files are guaranteed to be sequentialy named? |