Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eC9oL-0008G4-6D for pgsql-performance@arkaria.postgresql.org; Tue, 07 Nov 2017 19:45:25 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1eC9oK-0004mI-PC for pgsql-performance@arkaria.postgresql.org; Tue, 07 Nov 2017 19:45:24 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eC9oJ-0004kk-IO for pgsql-performance@postgresql.org; Tue, 07 Nov 2017 19:45:23 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eC9oF-000334-7S for pgsql-performance@postgresql.org; Tue, 07 Nov 2017 19:45:22 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 3DA7520BFA; Tue, 7 Nov 2017 14:45:18 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Tue, 07 Nov 2017 14:45:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=dX0zBR yUpH1fhmbO/rK9ShN+qxpUqYjtVJ/70Zp/u0g=; b=fbh+c+By1xQRsMH8CURvQQ wpZf1dNoeIeJrSe5vGyOgTP2Bn5wdhCEFWJ5ACD5UIdvTlXy5ciz8cqYx+bRw9t0 wUQ6o88kFH9dyBFXpIoBGdghBbWSg5nc5n1vO7AkO0SVdMEaoHnuHR0P1NwCWsYF A5dZloW6cNMXHXxNdaF4J4hPmnAmNdPZA2ozwU1coO4xeyT5xS7ccw3liuGJAL8P TI8NavvR1BBkvr3akvVe50VC1CB6J/kTHqeX+/wHbOHXqYou0cOUBB1zp061RneC Rg61NoJ+VWAmxfis6NdU5/xMiEF8RxObk5WKedluW9eEE44xNhARlvzRNFcP+k2w == X-ME-Sender: Received: from intern.anarazel.de (unknown [96.72.164.235]) by mail.messagingengine.com (Postfix) with ESMTPA id 046DA241BE; Tue, 7 Nov 2017 14:45:18 -0500 (EST) Date: Tue, 7 Nov 2017 11:45:17 -0800 From: Andres Freund To: Ulf =?iso-8859-1?Q?Lohbr=FCgge?= Cc: pgsql-performance@postgresql.org Subject: Re: Slow execution of SET ROLE, SET search_path and RESET ROLE Message-ID: <20171107194517.pabhi4czbtiasb2f@alap3.anarazel.de> References: <20171107151108.3jtmta4xrgmuyrqf@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On 2017-11-07 18:48:14 +0100, Ulf Lohbrügge wrote: > Hi, > > 2017-11-07 16:11 GMT+01:00 Andres Freund : > > > Hi, > > > > On 2017-11-07 11:11:36 +0100, Ulf Lohbrügge wrote: > > > I'm using PostgreSQL 9.5.9 on Debian and experience slow execution of > > some > > > basic SET statements. > > > > > > I created about 1600 roles and use that setup for a multi tenancy > > > application: > > > > Hm. How often do you drop/create these roles? How many other > > roles/groups is one role a member of? > > > > I create between 10-40 roles per day. Could you VACUUM (VERBOSE, FREEZE) that table and report the output? Do you ever delete roles? > > Can you manually reproduce the problem? What times do you get if you > > manually run the statement? > > > > Unfortunately not. Every time I manually execute "SET ROLE ..." the > statement is pretty fast. I created a simple SQL file that contains the > following statements: > > --snip-- > SET ROLE tenant382; > SET ROLE tenant1337; > SET ROLE tenant2; > -- repeat the lines above 100k times > --snap-- > > When I execute those statements via 'time psql < set-roles.sql', the call > lasts 138,7 seconds. So 300k "SET ROLE" statements result in 0,46ms per > call on average. And most of that is going to be roundtrip time. Hm. Could it be that you're just seeing the delays when pgbouncer establishes new pooling connections and you're attributing that to SET ROLE in your app? Greetings, Andres Freund -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance