Re: Lock rekord - Mailing list pgsql-general

From Herbert Liechti
Subject Re: Lock rekord
Date
Msg-id 394BB253.63E7A42@thinx.ch
Whole thread Raw
In response to Lock rekord  (Pawe³ Dubin <paweld@suimed.tpnet.pl>)
Responses RE: Lock rekord  ("Andrew Snow" <als@fl.net.au>)
List pgsql-general
"Pawe³ Dubin" wrote:

> Hello
>
> I was listening Your discusion. I have practical problem for which I write my
> own locking system:
>
> Now A change zip and write all
> B change adress and write
>
> so zip is unchanged.
>
> In pgsql I can solve it by SELECT FOR UPDATE but if user A goes for caffe
> during his update
> user B hangs for several minutes ...
>
> Ther is no solution to check if record is in transaction ?

I usually prefer the following trick for preventing long locking times. On every
table I define a timestamp field which is updated every time the record is
written to the database. If a user edits a record (without locking) and commit his changes
the timestamp is returned from the client program unchanged. The program
reads the record again for update and compares the timestamp from the database
and the timestamp from the user program.  If the timestamp has changed
in the meantime the record was updated from someone else and the
transaction will be rejected.

Regards Herbie

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Herbert Liechti                     E-Mail: Herbert.Liechti@thinx.ch
ThinX networked business services        Stahlrain 10, CH-5200 Brugg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




pgsql-general by date:

Previous
From: Trurl McByte
Date:
Subject: Re: copying table to a file
Next
From: "Andrew Snow"
Date:
Subject: RE: Lock rekord