Re: Weird locking situation - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Weird locking situation
Date
Msg-id 26968.1065105058@sss.pgh.pa.us
Whole thread Raw
In response to Weird locking situation  (Christopher Kings-Lynne <chriskl@familyhealth.com.au>)
Responses Re: Weird locking situation  (Hannu Krosing <hannu@tm.ee>)
Re: Weird locking situation  (Christopher Kings-Lynne <chriskl@familyhealth.com.au>)
List pgsql-hackers
Christopher Kings-Lynne <chriskl@familyhealth.com.au> writes:
> What is going on here?  Surely getting a FOR UPDATE row lock should 
> prevent another process getting an update lock?

I could not duplicate your results.  I did

regression=# create table tab(id int , blah int);
CREATE TABLE
regression=# insert into tab values(1,1);
INSERT 320558 1
regression=# insert into tab values(1,2);
INSERT 320559 1
regression=# insert into tab values(2,3);
INSERT 320560 1
regression=# BEGIN;
BEGIN
regression=# SELECT * FROM tab WHERE id=1 FOR UPDATE;id | blah
----+------ 1 |    1 1 |    2
(2 rows)

<< in another window >>

regression=# UPDATE tab SET blah=1 WHERE id=1;
[waits]

<< back to first window >>

regression=# UPDATE tab SET blah=1 WHERE id=1;
UPDATE 2
regression=# end;
COMMIT

<< second window now reports >>

UPDATE 2
regression=#

The behavior you describe would certainly be a bug, but you'll have to
show a reproducible example to convince me it wasn't pilot error.  One
idea that springs to mind is that maybe additional rows with id=1 were
inserted (by some other transaction) between the SELECT FOR UPDATE and
the UPDATE?
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: minor view creation weirdness
Next
From: Hannu Krosing
Date:
Subject: Re: Weird locking situation