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 1kVPf1-0000bE-RA for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Oct 2020 01:44:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kVPf0-000139-PA for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Oct 2020 01:44:58 +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 1kVPf0-000132-J6 for pgsql-hackers@lists.postgresql.org; Thu, 22 Oct 2020 01:44:58 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kVPey-0005eA-AA for pgsql-hackers@postgresql.org; Thu, 22 Oct 2020 01:44:57 +0000 Received: from oss.nttdata.com (localhost [127.0.0.1]) by oss.nttdata.com (Postfix) with ESMTP id 6CAA760560; Thu, 22 Oct 2020 10:44:53 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.3 at oss.nttdata.com MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 22 Oct 2020 10:44:53 +0900 From: Masahiro Ikeda To: Kyotaro Horiguchi Cc: amit.kapila16@gmail.com, pgsql-hackers@postgresql.org Subject: Re: Add statistics to pg_stat_wal view for wal related parameter tuning In-Reply-To: <20201021.180323.1892401452849353942.horikyota.ntt@gmail.com> References: <35ef960128b90bfae3b3fdf60a3a860f@oss.nttdata.com> <06bc2d405b086a72fb14657de9befae8@oss.nttdata.com> <20201021.180323.1892401452849353942.horikyota.ntt@gmail.com> Message-ID: <729d83f87da2cfbca4343e577f2e20a1@oss.nttdata.com> X-Sender: ikedamsh@oss.nttdata.com User-Agent: Roundcube Webmail/1.1.9 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020-10-21 18:03, Kyotaro Horiguchi wrote: > At Tue, 20 Oct 2020 16:11:29 +0900, Masahiro Ikeda > wrote in >> On 2020-10-20 12:46, Amit Kapila wrote: >> > I see that we also need to add extra code to capture these stats (some >> > of which is in performance-critical path especially in >> > XLogInsertRecord) which again makes me a bit uncomfortable. It might >> > be that it is all fine as it is very important to collect these stats >> > at cluster-level in spite that the same information can be gathered at >> > statement-level to help customers but I don't see a very strong case >> > for that in your proposal. > > We should avoid that duplication as possible even if the both number > are important. > >> Also about performance, I thought there are few impacts because it >> increments stats in memory. If I can implement to reuse pgWalUsage's >> value which already collects these stats, there is no impact in >> XLogInsertRecord. >> For example, how about pg_stat_wal() calculates the accumulated >> value of wal_records, wal_fpi, and wal_bytes to use pgWalUsage's >> value? > > I don't think that works, but it would work that pgstat_send_wal() > takes the difference of that values between two successive calls. > > WalUsage prevWalUsage; > ... > pgstat_send_wal() > { > .. > /* fill in some values using pgWalUsage */ > WalStats.m_wal_bytes = pgWalUsage.wal_bytes - > prevWalUsage.wal_bytes; > WalStats.m_wal_records = pgWalUsage.wal_records - > prevWalUsage.wal_records; > WalStats.m_wal_wal_fpi = pgWalUsage.wal_fpi - > prevWalUsage.wal_fpi; > ... > pgstat_send(&WalStats, sizeof(WalStats)); > > /* remember the current numbers */ > prevWalUsage = pgWalUsage; Thanks for your advice. This code can avoid the performance impact of critical code. By the way, what do you think to add these statistics to the pg_stat_wal view? I thought to remove the above statistics because there is advice that PG13's features, for example, pg_stat_statement view, vacuum log, and so on can cover use-cases. regards, -- Masahiro Ikeda NTT DATA CORPORATION