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 1mEBpT-0008KC-A1 for pgsql-general@arkaria.postgresql.org; Thu, 12 Aug 2021 14:37:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mEBpS-0001hj-1K for pgsql-general@arkaria.postgresql.org; Thu, 12 Aug 2021 14:37:06 +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 1mEBpR-0001d2-Mg for pgsql-general@lists.postgresql.org; Thu, 12 Aug 2021 14:37:05 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mEBpP-0000dK-1d for pgsql-general@lists.postgresql.org; Thu, 12 Aug 2021 14:37:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Type:MIME-Version:References:Reply-To: Message-ID:Subject:Cc:To:Sender:From:Date:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=ipYlvGeyhf64Z6S9Ue3Aye90dk1dNhWAwG5IE0I5dhE=; b=bXQxKxpNGPjCgAdNePRUTKCPgn twPu9iUzeWjKKUrF26zCvDzis2k9ruu62Z4lvXEHgAb8yLvKJq10ryp4AtDvQZI0Vh2olay+KVM5D 14HSWUQUCnOWVnk80eKpFTHDPgULuPWd4d57v5pGUNRJ7dycV115MeGhJpqCpq4ig1Ms=; Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by depesz.com with esmtpa (Exim 4.92) (envelope-from ) id 1mEBpL-0002hw-Bb; Thu, 12 Aug 2021 16:36:59 +0200 Date: Thu, 12 Aug 2021 16:36:59 +0200 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: Alvaro Herrera Cc: pgsql-general Subject: Re: Getting pg_stat_database data takes significant time Message-ID: <20210812143659.GA9497@depesz.com> Reply-To: depesz@depesz.com References: <20210811163355.GA20926@depesz.com> <202108121308.ewma4t6jv2e5@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <202108121308.ewma4t6jv2e5@alvherre.pgsql> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Aug 12, 2021 at 09:08:27AM -0400, Alvaro Herrera wrote: > 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? The fie is 120MB, and is stored in tmpfs, which I assume, on Linux, is ram disk. depesz