Re: questions about concurrency control in Postgresql - Mailing list pgsql-hackers

From Greg Stark
Subject Re: questions about concurrency control in Postgresql
Date
Msg-id 407d949e0912080416vd8377c8pb6877d64254138fb@mail.gmail.com
Whole thread Raw
In response to questions about concurrency control in Postgresql  (黄晓骋 <huangxclife@gmail.com>)
Responses 答复: questions about concurrency control in Postgresql  (黄晓骋 <huangxclife@gmail.com>)
答复: questions about concurrency control in Postgresql  (黄晓骋 <huangxclife@gmail.com>)
List pgsql-hackers
2009/12/8 黄晓骋 <huangxclife@gmail.com>:
> From the above, I think the tuple lock is unnecessary, because it uses
> transaction lock.
>
> Besides, tuple lock is unlocked after the tuple is updated but not after the
> transaction commits. I mean it's not 2PL.

It's a two step process. An update marks the tuple locked. Another
transaction which comes along and wants to lock the tuple waits on the
transaction marked on the tuple. When the first transaction commits or
aborts then the second transaction can proceed and lock the tuple
itself. The reason we need both locks is because the first transaction
cannot go around the whole database finding every tuple it ever locked
to unlock it, firstly that could be a very large list and secondly
there would be no way to do that atomically.

Tuple locks and all user-visible locks are indeed held until the end
of the transaction.

--
greg


pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: Streaming replication, some small issues
Next
From: Tim Bunce
Date:
Subject: Re: YAML