Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eC5Ys-0006lz-KY for pgsql-performance@arkaria.postgresql.org; Tue, 07 Nov 2017 15:13:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1eC5Yr-0007pk-V7 for pgsql-performance@arkaria.postgresql.org; Tue, 07 Nov 2017 15:13:10 +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 1eC5X0-0000I3-JG for pgsql-performance@postgresql.org; Tue, 07 Nov 2017 15:11:14 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eC5Ww-0005co-QL for pgsql-performance@postgresql.org; Tue, 07 Nov 2017 15:11:14 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id B17C320DA0; Tue, 7 Nov 2017 10:11:09 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Tue, 07 Nov 2017 10:11:09 -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=6R1cJp lQpWfhpXbIAnOUi9VrzD76z+8pTCKHPncC4BM=; b=gr5mVN9hkxKKqXH6u5+t77 aS4j40yU6CxvV/O1P7K0h3gLJn/r3CHHJwWXUxs4k2bRzlrzBrsQ4RB/hrsdZjB9 RLEsGxy0vBURLiQOOi2tKCggkPmEzwKTZGv/kjDVLmxYgcgGAUzknFI9V7C0wIIE yATXJxZHr8aiMdW3V3OxgJcOyFEfYGPhm4XU42IaSBBu/uLb2GGdx2U7WvrTYd1I 5xk7RUfPdKngiQtY5zHXDy76hiYYU97lyiox5NVTs3aIR4Yy0Oz4qtUXlC+0fT2T RdEEYJW8qIzG0ODqFjsc7hFA/ySLxSSmz2RPkQEOyYPt3ZH+VcS62PjmSNT+cSPw == X-ME-Sender: Received: from intern.anarazel.de (unknown [136.24.76.189]) by mail.messagingengine.com (Postfix) with ESMTPA id 7291F24BCA; Tue, 7 Nov 2017 10:11:09 -0500 (EST) Date: Tue, 7 Nov 2017 07:11:08 -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: <20171107151108.3jtmta4xrgmuyrqf@alap3.anarazel.de> References: 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 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? > My application solely uses the role 'admin' to connect to the database. > When performing sql statements for a specific tenant (e.g. tenant1337), a > connection with user 'admin' is established and the following commands are > executed: > > SET ROLE 1337; > SET search_path = tenant1337; > > Then the application uses that connection to perform various statements in > the database. Just to be sure: You realize bad application code could escape from that, right? > My application is a web service that approximately executes some hundred > statements per second. > > I set "log_min_duration_statement = 200ms" and I get about 2k to 4k lines > per day with statements like "SET ROLE"", "SET search_path ..." and "RESET > ROLE": > > --snip-- > 2017-11-07 09:44:30 CET [27760]: [3-1] user=admin,db=mydb LOG: duration: > 901.591 ms execute : SET ROLE "tenant762" > 2017-11-07 09:44:30 CET [27659]: [4-1] user=admin,db=mydb LOG: duration: > 1803.971 ms execute : SET ROLE "tenant392" That is weird. > Besides those peaks in statement duration, my application performs (i.e. > has acceptable response times) most of the time. > > Is there anything I can do to improve performance here? > Any help is greatly appreciated! Can you manually reproduce the problem? What times do you get if you manually run the statement? 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