Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g78sP-0007Xi-Dv for pgsql-committers@arkaria.postgresql.org; Tue, 02 Oct 2018 00:49:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g78sN-0007x1-ON for pgsql-committers@arkaria.postgresql.org; Tue, 02 Oct 2018 00:49:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g78sN-0007wu-JE for pgsql-committers@lists.postgresql.org; Tue, 02 Oct 2018 00:49:23 +0000 Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g78sI-00063c-Sw for pgsql-committers@lists.postgresql.org; Tue, 02 Oct 2018 00:49:23 +0000 Received: from vc1.ecl.ntt.co.jp (vc1.ecl.ntt.co.jp [129.60.86.153]) by tama50.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id w920nG5U019446; Tue, 2 Oct 2018 09:49:16 +0900 Received: from vc1.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 4A558EA7393; Tue, 2 Oct 2018 09:49:16 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (jcms-pop21.ecl.ntt.co.jp [129.60.87.134]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 3FAA7EA736F; Tue, 2 Oct 2018 09:49:16 +0900 (JST) Received: from [127.0.0.1] (unknown [129.60.241.61]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 1EBAB40019E; Tue, 2 Oct 2018 09:49:16 +0900 (JST) Subject: Re: pgsql: Add assertions that we hold some relevant lock during relation o References: From: Amit Langote Message-ID: <1bd0f5d5-e1aa-e396-ab70-68798fb6b13a@lab.ntt.co.jp> Date: Tue, 2 Oct 2018 09:49:07 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CC-Mail-RelayStamp: 1 To: Tom Lane , pgsql-committers@lists.postgresql.org X-TM-AS-MML: disable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2018/10/02 1:43, Tom Lane wrote: > Add assertions that we hold some relevant lock during relation open. > > Opening a relation with no lock at all is unsafe; there's no guarantee > that we'll see a consistent state of the relevant catalog entries. > While use of MVCC scans to read the catalogs partially addresses that > complaint, it's still possible to switch to a new catalog snapshot > partway through loading the relcache entry. Moreover, whether or not > you trust the reasoning behind sometimes using less than > AccessExclusiveLock for ALTER TABLE, that reasoning is certainly not > valid if concurrent users of the table don't hold a lock corresponding > to the operation they want to perform. > > Hence, add some assertion-build-only checks that require any caller > of relation_open(x, NoLock) to hold at least AccessShareLock. This > isn't a full solution, since we can't verify that the lock level is > semantically appropriate for the action --- but it's definitely of > some use, because it's already caught two bugs. > > We can also assert that callers of addRangeTableEntryForRelation() > hold at least the lock level specified for the new RTE. > > Amit Langote and Tom Lane > > Discussion: https://postgr.es/m/16565.1538327894@sss.pgh.pa.us Thanks for committing. I'm sorry if it wasn't clear, but the lock manager code was added to the original 0001 patch by David Rowley; see this message where he posted the updated version of my patch containing the new code: https://www.postgresql.org/message-id/CAKJS1f83VJjrnN6hQtZ7vJ%2BE4_%2BtH%3DU2VK6hgr74fZN-%3DDq3Ag%40mail.gmail.com Thanks, Amit