Re: table_open/table_close with different lock mode

From: Gurjeet Singh <gurjeet(at)singh(dot)im>
To: Junwang Zhao <zhjwpku(at)gmail(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: table_open/table_close with different lock mode
Date: 2023-07-21 06:56:49
Message-ID: CABwTF4XD5SVF_OV=dqSSjYhShv+kPtzH=NHTv0JPABg6Rdv1RA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jul 20, 2023 at 11:38 PM Junwang Zhao <zhjwpku(at)gmail(dot)com> wrote:
>
> On Fri, Jul 21, 2023 at 2:26 PM Michael Paquier <michael(at)paquier(dot)xyz> wrote:
> >
> > On Fri, Jul 21, 2023 at 02:05:56PM +0800, Junwang Zhao wrote:
> > > I noticed there are some places calling table_open with
> > > RowExclusiveLock but table_close with NoLock, like in function
> > > toast_save_datum.
> > >
> > > Can anybody explain the underlying logic, thanks in advance.
> >
> > This rings a bell. This is a wanted behavior, see commit f99870d and
> > its related thread:
> > https://postgr.es/m/17268-d2fb426e0895abd4@postgresql.org
> >
>
> I see this patch, so all the locks held by a transaction will be released
> at the commit phase, right? Can you show me where the logic is located?

The NoLock is simple a marker that tells the underlying machinery to
not bother releasing any locks. As a matter of fact, you can pass
NoLock in *_open() calls, too, to indicate that you don't want any new
locks, perhaps because the transaction has already taken an
appropriate lock on the object.

As for lock-releasing codepath at transaction end, see
CommitTransaction() in xact.c, and specifically at the
ResourceOwnerRelease() calls in there.

Best regards,
Gurjeet
http://Gurje.et

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Junwang Zhao 2023-07-21 07:01:59 Re: table_open/table_close with different lock mode
Previous Message Bharath Rupireddy 2023-07-21 06:51:57 Re: Support worker_spi to execute the function dynamically.