Re: Question Regarding Locks - Mailing list pgsql-general

From Karsten Hilbert
Subject Re: Question Regarding Locks
Date
Msg-id 20041029092242.D624@hermes.hilbert.loc
Whole thread Raw
In response to Re: Question Regarding Locks  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Question Regarding Locks  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-general
> > begin;
> >     select ... for update;
> >     update ... set ... where
> >     my_pk=<my_pk_value>
> >         AND
> >     xmin=<the_old_xmin>
>
> I think you can skip the SELECT FOR UPDATE altogether if you do it that
> way.  Otherwise it looks fine.
Except that there will be other clients accessing those rows,
too, of which I cannot be sure that they employ the same (or
even adequate) locking procedures. So I should still lock the
row for good measure, right ?

The docs say that XMIN is the transaction ID of the *inserting*
transaction for this row version. IOW updates will change XMIN.
Will XMIN also be changed by a *deleting* transaction ? I guess
it depends on how deletion is handled: Either the *unchanged*
row version is marked as deleted (hence XMIN would not change)
OR a new row version is created and marked deleted (which would
indeed change xmin).

IOW, can I also detect my row being *deleted* from under me by
another transation by way of checking XMIN ? Else I would
likely need to check XMAX, too.

Thanks for your help,

Karsten Hilbert, MD
http://www.gnumed.org
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346

pgsql-general by date:

Previous
From: Stuart Bishop
Date:
Subject: Re: Comment on timezone and interval types
Next
From: Martijn van Oosterhout
Date:
Subject: Re: Question Regarding Locks