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 1vhoC5-006YAz-2X for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Jan 2026 12:17:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vhoC4-00DBtM-2i for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Jan 2026 12:17:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vhoC4-00DBtD-1N for pgsql-hackers@lists.postgresql.org; Mon, 19 Jan 2026 12:17:16 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vhoC2-001KpV-1J for pgsql-hackers@lists.postgresql.org; Mon, 19 Jan 2026 12:17:16 +0000 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-47ee76e8656so48745185e9.0 for ; Mon, 19 Jan 2026 04:17:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768825029; x=1769429829; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=TqK9g1O1DCjumI3R1Ai5/dp7FwTsVlAEQ001abPkBZI=; b=CMIN6ZV5TdixgeY5Z4Fk3VcyYmoSA+ZYdVsC/Op7RNvKXZ044UcWhCQA7aQNLpzVCc T5u4JvyayEFyC0rLVxDle27NZzcKBKwUhMKpsEuyAmcG8n19cHJYnRBfs39zIKjMhcXC DxwCpPZG5ZFhSg8sYZwFdUkiIM6YgHY78s8NDJioQPV5t5/lAODx3B93Hdn46ue7DuuF rFJIqjLgoFgBbnEQ/7Ms0TUwPJZdtT19kuqKqJdiXSDq+HY9X5WO6ZviOItKbeLARYHA Jx4ZhyMsa+Svs8RCV/id9sM5GWzyJfOhCe9yU4Sb4Wrbcu4yLa4Ig26okXhglE7onrlp 93AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768825029; x=1769429829; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TqK9g1O1DCjumI3R1Ai5/dp7FwTsVlAEQ001abPkBZI=; b=DNTuvVkfg0L8nPgB7uveW1n0AynXlVm+wXT0GCHh6lJOJNdLpayqlDE48teYp6wrsw 6+qHXaTXQ5/6PpOD80PxlPpe4T452yhgp65ylS73mywchHFz9J9n7FRVzmFfQCqEU5Sx vasYrrUiIiRogg+PqCqUBTrYJDeabcC2vJjt7iRL+wBBzZpdURb9qel4w++q3dISC+Ss F6wgmk5AK3xQxqSCpc76ohriDdFTKum2ZxuTChUrhBGbC2yc3sAf2ZuCwxBvHOgyhcGu cINCOyP+mOHkhUIP8cPd2yl4xLgtGFSQgZVRum4Uky75eT42T5S5FZBKG/xqQV8Ty3rt 9rfw== X-Gm-Message-State: AOJu0YxsVv+z1I3MemqQ1q9sZ/JsrrBUG4vkwJ1v36/YAxcE/rbfWuOW PcDLoH6XMdvEj8ePgNpb8aLEbarFc7m2NU3bNJ+npgw2w/SvjSyHIGGUFGZ4nw== X-Gm-Gg: AY/fxX5wmAtESI6U/tXYt1suRpDcpC+6eLaKVntG+/kw8bmBJEOzAQPSNNNVqs7I/Xo kgprmNgvtgCOZPigQthEZs3S8C6JNFKt7jSNF/CDT+HW0cZG1RdQzFGBKy6Qm+RBxmDr8EQpqpf WtZCWep2FuI+wUpCJxT4vNy8zTsMGzj5Nqwws459yM/spnkpJTsQycNrQHg49+4Z2wHlOIlpc6i QAoI4aPs8oPXltr0ULTCdHu4VlLHklKHqePNdJygWpNFKn5aUq+2wYMQgBhpXPf3bPZEhprLgXB VB9NOCgdcG3zjmnhRvlLffaLyWAGL5IipLK0W+ByAjyYSR2648opbBVEzS48Zpjt4LdtuGw8OGU /1VAoy96CRSpmxc7by0yOeuqR5ZbylUAp+PKZTfJyoZYhhfZJzBq7xo68G13rGZluLadP6h/Mnx /HdBjr3/Ssxe5q1L9GYXlpwYazjWHsnb7/WE0geTEZCsyIA5nlyl164r/M/J7N2S6ZJFn1LFt7v 8TYP7GYWQCZS4a4JTpQjl9GFYAnXqCqZCwsfVy98KfOhBhFJQHe4Zjn X-Received: by 2002:a05:600c:8189:b0:47d:73a4:45a7 with SMTP id 5b1f17b1804b1-4801e339583mr124590095e9.24.1768825028217; Mon, 19 Jan 2026 04:17:08 -0800 (PST) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-237-197-144.eu-west-3.compute.amazonaws.com. [15.237.197.144]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47f428acd0csm246197485e9.6.2026.01.19.04.17.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jan 2026 04:17:07 -0800 (PST) Date: Mon, 19 Jan 2026 12:17:06 +0000 From: Bertrand Drouvot To: Sami Imseih Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Flush some statistics within running transactions Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="OFsrIl+bjhifp5hk" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --OFsrIl+bjhifp5hk Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, On Fri, Jan 16, 2026 at 10:44:48AM -0600, Sami Imseih wrote: > I took a look at 0001 in depth. Thanks! > > I don't think this feature could add a noticeable performance impact, so the tests > > have been that simple. Do you think we should worry more? > > One observation is there's no coordination between ANYTIME and > TXN_BOUNDARY flushes. While PGSTAT_MIN_INTERVAL > prevents a backend from flushing more than once per second, a backend can > still perform both an ANYTIME flush and a TXN_BOUNDARY flush within > the same 1-second window. Not saying this will be a real problem in > the real-world, > but we definitely took measures in the current implementation to avoid > this scenario. Right. I think that the PGSTAT_MIN_INTERVAL throttling was put in place to prevent flushing too frequently when the backend has a high commit rate. But here, while it's true that we don't follow that rule (means a backend could flush more than one time per second), that would be a maximum of 2 times (given that ANYTIME is flushing every second). So, I'm not sure that this single extra flush is worth worrying about. Plus we'd certainly need an extra GetCurrentTimestamp() call, so I'm not sure it's worth it. > A few other comments on 0001 > > + /* Skip if completely idle */ > + if (!DoingCommandRead || IsTransactionOrTransactionBlock()) > + pgstat_report_anytime_stat(false); > > Does this need to be conditional? worst case, we return right away with an empty > list. Best case, is we are consistently flushing. Yeah, I think we could remove this check and just rely on the ones in pgstat_report_anytime_stat(). Done in the attached. > + Assert(!anytime_only || dlist_is_empty(&pgStatPending) == > !have_pending); > > Checking for !anytime_only is unnecessary here. > "list_is_empty(&pgStatPending) == !have_pending" > should be true regardless of ANYTIME or TXN_BOUNDARY, right? Right, thanks for catching it, it was remaining garbage from my dev iterations. > Below are a couple of edits for comments I felt would improve > readability of the code. Done as suggested. > I will start looking at the remaining patches next. Thanks! Note that I also updated the doc in 0003 for the stats that have mixed fields. BTW, I think that we could also make the Function stat kind as flush any time, thoughts? Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com --OFsrIl+bjhifp5hk Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-Add-pgstat_report_anytime_stat-for-periodic-stats.patch"