On 2025/03/11 22:24, Fujii Masao wrote:
On 2025/03/11 16:50, Yuki Seino wrote:
Instead, wouldn't it be simpler to update LockAcquireExtended() to
take a new argument, like logLockFailure, to control whether
a lock failure should be logged directly? I’ve adjusted the patch
accordingly and attached it. Please let me know what you think!
Regards,
Thank you!
It's very simple and nice.
It seems like it can also handle other lock failure cases by extending
logLockFailure.
> I agree with this propose.
Thanks for reviewing the patch!
I've made some minor cosmetic adjustments. The updated patch is attached.
Unless there are any objections, I'll proceed with committing it.
Pushed the patch. Thanks!
Using the newly introduced mechanism, we can now easily extend
the log_lock_failure GUC to support additional NOWAIT lock failures,
such as LOCK TABLE ... NOWAIT, ALTER TABLE ... NOWAIT,
ALTER MATERIALIZED VIEW ... NOWAIT, and ALTER INDEX ... NOWAIT.
I've attached a patch implementing this.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
From 64d44806c1d6e18c9a239984c6b71bc1dd574742 Mon Sep 17 00:00:00 2001
From: Fujii Masao <fu...@postgresql.org>
Date: Fri, 14 Mar 2025 23:58:00 +0900
Subject: [PATCH v1] Extend log_lock_failure GUC to support more NOWAIT lock
failures.
Commit 6d376c3b0d1 introduced the log_lock_failure GUC to control
whether a detailed log message is generated when a lock acquisition fails.
Initially, it only supported logging failures from SELECT ... NOWAIT.
This commit extends the feature to log lock failures from other NOWAIT
operations, including LOCK TABLE ... NOWAIT, ALTER TABLE ... NOWAIT,
ALTER MATERIALIZED VIEW ... NOWAIT, and ALTER INDEX ... NOWAIT.
---
doc/src/sgml/config.sgml | 4 +++-
src/backend/storage/lmgr/lmgr.c | 2 +-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 3d62c8bd274..20d70c37781 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -7768,7 +7768,9 @@ log_line_prefix = '%m [%p] %q%u@%d/%a '
Controls whether a detailed log message is produced
when a lock acquisition fails. This is useful for analyzing
the causes of lock failures. Currently, only lock failures
- due to <literal>SELECT NOWAIT</literal> is supported.
+ caused by <literal>NOWAIT</literal>, such as in
+ <literal>SELECT ... NOWAIT</literal> or
+ <literal>LOCK TABLE ... NOWAIT</literal>, are supported.
The default is <literal>off</literal>. Only superusers and
users with the appropriate <literal>SET</literal> privilege
can change this setting.
diff --git a/src/backend/storage/lmgr/lmgr.c b/src/backend/storage/lmgr/lmgr.c
index f50962983c3..b5de5394b1e 100644
--- a/src/backend/storage/lmgr/lmgr.c
+++ b/src/backend/storage/lmgr/lmgr.c
@@ -157,7 +157,7 @@ ConditionalLockRelationOid(Oid relid, LOCKMODE lockmode)
SetLocktagRelationOid(&tag, relid);
res = LockAcquireExtended(&tag, lockmode, false, true, true, &locallock,
- false);
+ log_lock_failure);
if (res == LOCKACQUIRE_NOT_AVAIL)
return false;
--
2.48.1