Re: [HACKERS] It sorta works, but I'm confused about locking - Mailing list pgsql-hackers

From Vadim Mikheev
Subject Re: [HACKERS] It sorta works, but I'm confused about locking
Date
Msg-id 36142A59.311E12C9@krs.ru
Whole thread Raw
In response to Re: [HACKERS] It sorta works, but I'm confused about locking  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [HACKERS] It sorta works, but I'm confused about locking
List pgsql-hackers
Tom Lane wrote:
>
> > I can imagine some cases where you would want to get a lock and keep it
> > until the end of the transaction, and other times when you would want to
> > release it before transaction end.
>
> I guess I'm not understanding something.  How can it ever be correct
> practice to release a lock before transaction end?  For example, if I
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Postgres does this for system tables only.

> write some changes in a table, and then release the lock, wouldn't that
> allow other backends to see the not-yet-committed changes?  What if I
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
No. Backend uses xmin/xmax to know is tuple visible or not.

> then abort my transaction?  Now the other backends have acted on
> information they should never have seen at all.

Backend will see that xmin(xmax) is not committed.

Vadim

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [HACKERS] Proper cleanup at backend exit
Next
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] rules ON SELECT