Re: Fix FK deadlock, but no magic please

From: Jon Swinth <jswinth(at)atomicpc(dot)com>
To: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Fix FK deadlock, but no magic please
Date: 2003-01-16 23:05:50
Message-ID: 200301161505.50801.jswinth@atomicpc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Now I understand what you are trying to say, but what you are describing is
normal (happens in most DBs) and rather uncommon (in my experience). General
DB design is done so reference tables end up with a lot of read locks and
rarely have a write lock. It would be cool if you could remove that
contention, but not at the expense of expected write lock behaivor.

On Thursday 16 January 2003 02:43 pm, Stephan Szabo wrote:
> AFAICT, what you want is a sequence like the below (including lock
> annotations) for the above.
>
> Transaction 1: begin;
> Transaction 2: begin;
> Transaction 1: insert into fk values (1);
> - Checks pk table for value, finds it, gets a read lock
> Transaction 2: insert into fk values (2);
> - Checks pk table for value, finds it, gets a read lock
> Transaction 1: update pk set nonkey='a' where key=2;
> - Wants a write lock on row with pk.key=2, can't get it because
> Transaction 2 has a read lock. It has to wait.
> Transaction 2: update pk set nonkey='a' where key=1;
> - Wants a write lock on row with pk.key=1, can't get it because
> Transaction 1 has a read lock. It has to wait.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2003-01-16 23:31:49 Re: Fix FK deadlock, but no magic please
Previous Message Stephan Szabo 2003-01-16 22:43:31 Re: Fix FK deadlock, but no magic please