Re: lock table question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Andy Kriger" <akriger(at)greaterthanone(dot)com>
Cc: "Pgsql-General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: lock table question
Date: 2002-12-30 23:13:08
Message-ID: 24969.1041289988@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Andy Kriger" <akriger(at)greaterthanone(dot)com> writes:
> After various responses, it looks like SELECT...FOR UPDATE does fit the bill
> if I use it consistently for querying the records I'm interested in.

That's one way. Another approach to think about is to use serializable
mode for all your updating transactions (whether to use it for read-only
xacts is an orthogonal issue). If you do this, you can skip the FOR
UPDATE, but you have to be prepared to retry any such transaction from
the top if it gets a serialization failure. This is essentially an
optimistic locking approach: assume you don't need a lock, retry if
you're wrong. It will win under light row-level contention, since you
avoid all the work of marking rows FOR UPDATE. It can lose under heavy
contention if you have to retry too often, though. See past discussions
in the archives.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tommi Mäkitalo 2002-12-30 23:25:51 new c++-interface for postgresql
Previous Message Andy Kriger 2002-12-30 23:07:18 Re: lock table question