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.98.2) (envelope-from ) id 1xOqL8-00000000MU4-0aSO for pgsql-bugs@arkaria.postgresql.org; Thu, 05 Nov 2026 05:48:47 +0000 Received: from localhost ([127.0.0.1]:49988 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xOqL7-0000000AgJy-28Qx for pgsql-bugs@arkaria.postgresql.org; Thu, 05 Nov 2026 05:48:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:32804) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xOqL7-0000000AgJp-0ncy for pgsql-bugs@lists.postgresql.org; Thu, 05 Nov 2026 05:48:45 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1xOqL4-00000000Lp1-0z9Z for pgsql-bugs@lists.postgresql.org; Thu, 05 Nov 2026 05:48:44 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-4a4d7ae1ae9so14174055e9.1 for ; Wed, 04 Nov 2026 21:48:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793857720; x=1794462520; darn=lists.postgresql.org; h=in-reply-to:content-disposition:content-type:mime-version :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to:content-type; bh=xVfS8uVOP+MHRaZqpxPUvwknolw6ktPmaSMGMwTyYPA=; b=uh7rQMbmnX9KSp0TXsFMs6HRE2J5gDUfBlX65bGdi5LDNTdUwohXfYotVBDt9SMsO3 gti4gTt02al+KRyfx93cZQRDvP49NKtdJWAJNs+5QCyu8CLEMa/OP5EC5u/gy7vp7DmE GeG9HjXx5xJdwR7UGxcOnfe18RNszD/m++E6rKrBg3R+ORvUvfVVdQtV6ZUOOS+IoVbb ZVuuYB62xax5T7OkkJvVCO3hzoE9FlBEokMaJztB2lGIKyvCMrG+iLbYBLUseB3fHRTm 7M/9StwmZwG3vL4gZo5BSW8BuvvZ8cENp6Eib2ZNKtvZnBO0Ke9lqZYflBj6mrmONbRy RMuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793857720; x=1794462520; h=in-reply-to:content-disposition:content-type:mime-version :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=xVfS8uVOP+MHRaZqpxPUvwknolw6ktPmaSMGMwTyYPA=; b=P27nCVZKXS2Aj7x7vJQRAK8DnVcxhcmI8C0T03SjXDpJkjeR0IzSFb1YlZbplQyCbV jWmjD5XAP8dksCW/oak4pXgxTNm5c4efv6SG5ffb+j4f9lL1ZR8jmgIPddl6jfQFHASc sP/29xaI0Gfg1vL+VUiFAEiAC0jZ9vK/iTsnv5Q99spl9l7NO+0XiPL5stLi1XbkH7MT 6o5jZvomzdrjfRd/bV+7LozJ8ETWc3Roxxm7GM0f62RGpPUY8r/9xrJdy3RwgZU0YMnH zlzxOhoMCXfdqfnGQHhB7T91yHZMD4IKe4bSHnMM84P8+Xw197P6W4ybbk8cnZQrl+rf oAZw== X-Gm-Message-State: APuU4Z8xYoYLcRJHyLAA7Qt8f73bKGRanYoa3JOyMDhN/GlD5OauVxjg jQjwXwY/jZqyfUrtkwDi5aCzdvjnZ5N+dUyNbzIWMEcpi1U5XQ3hGC79QjxrqA== X-Gm-Gg: AYBFou3stn/NVnTzIcGPdnGWxgWA/6hhGyFA3KFCLBQ9tWy7DJcG+q8W7o1qI0cofjt C2QLL88615PnIdi7/KszsmS+vSxxtFIn1X6h/JNkcQkQHW8VzJvgONsB3+TG5MKLLWXKqOh7U/2 G9rDUJiTTfl3QmS1GviHQ0H33li4g/M9n0yhJOTzKeqjZ5BmHcoKRP7vnzdtjg+kR7iQwzKkEm1 WaUdJDmT2ZlkbHwk0lJ9ggfGqQ83cqkKUdeJbhG5Tmnnk2oq8PvIOBNyWE3qpVrt9katXGjK93G hSAB24Etzih52CrItSFe9k93AMgsOvwF/c5pR9ySka2yUh6UHASvl/LfjV/dT8H3qMi9XFROZ/A m+LWU4rK6ai3n6I1zsCIQslgGFbLJ74lVI4RhFpEnA3IcZYTy31awWvS8r8774VosGo/AsI5cpE P2XErb+GKuNdLjsrXgv4KQvfxQYB8LUBwBoX9Ylq2ArMtXFdfCTZBMCEDpeG9jWEmJ+wNqyogsZ E6q+SdsoVIdvEj4UZTvjqSP4TdRM4PLI0v2UHXBhEEnR0/xt3YiSbjhZiya9lKba38OH7fdQGJf ch9MFUug9JQZ96j1Q+M6NqZt2kih8kbyYaePkAyBMYml9GdyQqqlsgnWCnFS4YBX/x+QLQQkYLy eQR0jwAx7sgAT X-Received: by 2002:a05:600c:5249:b0:4a7:7f3f:6f8e with SMTP id 5b1f17b1804b1-4ac1228b5bfmr400530875e9.0.1793857720441; Wed, 04 Nov 2026 21:48:40 -0800 (PST) Received: from bdtpg (ec2-15-237-197-144.eu-west-3.compute.amazonaws.com. [15.237.197.144]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4b571f46538sm35608845e9.5.2026.11.04.21.48.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2026 21:48:40 -0800 (PST) Date: Thu, 5 Nov 2026 05:48:38 +0000 From: Bertrand Drouvot To: Staroverov Ilja Cc: pgsql-bugs@lists.postgresql.org Subject: Re: VACUUM/ANALYZE double-count the backend's own pending table stats Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1DC9D815-8754-4A76-B2B1-99C1A614A55A@localhost.localdomain> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, > VACUUM and ANALYZE overwrite live_tuples/dead_tuples in the shared stats > entry with their own counts. Those counts already include the effects > of transactions this backend committed earlier. But the matching deltas > can still be pending in the backend's local stats, because pending > stats are flushed at most once per PGSTAT_MIN_INTERVAL. They are then > added again on top of the new values at the next flush It looks like to me that those cases cases fall into the same category as [1] which was ultimately not considered a bug. > A related problem is in the same file. AtEOXact_PgStat_Relations() > does > > relstat->tab.truncdropped = trans->truncdropped; > > on every commit. So if one transaction truncates a table and a later > transaction of the same backend modifies it before the pending stats > are flushed, the pending truncation reset is lost. No VACUUM or ANALYZE > is needed for this one: > > > -- t has 1000 rows, stats flushed > TRUNCATE t; > INSERT INTO t SELECT generate_series(1, 300); > SELECT pg_stat_force_next_flush(); > -- n_live_tup = 1300 (count(*) = 300) So maybe only the TRUNCATE case deserves a fix? [1]: https://postgr.es/m/xnd433j72ixptoydkifnleke43bvql4rxrw4ohnodx6hk4wcho%40m46ab2bt33jh#07b7a951d9a983ce9432d6bf86979ff2 Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com