From 64d44806c1d6e18c9a239984c6b71bc1dd574742 Mon Sep 17 00:00:00 2001 From: Fujii Masao 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 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 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