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 1vufeP-000miw-11 for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Feb 2026 23:47:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vufeO-00Fx2H-0P for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Feb 2026 23:47:40 +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 1vufeN-00Fx27-2R for pgsql-hackers@lists.postgresql.org; Mon, 23 Feb 2026 23:47:39 +0000 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vufeK-00000000sAH-2SAw for pgsql-hackers@lists.postgresql.org; Mon, 23 Feb 2026 23:47:38 +0000 Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-65a11e565a9so5350881a12.3 for ; Mon, 23 Feb 2026 15:47:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1771890454; cv=none; d=google.com; s=arc-20240605; b=TRFSh5plgm4Qs3oIr3OpCui0Mbhjxlb6s/14MVbBKCuxbpx8Ys8oL0xz5CTzH9DOiK 0gw8neWK5n8Ma3TdDxoWnntLTIE4uWUdXnPc6nnZQEUQs8sOSc++prS95XhFjHGeIC8s BtkavgeNAgp73iJrowzP1JOp9qxzkojPJzymQYE1o30B4+8zSnofWvLE1qVHYdtuALf/ Mu2qq4/1v81SJ49qOm01AnS9NvpNI4IDWH4uHmrkT96YVWqJ9reVcS2wOFjmWJ4q3qaw 8G5tjhFjl26gb1/jwqp8bGMJ348I4kmNs8wFsAPzjBv0/bPWCgSxJb5Qo65JCiInvlUv CeNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=jnqVSOy/+Tmbw30/S+56tLEL/5yc7oHFbanQm271y4Q=; fh=yfb7i8Wjoi86vvHfFLjilR94SywUuJhmFIPkYYp1WuM=; b=djkoIsHcC/Guao/yUhG4NU8pXqhLRNAHd4m6VueiaorZ4tSGSVkYrlzTy/xa+DTEM5 5SeTtsIBqYBGzQgqVG4DoS+C9yh8LrnFfzLKmBxIztes/cSg249qq2UInJtegiwMgg+K etXAWZjVhcr061/AFINFLUbe7l+ksuWhwqCfGV4XDK2mvz3vRpzguCxwBpm0mqikLckj cOUX8BKnqATH8+jWUI7Hiyjd4yg3AtQxXOQqRBgTKb4FNN80XadaSicxbzxyDgaqCgW1 4/bax5ul9IXYwsGh0/y6AAvyGm7enfL7zKINxJ6y0u6RzvdmLXur2JpHmHJ2xGNIymR4 7gpQ==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771890454; x=1772495254; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=jnqVSOy/+Tmbw30/S+56tLEL/5yc7oHFbanQm271y4Q=; b=dxG62T2R7P5R7XpkRChRBw9u+gBqXXSDLEARSOxj3os+6oM5wZaUgFHEpuhsHPw0Bf Cr5snmLOR/vr6aYUt9Bb9wFMl1kqIqbuAJU46CFLS1ikMzli3L7Xae1mYNVZ3gkRbKDa vSsA1k1xmZleHqaZIlSX+X0Nap2LdKK+HCN6W57SXTge02a7GYSe1hXN2SJJitaSZDqi KXS4bd6z2K/kyeGglECvsWkPKdjn6RZRM1Cni3rZ87mJViFFppMBE+Na5hEweZIXZT7Q mgw8on8oJqLj6H1bE53lwFWnmptx6KysqCbqe7+86v1TQzZDzvi6v9j+DH68mFNPUVcl EqYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771890454; x=1772495254; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=jnqVSOy/+Tmbw30/S+56tLEL/5yc7oHFbanQm271y4Q=; b=vBrm6b0iqBOsr7OCW4dz2IY5jSelB1OVwfze+/W2zQSpXSmC7JkpA6O/uN/59aUsuu QYpc9cqnItI8KvaYzMsIIl+aodcUPsF3XCouoOzOzFaW1nRmiKqryCGZ03yuSH7COf5m 7pm5DcxjrzQtk+G5z8hdYod6BtUPd8JCUfdl7Es8ToEUZArctmcuhMdS7KNj3TTsZXDJ XuG+UTGKe6lWKNfTolu1D/+/8OSe2yIHkjnLqVTK7ld2ycjEkpJjg0TvwJIQrxZvyxX4 aBmRpeQw0kZ25rwWKbYxY8hzIBXUQHS0BwKrL110t5WjVkB/wr1JBwfJyxLJarxcZWLs +0kg== X-Forwarded-Encrypted: i=1; AJvYcCUW8rBUm8VA1lYsEV/tVOkrMhWQoH28kL9Bw0fGnwbuWKpbOZaNuh4LXqoQJ3gx2bnmR4pPfaRolox267JS@lists.postgresql.org X-Gm-Message-State: AOJu0YwNmnwCGhcZFbTNfkEazNoP9wS+mGTxQvG5pj1pOeBuzHSV8xkM jMWLmNzIzT2j4Ab+e6t2rczVVUATX353EWp5PpCiHgG5zwAZEn12RgHVL/05W8UE4ahf8dlIsEF RhXGs5cxk4w6yXwMqTtVkKdJetaS/Qvw= X-Gm-Gg: ATEYQzw9Q13Np1bWRnsafCbPgZWhK+A7Rc8TNPRnczHXA/eowEm8OxAZEUibjSiL5GW l0+IwK8sus4wF+yVNYaWFUCHR+dRkOHCKhFqY1fvBuF5e0MeTuS3JfNMFIag4D6cwtDSW2zyNZ2 7lEfUlqI3gQtXTVkKO/iuuRW/dKZA72Sw+uN059P4DGFLe6O9/uF2aixV8h70Ms18hLPpTdVyZ5 ACJBD893fZmI3KTPXgp5B8Wi0nmH2fdeVTDuvLXHi9zPBpXbRMTTTUfG0tBKIP4Wk958OnNX9dw 9wWUJA== X-Received: by 2002:a05:6402:51c9:b0:65c:2377:3344 with SMTP id 4fb4d7f45d1cf-65ea511737emr5559058a12.25.1771890454242; Mon, 23 Feb 2026 15:47:34 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Sami Imseih Date: Mon, 23 Feb 2026 17:47:22 -0600 X-Gm-Features: AaiRm50wUh4n-BWoM8rxdkuNAMCehmp50FFFkQxNcgO6oKQgvTM3iRd8mMr-3lU Message-ID: Subject: Re: Flush some statistics within running transactions To: Bertrand Drouvot Cc: Michael Paquier , Fujii Masao , pgsql-hackers@lists.postgresql.org, Zsolt Parragi Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > > For variable-length statistics, perhaps we can do things a bit > > differently than what is currently proposed. 0005 requires > > a relation anytime stat update to call > > pgstat_schedule_anytime_update(). This is done this way because > > it allows long-running queries to update their stats every > > stats_flush_interval using a timeout. > > > > But maybe what we should be doing for variable-numbered stats is > > to schedule an anytime update whenever a "transaction goes idle". > > I think the logic for fixed stats and variable stats should be the same. If > not we could observe discrepancies: for example a long running select could > genereate reads/hits IO visible in pg_stat_io but tuples_returned, tuples_fetched, > blocks_fetched or blocks_hit would not be updated until the session goes idle. After having more time to think about this, I believe it can be much simpler. As soon as we enter an idle-in-transaction (aborted) state, we can simply schedule an anytime update. This ensures that a flush is scheduled whenever the fixed stats trigger one, which will likely be the most common reason (e.g., I/O stats, WAL stats, etc.). To cover the cases where fixed stats do not schedule a flush, we can also schedule one as soon as a transaction goes idle. In my mind, this makes this whole flushing scheduling behavior easy to reason about, and if we introduce future anytime stats anywhere, we are not required to schedule a flush for each individual field. The flush callback will of course still need to decide what to flush anytime or at the transaction boundary. What do you think? -- Sami Imseih Amazon Web Services (AWS)