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 <zhong950419@gmail.com> Reported-by: Alex Shapalov <shapalov@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Fujii Masao <masao.fujii@gmail.com> Reviewed-by: Andrew Krylosov <krylosov.andrew@gmail.com> Discussion: https://postgr.es/m/CAPrb+Q+XN=sNusXiUeWmMo2H7Qgq3Y4uPekSSLkHcnCyf7GhXg@mail.gmail.com Discussion: https://postgr.es/m/CAGRkXqQLxZBr-ouVrtaX2utMggi4+TiVMbgH04b_0JLgKryxbA@mail.gmail.com Backpatch-through: 14
PostgreSQL Database Management System
This directory contains the source code distribution of the PostgreSQL database management system.
PostgreSQL is an advanced object-relational database management system that supports an extended subset of the SQL standard, including transactions, foreign keys, subqueries, triggers, user-defined types and functions. This distribution also contains C language bindings.
Copyright and license information can be found in the file COPYRIGHT.
General documentation about this version of PostgreSQL can be found at https://www.postgresql.org/docs/19/. In particular, information about building PostgreSQL from the source code can be found at https://www.postgresql.org/docs/19/installation.html.
The latest version of this software, and related software, may be obtained at https://www.postgresql.org/download/. For more information look at our web site located at https://www.postgresql.org/.