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 1vgi9S-000u4k-1N for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Jan 2026 11:38:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vgi9R-002zXD-1J for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Jan 2026 11:38:01 +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 1vgi9R-002zX5-0F for pgsql-hackers@lists.postgresql.org; Fri, 16 Jan 2026 11:38:01 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vgi9O-000kJy-2y for pgsql-hackers@lists.postgresql.org; Fri, 16 Jan 2026 11:38:00 +0000 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-47ee4338e01so7812245e9.2 for ; Fri, 16 Jan 2026 03:37:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768563477; x=1769168277; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=6DJvfsj/C/QX7rYNCvsdHCyLCLczuZNCT2qpcXqg/2E=; b=CXlAtzg2TtG63PCiURPHtucUdV5OdGpshzBozc7SjYtUAJhfkSDh32haY43XDAsQM0 2GvLvP0Xwsv2M143VwWmNODaMiua7Fen90Wme8CrE9g4kdaz+U6R/EvNeDIztVNvYKdP 8W96+puXNmL4kZELm+xcojfi4uUK49arMMmJQQlsfFt0QjGopq6KciE3LYCuVflK+0WO 3ncpsVpiiml6gF0BT/GNKRaFFm3QRFrTvWLLYZNwrC6ING3I0H/cp+tW1MS3lXCdy3Wh rGfY3XbFsUmYv15AOL1f0HN/TXDzQHVJgs0CTLlNYqZ4ZEMWYWv4pK7sZhacFv2SnQUO 2aQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768563477; x=1769168277; h=in-reply-to:content-transfer-encoding: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=6DJvfsj/C/QX7rYNCvsdHCyLCLczuZNCT2qpcXqg/2E=; b=UIZVBkMyrYeYmjHcdYF2QL+EmzcRWzss8eik3ZrQP/8OYKBIYrWgmUlPBodnYHoyuo 4XVRZ8gCCLMdFxk13mKv0rUm+sFJ7OZ1X1YaguuqnMQKsEOHvzotW3bTHw8ZZ1OU1ZfD kIIQoW+gLXzndW/wC7jB80dhKi6aFYEcUltCz1bsrRSgiTO1bJWFlCFcV7SgdQyTPzsF L0PjSy7jgXI5iTC84dePvNd13ZLkBc4nJgaCog14lmm3kgNUuxij1nYS7pSqnVecdcqg RH78du5IhTzu0cg8VnraUBFCFHDVp3d7KalQrX5a2/caSZSUy9wJ3gj/YpEMm6h4iMQA +bmA== X-Gm-Message-State: AOJu0YzM3+DxlZNayJ6yxV3yUJgssijlF8GjU8tRUGw8QWE893JLkySR L/u7aAODtz1hvw9u7nzSL1uFeh50ieX43XtorpSqtvseV/qIE+6kYu7r X-Gm-Gg: AY/fxX65//hu69ogI1vVC3nUMIAjq4aQDKADHKGQ3jB2d54KYOUk9l0szN3HxSiKFSy 8HsAhcGSVDw8/rC1upmp1Xz9TDRsn5gPe3+VYWqyZdnB7f2MG60U9WTz06FGvKwa5fEhCkvK7Bn LPL9xdrH5lSSOYOOKAzqn/UpPqq0wIsn/AlJQHKlKDh1Z1kLN0DGJM8QconHiYAzH04No4AvhGs SoWHwayH9ChixqQqz6MR8jYyeI8rnhojrVlwLdmVT4DnAHOjB5VeEhk+DiSOwG0HFMrwD7AeTFW 3mtiJ7vBDz1RXl8Ca078V2dbzFW9lRQY5uPFrW2uWxr/yr4eUYC3MfSBZ0Hs8VrIeU0BhAyEirn kz1IlL8ON5Qogcca2T/zR66mzr9iH1slSoLRZGalYKErfJxbAGpODlRz/UA/C/IkBqELPCaI+DD Q2h0DI1EtZLG+Vq/aLDxIpHP18ggM7SSG9OCJjQvyHMPp+DaQl3pd9te6CTLM3vAtjL7AoyQxwt pUYUahY6j/NT9Ja8bQUQJSVtsSP3AL1WYnA8iqZ+d5FvQ== X-Received: by 2002:a05:600c:4587:b0:47e:e952:86c9 with SMTP id 5b1f17b1804b1-4801ea340d1mr25212275e9.0.1768563476688; Fri, 16 Jan 2026 03:37:56 -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-435699271dfsm4654711f8f.15.2026.01.16.03.37.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jan 2026 03:37:56 -0800 (PST) Date: Fri, 16 Jan 2026 11:37:55 +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: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Thu, Jan 15, 2026 at 11:25:18AM -0600, Sami Imseih wrote: > > > > The 1 second flush interval is currently hardcoded but we could imagine increase > > > > it or make it configurable. > > > > > > Someone may want to turn this off as well. I think a GUC will be needed. > > > > I gave this more thoughts and I wonder if this should be configurable at all. > > I mean, we don't do it for PGSTAT_MIN_INTERVAL, PGSTAT_MAX_INTERVAL and > > PGSTAT_IDLE_INTERVAL. We could imagine make it configurable if it produces > > noticeable performance impact but that's not what I observed. > > Is there a reason we need a new constant (PGSTAT_ANYTIME_FLUSH_INTERVAL) > for anytime flushes and can't rely on the existing PGSTAT_MIN_INTERVAL? It currently gives flexibility for testing. If we agree that 1s is the right value to set and that it should not be configurable then yeah we could replace it with PGSTAT_MIN_INTERVAL then. > Also, How did you benchmark? I am less concerned about long running > transactions, > background processes and more about short/high concurrency transactions seeing > additional overhead due to additional flushing. Is that latter a concern? I ran 3 kinds of tests: 1/ pgbench -c 32 -j 4 -T 60 -f short.sql -n -r $DB with short.sql: \set t1 random(1, 100) \set t2 random(1, 100) \set t3 random(1, 100) \set t4 random(1, 100) \set t5 random(1, 100) \set t6 random(1, 100) \set t7 random(1, 100) \set t8 random(1, 100) \set t9 random(1, 100) \set t10 random(1, 100) \set row random(1, 1000) BEGIN; UPDATE t:t1 SET val = val + 1 WHERE id = :row; UPDATE t:t2 SET val = val + 1 WHERE id = :row; UPDATE t:t3 SET val = val + 1 WHERE id = :row; UPDATE t:t4 SET val = val + 1 WHERE id = :row; UPDATE t:t5 SET val = val + 1 WHERE id = :row; UPDATE t:t6 SET val = val + 1 WHERE id = :row; UPDATE t:t7 SET val = val + 1 WHERE id = :row; UPDATE t:t8 SET val = val + 1 WHERE id = :row; UPDATE t:t9 SET val = val + 1 WHERE id = :row; UPDATE t:t10 SET val = val + 1 WHERE id = :row; COMMIT; 2/ psql $DB -f long.sql with long.sql: DO $$ BEGIN FOR i IN 1..100 LOOP EXECUTE format('TRUNCATE TABLE t%s', i); EXECUTE format('INSERT INTO t%s SELECT generate_series(1, 1000000)', i); EXECUTE format('UPDATE t%s SET val = val + 1', i); EXECUTE format('SELECT COUNT(1) FROM t%s', i); END LOOP; END $$; 3/ pgbench -i -s 50 $DB pgbench -c 32 -j 4 -T 60 -N -n -r $DB 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? > > > I’m concerned that fields being temporarily out of sync might impact monitoring > > > calculations, if the formula is dealing with fields that have > > > different flush strategies. > > > > That's a good point. Maybe we should document the fields flush strategy? > > Yeah, we will need to document this. Will do in the next version. > I checked by running seq scans in a long running transaction, > and I observed both for these values being updated at the same time. I think > this is OK. > I do think the same. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com