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 1ovOSj-0001Bc-KE for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Nov 2022 19:52:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ovOSg-00075k-Om for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Nov 2022 19:52:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ovOSf-00075b-FK for pgsql-hackers@lists.postgresql.org; Wed, 16 Nov 2022 19:52:42 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ovOSa-0000Uj-Ej for pgsql-hackers@lists.postgresql.org; Wed, 16 Nov 2022 19:52:41 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 0F96F5C00C4; Wed, 16 Nov 2022 14:52:34 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 16 Nov 2022 14:52:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm1; t=1668628354; x=1668714754; bh=3msWkQWsp6 52g4uvtd1d7ueLL6upK9YPPSjq7TERKlQ=; b=K4ZCMuP1GOA8/PhQD3M5sjLR3U 4RCCih8uuJ/cZa9A0le5cPisahiWxhULhfgmxgGxNlIvEcIrGlJ8oZp3k9kpG4cA 0TeHHFqCJatHUV9fYjMykn8wGFLuFROlRIfvQ7/WoqzhJGyk8JB6RuWJqCYLrbK0 HqH53jMCF3Kgq4lrI4Vgg7pKWRRmgd2g6STEt6sct1jTh32EOJ/Uv8SC+zCEq5pV bhhsmZ+c5tH0KyIHE328nkylDsReBwl8Y6JxK3cQxrEV4DI0W3jhBQfK/JQvnuOc Kvlcac8TFBQbXD0lFlKBVNp0fiO+zKjgdC/1mE4LsLKXj9/reTF6PhLzrJyw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1668628354; x=1668714754; bh=3msWkQWsp652g4uvtd1d7ueLL6up K9YPPSjq7TERKlQ=; b=TBtQwxOnfX/3CkT/th5FEp3naNL0j6DXohHv/x7OWiqg EECIrLg6ghMbg7dNGu+cfwk9DAn/uTuJVGorw4V/yyE4JtFqxYOjxSPDPuWJZCC1 6r6YjqMp7u+ked+CZ8Mip0n87/0DpEj9awbT/o76GjNYwrdOoHCXsGnEfWswjMby Mw4v4QCO+EuYMzGMQ8ty1Db/XdsndEka75xiTEbWT7XIgrbrL2GGLHqcXrlBcdKf DGGiYBJplmYkJyMW6MDbFR1RJXka7ATTWrY8sgWCS3TPJ1svXleUYHumghdT1bRA tG5yyDyGSBAagyBiGNXRjAjLsNt47dw4G2EpfT/Ibg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrgeeigdduvdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomheptehnughr vghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrf grthhtvghrnhepveevieffveejtefggeffgfekueeiueekvdethfehieduheejleetjeek ieettdffnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrghenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrnhgurhgvshesrghnrghr rgiivghlrdguvg X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 16 Nov 2022 14:52:33 -0500 (EST) Date: Wed, 16 Nov 2022 11:52:32 -0800 From: Andres Freund To: Robert Haas , Melanie Plageman Cc: Bharath Rupireddy , "Drouvot, Bertrand" , Nitin Jadhav , Matthias van de Meent , Ashutosh Sharma , Julien Rouhaud , Bruce Momjian , Tom Lane , Magnus Hagander , PostgreSQL Hackers Subject: Re: Report checkpoint progress with pg_stat_progress_checkpoint (was: Report checkpoint progress in server logs) Message-ID: <20221116195232.wynvnlng2ivne76b@awork3.anarazel.de> References: <20220319001556.atuqbmafvc73pa2k@alap3.anarazel.de> <20220707000446.hefgyu5xikxwt4md@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2022-11-16 14:19:32 -0500, Robert Haas wrote: > I have never really understood why we drive background writer or > checkpointer statistics through the statistics collector. To some degree it is required for durability - the stats system needs to know how to write out those stats. But that wasn't ever a good reason to send messages to the stats collector - it could just read the stats from shared memory after all. There's also integration with snapshots of the stats, resetting them, etc. There's also the complexity that some of the stats e.g. for checkpointer aren't about work the checkpointer did, but just have ended up there for historical raisins. E.g. the number of fsyncs and writes done by backends. See below: > Here again, for things like table statistics, there is no choice, because we > could have an unbounded number of tables and need to keep statistics about > all of them. The statistics collector can handle that by allocating more > memory as required. But there is only one background writer and only one > checkpointer, so that is not needed in those cases. Why not just have them > expose anything they want to expose through shared memory directly? That's how it is in 15+. The memory for "fixed-numbered" or "global" statistics are maintained by the stats system, but in plain shared memory, allocated at server start. Not via the hash table. Right now stats updates for the checkpointer use the "changecount" approach to updates. For now that makes sense, because we update the stats only occasionally (after a checkpoint or when writing in CheckpointWriteDelay()) - a stats viewer seeing the checkpoint count go up, without yet seeing the corresponding buffers written would be misleading. I don't think we'd want every buffer write or whatnot go through the changecount mechanism, on some non-x86 platforms that could be noticable. But if we didn't stage the stats updates locally I think we could make most of the stats changes without that overhead. For updates that just increment a single counter there's simply no benefit in the changecount mechanism afaict. I didn't want to do that change during the initial shared memory stats work, it already was bigger than I could handle... It's not quite clear to me what the best path forward is for buf_written_backend / buf_fsync_backend, which currently are reported via the checkpointer stats. I think the best path might be to stop counting them via the CheckpointerShmem->num_backend_writes etc and just populate the fields in the view (for backward compat) via the proposed [1] pg_stat_io patch. Doing that accounting with CheckpointerCommLock held exclusively isn't free. > If the statistics collector provides services that we care about, like > persisting data across restarts or making snapshots for transactional > behavior, then those might be reasons to go through it even for the > background writer or checkpointer. But if so, we should be explicit > about what the reasons are, both in the mailing list discussion and in > code comments. Otherwise I fear that we'll just end up doing something > in a more complicated way than is really necessary. I tried to provide at least some of that in the comments at the start of pgstat.c in 15+. There's very likely more that should be added, but I think it's a decent start. Greetings, Andres Freund [1] https://www.postgresql.org/message-id/CAOtHd0ApHna7_p6mvHoO%2BgLZdxjaQPRemg3_o0a4ytCPijLytQ%40mail.gmail.com