From 39384ef9cd915e6cfca7ab3bfa26803d3de6f8fa Mon Sep 17 00:00:00 2001 From: Fujii Masao Date: Fri, 14 Mar 2025 23:58:00 +0900 Subject: [PATCH] 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 f923ca13a744..eec4bb65e54d 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -7856,7 +7856,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 SELECT NOWAIT is supported. + caused by NOWAIT, such as in + SELECT ... NOWAIT or + LOCK TABLE ... NOWAIT, are supported. The default is off. Only superusers and users with the appropriate SET privilege can change this setting. diff --git a/src/backend/storage/lmgr/lmgr.c b/src/backend/storage/lmgr/lmgr.c index f50962983c37..b5de5394b1e1 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;