mirror of
https://github.com/postgres/postgres.git
synced 2025-10-25 13:17:41 +03:00
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
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user