Re: Is it OK to perform logging while holding a LWLock? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Is it OK to perform logging while holding a LWLock?
Date
Msg-id 4006831.1770779994@sss.pgh.pa.us
Whole thread Raw
In response to Is it OK to perform logging while holding a LWLock?  (Chao Li <li.evan.chao@gmail.com>)
Responses Re: Is it OK to perform logging while holding a LWLock?
Re: Is it OK to perform logging while holding a LWLock?
List pgsql-hackers
Chao Li <li.evan.chao@gmail.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



pgsql-hackers by date:

Previous
From: Chao Li
Date:
Subject: Re: Little cleanup: Move ProcStructLock to the ProcGlobal struct
Next
From: shveta malik
Date:
Subject: Re: [PATCH] Support automatic sequence replication