Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eMzC6-0005rU-1v for pgsql-performance@arkaria.postgresql.org; Thu, 07 Dec 2017 16:38:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eMzC5-0002Pa-8q for pgsql-performance@arkaria.postgresql.org; Thu, 07 Dec 2017 16:38:41 +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.84_2) (envelope-from ) id 1eMzC5-0002PQ-2N for pgsql-performance@lists.postgresql.org; Thu, 07 Dec 2017 16:38:41 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eMzC1-0007wA-Fp for pgsql-performance@postgresql.org; Thu, 07 Dec 2017 16:38:40 +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 vB7GcUdW008330; Thu, 7 Dec 2017 11:38:30 -0500 From: Tom Lane To: =?UTF-8?Q?Ulf_Lohbr=C3=BCgge?= cc: Scott Marlowe , Andres Freund , "pgsql-performance@postgresql.org" Subject: Re: [PERFORM] Slow execution of SET ROLE, SET search_path and RESET ROLE In-reply-to: References: <6684.1512662473@sss.pgh.pa.us> Comments: In-reply-to =?UTF-8?Q?Ulf_Lohbr=C3=BCgge?= message dated "Thu, 07 Dec 2017 17:15:34 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <8328.1512664710.1@sss.pgh.pa.us> Date: Thu, 07 Dec 2017 11:38:30 -0500 Message-ID: <8329.1512664710@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =?UTF-8?Q?Ulf_Lohbr=C3=BCgge?= writes: > 2017-12-07 17:01 GMT+01:00 Tom Lane : >> It looks like the first time such a question is asked within a session, >> we build and cache a list of all the roles the session user is a member >> of (directly or indirectly). That's what's taking the time here --- >> apparently in your test case, the "admin" role is a member of a whole lot >> of roles? > Yes, the user "admin" is member of more than 1k roles. > So this cache will not invalidate during the lifetime of the session unless > a new role is added, I guess? It looks like any update to the role membership catalog (pg_auth_members) invalidates that cache. So basically a "GRANT role" or "REVOKE role" would do it. > Is there any locking involved when this cache gets invalidated? Could this > be a source for my earlier observed slow executions? This particular aspect of things doesn't seem like such a problem to me, but it's certainly possible that there are other aspects that get unreasonably slow when there are that many role memberships involved. Don't see what it'd have to do with SET SEARCH_PATH, though. Or RESET ROLE; that doesn't require any permission checks, either. regards, tom lane