Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vsvBI-008gdO-2x for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Feb 2026 03:58:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vsvBG-001cJT-0E for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Feb 2026 03:58:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vsvBF-001cJE-28 for pgsql-hackers@lists.postgresql.org; Thu, 19 Feb 2026 03:58:21 +0000 Received: from fout-b8-smtp.messagingengine.com ([202.12.124.151]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vsvBC-000000004gE-1dvr for pgsql-hackers@lists.postgresql.org; Thu, 19 Feb 2026 03:58:20 +0000 Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfout.stl.internal (Postfix) with ESMTP id A9CDF1D00042; Wed, 18 Feb 2026 22:58:18 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Wed, 18 Feb 2026 22:58:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1771473498; x=1771559898; bh=SNIc6eEuZB r2lnPIAniUPB5dWEFtV4qN0PrLkou8BBw=; b=mo7D6ESdHmx6po0sq68/AT1/Ot eQpJdDp9XkNsI/J5wK2Kbz7X4qatpEeRdqbEARMpipkCUkGVKIE0GgriFtwJwECa wo/pq4lxORdskxdpV0B/pxKtBfcAoQE4TLZvaxq0fFBnAmtLcFiFq1rpit7Dd64A MHN1eS+r9lqIrmS1M/iN+BLZV+jdyXv2JTcVn90OiA4pdm9OD7H/fAHx2QjtE8c5 bJ3WnzwU/krGeK/ZP8R/mF0ZaXOPDRXosXt5tqcdg7r3niS683OpJkCVQJB6Jkj2 ape1R9MKlwZ5BfWEaWI+t9nJ9uVhWcJxhAlGxvYehKSBESEQg0IJ182RfAzA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1771473498; x=1771559898; bh=SNIc6eEuZBr2lnPIAniUPB5dWEFtV4qN0Pr Lkou8BBw=; b=sN8N94d8OdsKXL4zm63sDzMweO1WMsbClYOLzZlBYhXT3MTrKk7 vxpYxFkWFNAOmbhKwk1OHLnAX8A5uu+pqjPHFLVNb5urq+wv0U/Pc0Qt2xJy4+d5 /xHEjJB06eq6lS6qFmxB03Lev/xdkbCciQwp7Rg/5VayyjwR48NVCLXtZddqB/zv FPWlBazdM4Vj0JclW79e8FzpV7UdwaGuM/YqvFivTImbTUfk39ctfDs/SYC/IHwl fsUQk9FEWNw2EPbISI+S0aN6SYRoD2mPL441MUpgwg+PKEgG2QQqtaxL8oDXZ1Tt 1qrwqzcjhTX0gQS6E1923WmlFu0pHbQrLig== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvvdeghedtucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnegfrh hlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddv necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteelieefudffhffhtdetleeggeeg fffhkeeuveetiefgudduvedutefggeeivdejnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiidp nhgspghrtghpthhtohephedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepsggvrh htrhgrnhguughrohhuvhhothdrphhgsehgmhgrihhlrdgtohhmpdhrtghpthhtohepshgr mhhimhhsvghihhesghhmrghilhdrtghomhdprhgtphhtthhopehmrghsrghordhfuhhjih hisehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrsheslhhi shhtshdrphhoshhtghhrvghsqhhlrdhorhhgpdhrtghpthhtohepiihsohhlthdrphgrrh hrrghgihesphgvrhgtohhnrgdrtghomh X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 18 Feb 2026 22:58:16 -0500 (EST) Date: Thu, 19 Feb 2026 12:58:12 +0900 From: Michael Paquier To: Bertrand Drouvot Cc: Sami Imseih , Fujii Masao , pgsql-hackers@lists.postgresql.org, Zsolt Parragi Subject: Re: Flush some statistics within running transactions Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="dz6PXkybTFxm8NHl" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --dz6PXkybTFxm8NHl Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Feb 18, 2026 at 05:40:46AM +0000, Bertrand Drouvot wrote: > PFA a mandatory rebase (nothing that needs review) due to a92b809f9da1. I don't find the design of this patch appealing, and my mind points towards two pieces of it: 1) The new requirement related to pgstat_schedule_anytime_update() that a stats kind needs to call to enable a timeout. This partially doubles with pgstat_report_fixed. And I suspect that this extra set of requirements, introducing a new level of complexity for in-core stats kinds as well as extension developers, would be the source of more bugs. 2) The timeout requirement itself, relying on a timeout threshold controlled by a backend-side configuration. With that in mind, wouldn't it be simpler if we introduced an API that could be used from client applications instead, in a model similar what we do for procsignal.c/h? One such example is LOG_MEMORY_CONTEXT, where we have a SQL function that is able to tell to a backend that it needs to do something. I could see various benefits to this approach, because it gives more flexibility with the timing of the stats flushes, which may not be a backend-side only policy: - Use a cron bgworker in the backend, that scans pg_stat_activity, for example for long-running transactions based on a threshold. - Do the same periodic scan of pg_stat_activity, but from a client application. The PROCSIG would need to set a flag in a new SIGUSR1 handler that would trigger the flush for the stats kinds that have the out-of-transaction property set once we go through in ProcessInterrupts(). We already have a pgstats report call there, hence it is a matter of removing the timeout requirements as presented in the patch, and let client applications when this should happen. The property of tracking which stats kind is surely important, Sami has reminded that a couple of hours ago that there are some stats that we should not flush even if we get an async request. Another thing that I am doubting about is if using the same async flush threshold makes sense for everything. Long-running transactions, for example, mostly would not care much even if we use an interval less aggressive than what a WAL sender sees. Not a fan of the hardcoded sleeps in the tests, either. On fast machines, these tend to waste in runtime because a process stands idle doing nothing. On slow machines, tests could be unstable if a sleep takes longer than it takes for the environment to react to a condition of the test. -- Michael --dz6PXkybTFxm8NHl Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmmWilQACgkQnvQgOdby QH2geQ//fwHjFDFspB+UOUaPdy/jnE2e7y/dcQUnX9xJt71n6S3nKQ213ozLM7W/ s6VwD0VymWxEqaWDHLcUYj4og40vb8S0/LbuVyXYkb+DahxXWupUQg0hFhx7UOzd f1dSSAy1Pih752b0zrxyW/pnSFS4ecWDKXC/xDkrEd1D/I/5MZ97siHO09KggOtc 2O2XmQpjwEXP5b2oqIvKMGIWkwLLylv8Iancskxy3hTzl+4bIKYsYts0klMGtESC oCF0PQ2EAmG6nJdG2Gu1YzI03LF2ICQK1X2X4GYitRveR1bPDUczncu6psA+HaNM qQzn+fCdKpuq8XIpBNwY4p6KkOKvFGqb4Y8cwu8P0rmnWbZ9V2ZK1jk3+by/X+Cl Qk13Du8H3ZymEeSk52f+LaJP634uhw6qeM4VcXDFApY32HlRsk35V+LMjja43TAY OuCIagj95/m6DLpNczGyXUw56gJTSzYaKR7opCChC4j1i2bfWOGxWXs058KhxHWm uZE7aV0o3TEXD0RrkBMbmYc/anaqEfBriC2kCl+gEqLcUVN5ce9Go0iK7skXbojl 1gBPntvf3Z9ObXxFyY+wTQRPMh9Sujvrc03ulW7C3d0QeWWEO10bMBTdaUDogs3Q oz+bng+Q4oHeEWZr1tAHiHC1GLbNM3oFP18xSRm47sPkZWlb30s= =uUg+ -----END PGP SIGNATURE----- --dz6PXkybTFxm8NHl--