Re: Foreign key deadlocks

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Csaba Nagy <nagy(at)domeus(dot)de>
Cc: "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Foreign key deadlocks
Date: 2002-11-08 17:28:28
Message-ID: 20021108092307.E12246-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 8 Nov 2002, Csaba Nagy wrote:

> I'm currently porting an application from Oracle to Postgres.
> Most of the things are working fine, but I still couldn't sort the problems
> with foreign keys.
> When creating the foreign key constraints as they are in the Oracle schema,
> the application deadlocks quite often.
> The reason is AFAICT the update lock placed on the referenced row when
> inserting in a table with foreign key constraints.
Yes, that lock is too strong.

> I can't believe this is a deliberate way to handle row locks, it just
> doesn't make sense. Am I missing some crucial design issue which makes the
> shared row locks impossible ?
The fact that AFAICT there isn't a way to get a shared row lock through
an sql statement right now in PostgreSQL. The locking is there to make
the constraint not allow things through that shouldn't.

> Is there any guidline about how to solve this ? Rewriting the code is not an
> option, it relies too heavily on how foreign key constraints work in Oracle.

Depending on your needs for timing, I've been working (only partially
successfully) at lowering the number of deadlocks in the foreign key
stuff. It's currently only as a patch to 7.3b2 (I've got to update to
most recent soon) and is not nearly production ready, but if you've got
development time, we could use help testing it.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Medi Montaseri 2002-11-08 18:31:20 Re: table growing
Previous Message Stephan Szabo 2002-11-08 17:22:30 Re: two table foreign keys