Re: Is it OK to perform logging while holding a LWLock?

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Is it OK to perform logging while holding a LWLock?
Date: 2026-02-12 01:07:08
Message-ID: F92D5A64-8AEB-4E82-855A-D1870307DAC8@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Feb 11, 2026, at 11:19, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> writes:
>> As $SUBJECT says, my understanding is no.
>
> It's not a great idea, but I'm not sure it's fatal. There are places
> that hold LWLocks for awhile.
>
>> I think LWLocks are generally only held for a very short duration,
>> like a few CPU cycles to read or modify some shared data,
>
> Spinlocks are treated that way, but we're willing to hold LWLocks
> longer. The main thing I'd be concerned about is that there is no
> deadlock-detection infrastructure for LWLocks, so you'd better be
> darn certain there is no possibility of deadlock. That usually
> means you want to limit the extent of code that could run while
> you're holding the lock.
>
> In your specific example, the thing I'd be afraid of is that an
> errcontext callback might do something you're not expecting.
> We don't forbid errcontext callbacks from doing catalog lookups,
> for instance. So on the whole I agree with this patch, with
> or without any concrete example that fails.
>
> regards, tom lane

As Tom has agreed with this patch, added to CF for tracking: https://commitfest.postgresql.org/patch/6477/

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tatsuo Ishii 2026-02-12 01:17:01 Re: Row pattern recognition
Previous Message wangpeng 2026-02-12 00:59:13 Re: Fix wrong log in pgstat_report_checksum_failures_in_db()