Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gVOEn-0002Si-9k for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Dec 2018 22:04:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gVOEl-0004JG-2j for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Dec 2018 22:04:43 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1gVOEk-0004J9-S1 for pgsql-hackers@lists.postgresql.org; Fri, 07 Dec 2018 22:04:42 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gVOEi-0002b6-Cc for pgsql-hackers@postgresql.org; Fri, 07 Dec 2018 22:04:42 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id wB7M4W15024824; Fri, 7 Dec 2018 17:04:33 -0500 From: Tom Lane To: Robert Haas cc: Andres Freund , Pavel Stehule , "pgsql-hackers@postgresql.org" Subject: Re: slow queries over information schema.tables In-reply-to: References: <5978.1544030694@sss.pgh.pa.us> <20181205175657.s7mt6as356kwvrji@alap3.anarazel.de> <8210.1544034143@sss.pgh.pa.us> <20181205182555.x4wtnzffmhwsc3c7@alap3.anarazel.de> <8843.1544035292@sss.pgh.pa.us> <20577.1544113962@sss.pgh.pa.us> <21728.1544115813@sss.pgh.pa.us> <17422.1544118632@sss.pgh.pa.us> Comments: In-reply-to Robert Haas message dated "Fri, 07 Dec 2018 15:24:32 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <24822.1544220272.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 07 Dec 2018 17:04:32 -0500 Message-ID: <24823.1544220272@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Robert Haas writes: > On Thu, Dec 6, 2018 at 12:50 PM Tom Lane wrote: >> No. You need to do AIM *after* obtaining the lock, else you still >> have the race condition that you can execute a query on a table >> without being aware of recent DDL on it. > Huh? The call in relation_openrv_extended() happens before acquiring the= lock. Oh, I was looking at the wrong AIM call :-(. You're talking about this one: /* * Check for shared-cache-inval messages before trying to open the * relation. This is needed even if we already hold a lock on the * relation, because GRANT/REVOKE are executed without taking any lock= on * the target relation, and we want to be sure we see current ACL * information. We can skip this if asked for NoLock, on the assumpti= on * that such a call is not the first one in the current command, and s= o we * should be reasonably up-to-date already. (XXX this all could stand= to * be redesigned, but for the moment we'll keep doing this like it's b= een * done historically.) */ if (lockmode !=3D NoLock) AcceptInvalidationMessages(); which is indeed about as bletcherous as it could possibly be. The ideal thing would be for GRANT/REVOKE to act more like other DDL, but I'm not sure how we get to that point: REVOKE SELECT, at the very least, would have to take AccessExclusiveLock so that it'd block SELECT. People doing things like GRANT/REVOKE ON ALL TABLES would doubtless complain about the greatly increased risk of deadlock from taking a pile of AELs. And that still would only fix the problem for table privileges, not privileges on other object types that we have no consistent locking scheme for. I can see the attraction of replacing these AIM calls (and, probably, the one in AtStart_Cache) with a single call that occurs somewhere during statement startup. Not sure exactly where that should be; but there is certainly not anything principled about doing it in relation_open_xxx(). regards, tom lane