Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l6ysI-00049x-Vj for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Feb 2021 16:49:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l6ysH-0002sC-Oc for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Feb 2021 16:49:57 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l6ysH-0002pI-HT for pgsql-hackers@lists.postgresql.org; Tue, 02 Feb 2021 16:49:57 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l6ysA-0000m3-LB for pgsql-hackers@postgresql.org; Tue, 02 Feb 2021 16:49:56 +0000 Received: from hnk.local (p2112118-ipbf2507funabasi.chiba.ocn.ne.jp [123.216.63.118]) by oss.nttdata.com (Postfix) with ESMTPSA id B886262403; Wed, 3 Feb 2021 01:49:46 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.3 at oss.nttdata.com Subject: Re: adding wait_start column to pg_locks To: torikoshia Cc: Ian Lawrence Barwick , Robert Haas , Justin Pryzby , pgsql-hackers References: <20210101214930.GH25152@telsasoft.com> <9e958478d8bcea814e7ce16511a18912@oss.nttdata.com> <23d39ee9c31643fad8f9ba9c5cf3aaf4@oss.nttdata.com> <0fd375a53e306566cea7f451cc8cfcde@oss.nttdata.com> <7b1bb07a-73ec-1fcc-2f65-41101adf0080@oss.nttdata.com> <8002219d-b999-12fa-2327-49afe40e5fbb@oss.nttdata.com> <88c451c7-2729-4329-fbae-6ed7664adea1@oss.nttdata.com> From: Fujii Masao Message-ID: Date: Wed, 3 Feb 2021 01:49:46 +0900 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2021/02/02 22:00, torikoshia wrote: > On 2021-01-25 23:44, Fujii Masao wrote: >> Another comment is; Doesn't the change of MyProc->waitStart need the >> lock table's partition lock? If yes, we can do that by moving >> LWLockRelease(partitionLock) just after the change of >> MyProc->waitStart, but which causes the time that lwlock is being held >> to be long. So maybe we need another way to do that. > > Thanks for your comments! > > It would be ideal for the consistency of the view to record "waitstart" during holding the table partition lock. > However, as you pointed out, it would give non-negligible performance impacts. > > I may miss something, but as far as I can see, the influence of not holding the lock is that "waitstart" can be NULL even though "granted" is false. > > I think people want to know the start time of the lock when locks are held for a long time. > In that case, "waitstart" should have already been recorded. Sounds reasonable. > If this is true, I think the current implementation may be enough on the condition that users understand it can happen that "waitStart" is NULL and "granted" is false. > > Attached a patch describing this in the doc and comments. > > > Any Thoughts? 64-bit fetches are not atomic on some platforms. So spinlock is necessary when updating "waitStart" without holding the partition lock? Also GetLockStatusData() needs spinlock when reading "waitStart"? + Lock acquisition wait start time. Isn't it better to describe this more clearly? What about the following? Time when the server process started waiting for this lock, or null if the lock is held. + Note that updating this field and lock acquisition are not performed + synchronously for performance reasons. Therefore, depending on the + timing, it can happen that waitstart is + NULL even though + granted is false. I agree that it's helpful to add the note about that NULL can be returned even when "granted" is false. But IMO we don't need to document why this behavior can happen internally. So what about the following? Note that this can be null for a very short period of time after the wait started even though granted is false. Since the document for pg_locks uses "null" instead of NULL (I'm not sure why, though), I used "null" for the sake of consistency. Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION