Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gEaiR-0001Fz-Nn for pgsql-performance@arkaria.postgresql.org; Mon, 22 Oct 2018 13:57:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gEaiP-0008I6-Hm for pgsql-performance@arkaria.postgresql.org; Mon, 22 Oct 2018 13:57:53 +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 1gEaiP-0008Hz-AI for pgsql-performance@lists.postgresql.org; Mon, 22 Oct 2018 13:57:53 +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 1gEaiM-0002Zk-QW for pgsql-performance@postgresql.org; Mon, 22 Oct 2018 13:57:52 +0000 Received: from pro.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w9MDvm8M032247; Mon, 22 Oct 2018 09:57:48 -0400 From: Tom Lane To: =?UTF-8?Q?Ulf_Lohbr=C3=BCgge?= cc: pgsql-performance@postgresql.org Subject: Re: High CPU Usage of "SET ROLE" In-reply-to: References: Comments: In-reply-to =?UTF-8?Q?Ulf_Lohbr=C3=BCgge?= message dated "Mon, 22 Oct 2018 15:44:16 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <82966.1540216668.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 22 Oct 2018 09:57:48 -0400 Message-ID: <82967.1540216668@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =3D?UTF-8?Q?Ulf_Lohbr=3DC3=3DBCgge?=3D writes: > I'm running PostgreSQL 9.6.10 on Debian and reported some performance > issues with "SET ROLE" a while ago: > https://www.postgresql.org/message-id/CABZYQR%2BKu%2BiLFhqwY89QrrnKG9wKx= ckmssDG2rYKESojiohRgQ%40mail.gmail.com > ... > The setup is the same as reported in the above mentioned post: I use mor= e > than a thousand roles per PostgreSQL instance and set the role for every > connection before executing actual statements. My pg_class consists > of 1,557,824 rows as every role has its own schema with more than 300 > tables. It seems plausible to guess that you've hit some behavior that's O(N^2) in the number of objects (for some object type or other). Perhaps "perf" or a similar tool would give some insight into where the bottleneck is. https://wiki.postgresql.org/wiki/Profiling_with_perf regards, tom lane