diff options
| author | Fujii Masao | 2025-03-14 14:14:12 +0000 |
|---|---|---|
| committer | Fujii Masao | 2025-03-14 14:14:12 +0000 |
| commit | 6d376c3b0d1e79c318d2a1c04097025784e28377 (patch) | |
| tree | d1ed6941bfa91892223567b1aa2659a31abc660f /src/include | |
| parent | e80171d57c25caf4362a7de17e96195f905386ea (diff) | |
Add GUC option to log lock acquisition failures.
This commit introduces a new GUC, log_lock_failure, which controls whether
a detailed log message is produced when a lock acquisition fails. Currently,
it only supports logging lock failures caused by SELECT ... NOWAIT.
The log message includes information about all processes holding or
waiting for the lock that couldn't be acquired, helping users analyze and
diagnose the causes of lock failures.
Currently, this option does not log failures from SELECT ... SKIP LOCKED,
as that could generate excessive log messages if many locks are skipped,
causing unnecessary noise.
This mechanism can be extended in the future to support for logging
lock failures from other commands, such as LOCK TABLE ... NOWAIT.
Author: Yuki Seino <seinoyu@oss.nttdata.com>
Co-authored-by: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Jelte Fennema-Nio <postgres@jeltef.nl>
Discussion: https://postgr.es/m/411280a186cc26ef7034e0f2dfe54131@oss.nttdata.com
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/storage/lmgr.h | 5 | ||||
| -rw-r--r-- | src/include/storage/lock.h | 4 | ||||
| -rw-r--r-- | src/include/storage/proc.h | 4 |
3 files changed, 10 insertions, 3 deletions
diff --git a/src/include/storage/lmgr.h b/src/include/storage/lmgr.h index 728260c1cc0..58eee4e0d54 100644 --- a/src/include/storage/lmgr.h +++ b/src/include/storage/lmgr.h @@ -73,7 +73,7 @@ extern void UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode); /* Lock a tuple (see heap_lock_tuple before assuming you understand this) */ extern void LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode); extern bool ConditionalLockTuple(Relation relation, ItemPointer tid, - LOCKMODE lockmode); + LOCKMODE lockmode, bool logLockFailure); extern void UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode); /* Lock an XID (used to wait for a transaction to finish) */ @@ -81,7 +81,8 @@ extern void XactLockTableInsert(TransactionId xid); extern void XactLockTableDelete(TransactionId xid); extern void XactLockTableWait(TransactionId xid, Relation rel, ItemPointer ctid, XLTW_Oper oper); -extern bool ConditionalXactLockTableWait(TransactionId xid); +extern bool ConditionalXactLockTableWait(TransactionId xid, + bool logLockFailure); /* Lock VXIDs, specified by conflicting locktags */ extern void WaitForLockers(LOCKTAG heaplocktag, LOCKMODE lockmode, bool progress); diff --git a/src/include/storage/lock.h b/src/include/storage/lock.h index c0c0b0f7a2d..ad4e40badbe 100644 --- a/src/include/storage/lock.h +++ b/src/include/storage/lock.h @@ -30,6 +30,7 @@ typedef struct PGPROC PGPROC; /* GUC variables */ extern PGDLLIMPORT int max_locks_per_xact; +extern PGDLLIMPORT bool log_lock_failure; #ifdef LOCK_DEBUG extern PGDLLIMPORT int Trace_lock_oidmin; @@ -560,7 +561,8 @@ extern LockAcquireResult LockAcquireExtended(const LOCKTAG *locktag, bool sessionLock, bool dontWait, bool reportMemoryError, - LOCALLOCK **locallockp); + LOCALLOCK **locallockp, + bool logLockFailure); extern void AbortStrongLockAcquire(void); extern void MarkLockClear(LOCALLOCK *locallock); extern bool LockRelease(const LOCKTAG *locktag, diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 114eb1f8f76..0750ec3c474 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -489,6 +489,10 @@ extern void ProcWakeup(PGPROC *proc, ProcWaitStatus waitStatus); extern void ProcLockWakeup(LockMethod lockMethodTable, LOCK *lock); extern void CheckDeadLockAlert(void); extern void LockErrorCleanup(void); +extern void GetLockHoldersAndWaiters(LOCALLOCK *locallock, + StringInfo lock_holders_sbuf, + StringInfo lock_waiters_sbuf, + int *lockHoldersNum); extern void ProcWaitForSignal(uint32 wait_event_info); extern void ProcSendSignal(ProcNumber procNumber); |
