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 1mEV4t-0002uz-Kr for pgsql-general@arkaria.postgresql.org; Fri, 13 Aug 2021 11:10:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mEV4s-0002a7-Hm for pgsql-general@arkaria.postgresql.org; Fri, 13 Aug 2021 11:10:18 +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 1mEV4s-0002Zx-6q for pgsql-general@lists.postgresql.org; Fri, 13 Aug 2021 11:10:18 +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 1mEV4o-0001iz-RV for pgsql-general@lists.postgresql.org; Fri, 13 Aug 2021 11:10:17 +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=omvWsVR09DbLETBK3gxpiztlDPeRO7fn3sjCa24+ksk=; b=YSRfm4J15mh3k0KxYZFJFWy93J I77LikLCXeTfdDhhxIcjPHg3xyTrLlxcXITsLIG7lmRGoKbnEyNDcELPOGL5uYv/v4Aji5fqPbzYo gJdpPkAfAvpMHtjcKgG6J9TIikahsB7OQL1cTvAQF2NB1+GugwdCMTmtlX+rB6+Kit8I=; Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by depesz.com with esmtpa (Exim 4.92) (envelope-from ) id 1mEV4l-0002Bh-96; Fri, 13 Aug 2021 13:10:11 +0200 Date: Fri, 13 Aug 2021 13:10:11 +0200 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: Magnus Hagander Cc: Alvaro Herrera , pgsql-general Subject: Re: Getting pg_stat_database data takes significant time Message-ID: <20210813111010.GA5785@depesz.com> Reply-To: depesz@depesz.com References: <20210811131247.GA27197@depesz.com> <202108111416.4ddlilf6hr6r@alvherre.pgsql> <20210811163355.GA20926@depesz.com> <20210812143849.GB9497@depesz.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: 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 06:20:23PM +0200, Magnus Hagander wrote: > On Thu, Aug 12, 2021 at 4:38 PM hubert depesz lubaczewski > wrote: > > > > On Thu, Aug 12, 2021 at 11:32:15AM +0200, Magnus Hagander wrote: > > > Which database are you connected to? If you just want to look at the > > > global stats, it might help to be connected to a database that is > > > *not* the one with all the tables in -- e.g. connect to "postgres" and > > > query pg_stat_database looking for values on a different database? In > > > this case it would open files for "global", for "database postgres" > > > and "shared relations" only and skip the file for your db with many > > > objects. I think. > > > > I'm connected to the db I need data about, and I need data from virtualy > > all columns of pg_stat_database. > Try connecting to a different database, while still querying all columns. Damn, this is huge difference: =$ time psql -d postgres -c "select * from pg_stat_database where datname = 'appdb'" -qAtX > /dev/null real 0m0.058s user 0m0.026s sys 0m0.013s =$ time psql -d appdb -c "select * from pg_stat_database where datname = 'appdb'" -qAtX > /dev/null real 0m0.466s user 0m0.031s sys 0m0.008s Not sure if I can make the monioring software use different connection for this one particular query, though. Will check with them. Thanks. Best regards, depesz