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 1wUgga-001MgA-0L for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Jun 2026 08:10:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wUggZ-000R7c-03 for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Jun 2026 08:10:47 +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 1wUggY-000R7U-2L for pgsql-hackers@lists.postgresql.org; Wed, 03 Jun 2026 08:10:46 +0000 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wUggW-000000010lc-2yYE for pgsql-hackers@postgresql.org; Wed, 03 Jun 2026 08:10:46 +0000 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-8423f420455so1502397b3a.3 for ; Wed, 03 Jun 2026 01:10:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780474242; x=1781079042; darn=postgresql.org; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:from:subject:cc:to:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=kwEjbUARbCiEwJOPTg5TT4IvYcLxrbSTsWo3XswQ8iU=; b=Muv4umbjWy9ds+YabgGsh70w+yflOQI7lU8DYd8SmRKfxGcjypPYAqkJbSAiruva5W 30vbbkKRXyyGz4rUVXdgSU7N8U6pD8BOr5VeGH330yopuvW1Zgq1JVx9okcvE6jTgJvI 1vWLq8eeEWQQceSZLUA1GCpexfHOa/OqcDHR59/9l1+dvnBdJYOZJkhW+UlKqDFajksB NtC3Hil4N7LxweoBvAPv/+/qJbgdXhWCkp6X6cXWvJRjVDsNpo8Suu7ekrZj35o52zG5 lal0ZpGsigvgexLZ1aa/QFFZ2RUFjM9aG0i3biu++WQSLDMVBvH09GXjAX1DtKElF74J emkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780474242; x=1781079042; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:from:subject:cc:to:message-id:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kwEjbUARbCiEwJOPTg5TT4IvYcLxrbSTsWo3XswQ8iU=; b=hSgn4nl8pRE2xR7UwhiraAUkzSTAnIyDp+H6y4IC5hpy1VluwuRThNbhZ7/UZRCRtu TOYC3hZ1lwsGd3m4DWeK952qP/ShfytHsrAFoWiSil34rOmBxpA6PYoDxFlYsRWpA+Xn Tpu/289XRswGQuF6rWNDKR9PwM4rJEXv9TJ4PZwCUENl5qc7ZcndiYj2ZM50a+33Lzim mnTrtmTWm1mImmGqrvdsc0IeiuQya+LHHVtynHgQ34bfAY8l/8UOFz72iKhREsMWkHHC fsb5Q90ix+qNzCJrstaTq8xL3uBsK+sd5eQQEqPbZfM5pymX5WxNLwJksJDebKxFZtav vwfw== X-Forwarded-Encrypted: i=1; AFNElJ+aebx+aEhAYmNsyu4v0nNu9mzo/8CgGIvbKdSlL0Mtu1dizPnKRAhEfqiiBnCXDSdxCS7ot9Ye2vbCX42C@postgresql.org X-Gm-Message-State: AOJu0YyMDC/61S2iqkEk7G/A9FyoL5JQH06/0onjjz3jL0SbpzT1PG/8 b6LWYzvtrxatGlghVigGzhy1beq++L+pGVwkiTLOQHbyyxvChtE+UGUu X-Gm-Gg: Acq92OGlKrvCEiadXnUzfh4ouhJriWy3u+3iB0w3DMFBAvnvpP5Y0JxL4a87Uvt82cU ajg25V3fVtXiGjKQbmseRNQoj/57FEy1ujDHyRy/ipr+GBHgTXXQnVwkGl6LZOJ0sIEBX1JKKx8 U6ITeKpDDoBQA6SSAk/dY8yXr8cG7u6PFVYMw/1KDxREdkayLBuh1Vcbwu/394zSaRW3m4HlzK5 SYJj7fuB68h4jTrh7iM8IbVkdS/BF4Xo5fJ6Kgo904VUk9NL11B+G6QIrw+iureGcpYAO/1VTOS Jqc+eKEse5PdFiQYWo79XaUnzpV7odZqerDGSG/JjzEiK4h9WZRwmiwkqj4pewdumi91nrjvEzi rC+QC0hpHzKcWlH3l0pf7f7JMl48A4DP03eH0ZBqs4JTkvJIvNSjpKPj2wjyYYopjaxnVi4o5cv 2V032pHKJ3Zw2+huXuXs3ql4OSTG4p+D5AHsfGV17J9KRM0M5N02PCfwTFkMZa3FiZjYnV8IbBi ADMAsZofQ== X-Received: by 2002:a05:6a00:3e12:b0:842:672e:7b5d with SMTP id d2e1a72fcca58-84284e32751mr2346346b3a.17.1780474242225; Wed, 03 Jun 2026 01:10:42 -0700 (PDT) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-842822222ccsm2498800b3a.3.2026.06.03.01.10.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 01:10:41 -0700 (PDT) Date: Wed, 03 Jun 2026 17:10:39 +0900 (JST) Message-Id: <20260603.171039.1005148564287106445.horikyota.ntt@gmail.com> To: michael@paquier.xyz Cc: samimseih@gmail.com, lukas@fittl.com, pgsql-hackers@postgresql.org Subject: Re: Improve pg_stat_statements scalability From: Kyotaro Horiguchi In-Reply-To: References: <20260601.135858.1116584574478485492.horikyota.ntt@gmail.com> User-Agent: Mew version 6.8 on Emacs 29.4 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello, At Tue, 2 Jun 2026 15:30:40 +0900, Michael Paquier wrote in > Hmm, OK. One cost in this decision is that it could randomly make the > tests randomly slower, which is one reason why this patch has been > added to this thread. That's a fair point. If this interface is primarily intended for testing purposes, then I don't think throttling is particularly important. On the other hand, if it is expected to be used outside testing as well, I think some form of throttling would still make sense. In that case, I think pg_stat_force_next_flush() should probably apply to anytime flushes as well. > > I wonder whether it would be cleaner for the caller to make the lifetime > > decision, based on the kind of flush being performed, and for the > > callback to be told that flush context explicitly. For example, the > > callback could be passed whether this is an anytime flush or a > > transaction-boundary flush, flush the counters that are appropriate for > > that context, and then return whether any counters remain. > > So you would suggest to extend the flush callback(s) with a context > value instead of having each flush callback do their own decisions > depending on if we are in a transaction block or not, right? Yes, that's roughly what I had in mind. My concern was that the callback result used to answer a simple question: whether anything remained after the flush. The flush context is already known by the caller, so it seems cleaner to keep that information separate. The callback can simply report whether anything remains. That keeps the meaning of the callback result straightforward. The caller can make decisions based on the flush context, while the callback only reports the state of the counters themselves. One alternative would be to introduce a separate callback for anytime flushes. However, since transaction-boundary flushes ultimately need to flush everything anyway, it seems to me that passing a context flag would be sufficient. > Another question that I would have for you is: do you think that we > should try to keep pgstat_report_stat() as the sole entry point for > the flush of the stats? Or should we try to keep the same approach as > what this patch is doing with a new routine that loops through the > flush callbacks? FWIW, I am kind of finding the approach of having a > single entry point rather than two as more appealing with the > long-term picture in mind. That's just a single take, where we could > just pgstat_report_stat() an extra argument based on the context where > it is called, lifting its current !IsTransactionOrTransactionBlock() > requirement. > > As you are the original author of this area of this code, I'd be > really interested in your opinion here. I tend to agree with the single-entry-point approach. The basic operation is common; the anytime case differs only in the context in which the flush is requested. The flush-timing logic in pgstat_report_stat() may become slightly more complicated with anytime flushes, but after that point I think the existing path should continue to work with only minor adjustments, by carrying an explicit context value down to the callbacks. Regards. -- Kyotaro Horiguchi NTT Open Source Software Center