Add GUC option to log lock acquisition failures.
authorFujii Masao <fujii@postgresql.org>
Fri, 14 Mar 2025 14:14:12 +0000 (23:14 +0900)
committerFujii Masao <fujii@postgresql.org>
Fri, 14 Mar 2025 14:14:12 +0000 (23:14 +0900)
commit6d376c3b0d1e79c318d2a1c04097025784e28377
treed1ed6941bfa91892223567b1aa2659a31abc660f
parente80171d57c25caf4362a7de17e96195f905386ea
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
doc/src/sgml/config.sgml
src/backend/access/heap/heapam.c
src/backend/access/heap/heapam_handler.c
src/backend/storage/lmgr/lmgr.c
src/backend/storage/lmgr/lock.c
src/backend/storage/lmgr/proc.c
src/backend/utils/misc/guc_tables.c
src/backend/utils/misc/postgresql.conf.sample
src/include/storage/lmgr.h
src/include/storage/lock.h
src/include/storage/proc.h