diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c new file mode 100644 index 9a758bd..1e953f3 *** a/src/backend/storage/lmgr/proc.c --- b/src/backend/storage/lmgr/proc.c *************** int StatementTimeout = 0; *** 60,65 **** --- 60,66 ---- int LockTimeout = 0; int IdleInTransactionSessionTimeout = 0; bool log_lock_waits = false; + bool notice_lock_waits = false; /* Pointer to this process's PGPROC and PGXACT structs, if any */ PGPROC *MyProc = NULL; *************** ProcSleep(LOCALLOCK *locallock, LockMeth *** 1307,1313 **** * If awoken after the deadlock check interrupt has run, and * log_lock_waits is on, then report about the wait. */ ! if (log_lock_waits && deadlock_state != DS_NOT_YET_CHECKED) { StringInfoData buf, lock_waiters_sbuf, --- 1308,1314 ---- * If awoken after the deadlock check interrupt has run, and * log_lock_waits is on, then report about the wait. */ ! if ((log_lock_waits || notice_lock_waits) && deadlock_state != DS_NOT_YET_CHECKED) { StringInfoData buf, lock_waiters_sbuf, *************** ProcSleep(LOCALLOCK *locallock, LockMeth *** 1389,1394 **** --- 1390,1410 ---- LWLockRelease(partitionLock); + if (notice_lock_waits && myWaitStatus == STATUS_WAITING) + ereport(NOTICE, + (errmsg("process %d still waiting for %s on %s after %ld.%03d ms", + MyProcPid, modename, buf.data, msecs, usecs), + (errdetail_log_plural("Process holding the lock: %s. Wait queue: %s.", + "Processes holding the lock: %s. Wait queue: %s.", + lockHoldersNum, lock_holders_sbuf.data, lock_waiters_sbuf.data)))); + + if (notice_lock_waits && myWaitStatus == STATUS_OK) + ereport(NOTICE, + (errmsg("process %d acquired %s on %s after %ld.%03d ms", + MyProcPid, modename, buf.data, msecs, usecs))); + + if (!log_lock_waits) continue; + if (deadlock_state == DS_SOFT_DEADLOCK) ereport(LOG, (errmsg("process %d avoided deadlock for %s on %s by rearranging queue order after %ld.%03d ms", diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c new file mode 100644 index 9c93df0..f390035 *** a/src/backend/utils/misc/guc.c --- b/src/backend/utils/misc/guc.c *************** static struct config_bool ConfigureNames *** 1289,1294 **** --- 1289,1304 ---- }, { + {"notice_lock_waits", PGC_SUSET, LOGGING_WHAT, + gettext_noop("Issues NOTICES for long lock waits."), + NULL + }, + ¬ice_lock_waits, + false, + NULL, NULL, NULL + }, + + { {"log_hostname", PGC_SIGHUP, LOGGING_WHAT, gettext_noop("Logs the host name in the connection logs."), gettext_noop("By default, connection logs only show the IP address " diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h new file mode 100644 index 775c66a..9e06ffc *** a/src/include/storage/proc.h --- b/src/include/storage/proc.h *************** extern int StatementTimeout; *** 260,265 **** --- 260,266 ---- extern int LockTimeout; extern int IdleInTransactionSessionTimeout; extern bool log_lock_waits; + extern bool notice_lock_waits; /*