pgsql: Don't hold ProcArrayLock longer than needed in rare cases

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Don't hold ProcArrayLock longer than needed in rare cases
Date: 2020-11-23 21:56:40
Message-ID: E1khJpA-0005pi-92@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Don't hold ProcArrayLock longer than needed in rare cases

While cancelling an autovacuum worker, we hold ProcArrayLock while
formatting a debugging log string. We can make this shorter by saving
the data we need to produce the message and doing the formatting outside
the locked region.

This isn't terribly critical, as it only occurs pretty rarely: when a
backend runs deadlock detection and it happens to be blocked by a
autovacuum running autovacuum. Still, there's no need to cause a hiccup
in ProcArrayLock processing, which can be very high-traffic in some
cases.

While at it, rework code so that we only print the string when it is
really going to be used, as suggested by Michael Paquier.

Discussion: https://postgr.es/m/20201118214127.GA3179@alvherre.pgsql
Reviewed-by: Michael Paquier <michael(at)paquier(dot)xyz>

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/450c8230b1f7eed1e927c44fb710d80502bea1d2

Modified Files
--------------
src/backend/storage/lmgr/proc.c | 35 ++++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2020-11-23 22:00:11 pgsql: Remove unnecessary #include.
Previous Message Tom Lane 2020-11-23 16:38:48 pgsql: Rename the "point is strictly above/below point" comparison oper