Prevent stale pg_locks.waitstart values Previously, pg_locks.waitstart could report the start time of a previous lock wait for a new wait. For a regular backend, this could happen briefly before the new start time was stored. On a standby, the startup process could show the old time throughout the next wait, making it appear to have started earlier than it did.
This happened because PGPROC->waitStart could remain set after a previous wait in two cases. First, RemoveFromWaitQueue() did not clear it when a wait was canceled due to a lock timeout, cancellation, or deadlock. Second, even after a successful lock grant, ProcWakeup() could clear it before the waiter stored its new start time. Fix this by clearing waitStart in RemoveFromWaitQueue() when a failed wait is removed, at the end of ProcSleep() to handle writes made after ProcWakeup() cleared it, and in LockErrorCleanup() when an error bypasses the ProcSleep() reset. This prevents pg_locks.waitstart from showing the previous wait's time for a new wait. Backpatch to all supported versions. Author: Shihao Zhong <[email protected]> Reported-by: Alex Shapalov <[email protected]> Reviewed-by: Chao Li <[email protected]> Reviewed-by: Michael Paquier <[email protected]> Reviewed-by: Fujii Masao <[email protected]> Reviewed-by: Andrew Krylosov <[email protected]> Discussion: https://postgr.es/m/CAPrb+Q+XN=snusxiuewmmo2h7qgq3y4upeksslkhcncyf7g...@mail.gmail.com Discussion: https://postgr.es/m/cagrkxqqlxzbr-ouvrtax2utmggi4+tivmbgh04b_0jlgkry...@mail.gmail.com Backpatch-through: 14 Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/6f2f510845c522fc5d57a05cabc492fce3ff23bb Modified Files -------------- src/backend/storage/lmgr/lock.c | 1 + src/backend/storage/lmgr/proc.c | 9 +++++++++ 2 files changed, 10 insertions(+)
