Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mEARs-0005pw-Je for pgsql-general@arkaria.postgresql.org; Thu, 12 Aug 2021 13:08:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mEARq-00018k-HO for pgsql-general@arkaria.postgresql.org; Thu, 12 Aug 2021 13:08:38 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mEARq-00018W-4D for pgsql-general@lists.postgresql.org; Thu, 12 Aug 2021 13:08:38 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mEARl-0008PQ-UE for pgsql-general@lists.postgresql.org; Thu, 12 Aug 2021 13:08:36 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 310605C042F; Thu, 12 Aug 2021 09:08:33 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 12 Aug 2021 09:08:33 -0400 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:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=lLysR1NmThxwCYM9XTypu4ssMTBhmTCEzGrZoYVH7rk=; b=ZlvI3I4C 3DTC3m9SNtNVm6Z3uEGs2bimwIvN/6RgyiPnJCLfdkcKFXxLpbyBuGKg4PF4Xb45 ofcuO2H5lStiVpNzhpxG+C6KZ7E2rIS3lITAemYam8vDLpxA0ANfkt1dvAK+E6X3 RitC+Ho0fENeFuglEYzdpkJmyA7CQ7YY2R4221BYc9Vp27GMxLQbcPmLJGDn+o9S TWtW8ejJo/WRnc9iaU1O7N8QFLLCBXi0hxfyUi81V8ift0ukaYVfHm8QZROC4Gke LqA98D3SlfhMDPve483Fhe1d/gk/cYVrlJNAUuqr43N6XtDuJdkTWkQhrin/rCz4 NZPRVEkQNeiRmg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrkeefgdehkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgrrhho ucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgheqne cuggftrfgrthhtvghrnhepgeeghfekgfdvtdfhffdtvdevudevjedvtdegudfgleegleef teegudeihfdttdeknecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomhdpsh hlrghshhguohhtrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehm rghilhhfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Aug 2021 09:08:31 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 832502A07B7; Thu, 12 Aug 2021 09:08:27 -0400 (-04) Date: Thu, 12 Aug 2021 09:08:27 -0400 From: Alvaro Herrera To: hubert depesz lubaczewski Cc: pgsql-general Subject: Re: Getting pg_stat_database data takes significant time Message-ID: <202108121308.ewma4t6jv2e5@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210811163355.GA20926@depesz.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2021-Aug-11, hubert depesz lubaczewski wrote: > On Wed, Aug 11, 2021 at 10:16:13AM -0400, Alvaro Herrera wrote: > > 1. this depends on reading the stats file; that's done once per > > transaction. So if you run the query twice in a transaction, the second > > time will take less time. You can know how much time is spent reading > > that file by subtracting both times. > > Yeah. I noticed. Looks like loading the stats file is the culprit. But > does that mean that the whole stats file has to be read at once? I just > need stats on db, not on relations? As I recall there is one file per database containing everything pertaining to that database, and you cannot read it partially. Maybe you can use stats_temp_directory to put these files in faster or less busy storage -- a RAM disk perhaps? -- Álvaro Herrera Valdivia, Chile — https://www.EnterpriseDB.com/ "Those who use electric razors are infidels destined to burn in hell while we drink from rivers of beer, download free vids and mingle with naked well shaved babes." (http://slashdot.org/comments.pl?sid=44793&cid=4647152)