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 1vur6f-009rbf-3B for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Feb 2026 12:01:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vur6e-0010SP-2a for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Feb 2026 12:01:36 +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 1vur6e-0010SG-1b for pgsql-hackers@lists.postgresql.org; Tue, 24 Feb 2026 12:01:36 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vur6b-00000000xBO-1WKE for pgsql-hackers@lists.postgresql.org; Tue, 24 Feb 2026 12:01:35 +0000 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-483abed83b6so20828785e9.0 for ; Tue, 24 Feb 2026 04:01:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771934493; x=1772539293; 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=PeH0YrUa2N6WR24NTT8kn1xT8Q1Oq22rQ4jtjyWLzg4=; b=fKrB3b1d9CHTiQhfbQ1aRp0pCRAJFQlDa1wN6Pcz+IIwtYyOGr+7AvNqK9Q2w+bhmu cUXf4C0VHivO6SSNfrFiGPX1G3JV1NxS1s2/bUntWSFbNoSiXKgHMhioFwJhYYR2gOzP vG0PjLd/hfhy3KO204JODiwkdYrIfnboeoEYdKkik+oMcLiKKfOcteld/F/0phOm7YBQ DZIXXl+hveLgKfzWsBfypF/Iq7Iwq4PLsjSv9vxmrCRTWjeLaYtF0+GYHswJG9gFtLFg XWC5VGDv/SXNC9DCr1q7i6f2uiHgLybgmkuMLowZKX8xfMkP2gEbBV6uVehJL5GOD4uJ t1Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771934493; x=1772539293; 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=PeH0YrUa2N6WR24NTT8kn1xT8Q1Oq22rQ4jtjyWLzg4=; b=MOf+jehDzFDYrxCvRuqxISUnSR/B5SC4VIKOH9e5yVWazqCIa9FHbePqNujLF92/63 bSBNyRwKmitWZD4NR7F9Qql+6Y8ItxE9q8aOzU9iWnfQoWAFf8/pwko6I7xQnuMl/zFE 2KcoYD8FxbRkT+ar9AhWTD6bdewT/MTGipUM2Tpvrpm+N1/VTZzAYE557LGIgPbKvr5N 3nhEcKJ4UsBshuc87QqM6R+3BVnPIGANUlUQ+f3tCfi+upnYWlOj7v0PUp0qPCbj4Id8 hQNQI7YOvVmirTOxogqGM+qdotCOslPIK485+H7DLWgoyriOkjcgr0jZ0yPFEYGrzran dW0Q== X-Forwarded-Encrypted: i=1; AJvYcCUtM5xVjlla/g2h82CpGbXU4AeKaU0row3K1x82uQeHjru+6v63WL8ILbbXEPSiOIqKGcKaTCDrJMIKRFfN@lists.postgresql.org X-Gm-Message-State: AOJu0YyQM5Mnn9vCsw4aYXL92DP0MEyZ5xUcKuHMskY6wqTZ04uJLbxf CxXell66esVTzdP3wK/o3SiDq4j/iWkUMzfEvQszmtD56N402iqNVrvf X-Gm-Gg: AZuq6aJFJNY6kQs1jOUxuIp3Igs5Ybs3um82bj+aNqVNs7wX+7jFExi5lwZKTOv7KcR wt+14Va7spbdN1qJi9zvgmkQjiLYgeRuXg1zh2N3XzJR9jyCgF0JhIbDCm8AV1cHbGHFiL1En3Q OoxD+PIrtYv+iyWb7QPYDmWGcpZ5rrw0tRkNUl3O0Ma2SJ+rPwsr8ylHy70J7SE0XspsTtJQ5CH i1DphC3t/55Mrzd+bT9MEelsXkBoT4QuJ2N8Q/j0g3newwC1GsPjfJdJowYo0Ypx950iJZ9mcSt kb004rH2b4wORWRoTo1R7HbeTAAEslhF2yyhb4fnTUVMeRcQP1NTM4vCl7OKikenyv9s0dqV6OX bnntw//eqv3logHMIirPIIy0fepzmq1OPTz80eIL5o+YVBd9s/Nd59Qb2kGp7YwnubxNhdrR6/D HhNxGwP36NLL5ZRvc4ONRRFralVyNGT0c1SM57Hxim3GoYYDdR5j+8cPLmdr29zOPAp2hlI9C7P v1JX6N9+P5m74y0W+FISunqynz52AG4y11cBiA6hgG1cxfekpcRjvDX6Q== X-Received: by 2002:a05:600c:3b0a:b0:480:4ae2:def1 with SMTP id 5b1f17b1804b1-483a95be7c9mr235516765e9.13.1771934492502; Tue, 24 Feb 2026 04:01:32 -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 ffacd0b85a97d-43970bfa015sm26351928f8f.8.2026.02.24.04.01.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Feb 2026 04:01:32 -0800 (PST) Date: Tue, 24 Feb 2026 12:01:30 +0000 From: Bertrand Drouvot To: Sami Imseih Cc: Michael Paquier , 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: 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 Mon, Feb 23, 2026 at 05:47:22PM -0600, Sami Imseih wrote: > > > 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? My understanding is that (correct me if I'm wrong): - fixed stats would still be designed the way it is in v11 - variable stats would not need the pgstat_schedule_anytime_update() calls in various places. The flush would be done/schedule when the session goes idle. Then I agree that that looks ok and that: > 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.) Though I don't think that adresses Michael's concern: "main worries are mainly around 1), I guess, with the new SIGALRM handler requirements for all auxiliary processes" in [1]. Regards, [1]: https://postgr.es/m/aZznT84Ssh8PywcH%40paquier.xyz -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com