pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joseph Shraibman <jks@selectacast.net>
To: pgsql-general@hub.org <pgsql-general@hub.org>
Subject: select for update not locking properly.
Date: Wed, 12 Jul 2000 22:35:22 -0400
Message-ID: <396D2AEA.5D19984A@selectacast.net> (raw)

I have a program that does this:
BEGIN;
SELECT mystring FROM mytable WHERE x = 3 AND y = 4 FOR UPDATE;
<my program takes mystring and appends to it>
UPDATE mytable SET mystring = '<appended string here>' WHERE x = 3 AND y
= 4;
END;

But the locking isn't working properly.  I do something that should
cause 3 different threads to try and do that append, and the first one
goes through properly, but the second two append to the result of the
first on only, meaning that the third one didn't see the result of the
second's append.

I tried to make a simple example that reproduced this, but failed.

I'm guessing that the value of that the select is generated before the
row is locked, and thus each of my last two threads saw the table after
the first append, *then* one of them blocked because the other had
locked the table. It's the only thing I can figure.



view thread (6+ messages)  latest in thread

Message-ID: <396D2AEA.5D19984A@selectacast.net>
Permalink:  ../396D2AEA.5D19984A@selectacast.net/
Also on:    postgresql.org/message-id/396D2AEA.5D19984A@selectacast.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: jks@selectacast.net, pgsql-general@hub.org
  Subject: Re: select for update not locking properly.
  In-Reply-To: <396D2AEA.5D19984A@selectacast.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox