pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
To: Staroverov Ilja <i.staroverov@ftdata.ru>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: VACUUM/ANALYZE double-count the backend's own pending table stats
Date: Thu, 5 Nov 2026 05:48:38 +0000
Message-ID: <auwYtm6qM3fPltNF@bdtpg> (raw)
In-Reply-To: <1DC9D815-8754-4A76-B2B1-99C1A614A55A@localhost.localdomain>

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#07b7a951d9a983...

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com






view thread (15+ messages)  latest in thread

Message-ID: <auwYtm6qM3fPltNF@bdtpg>
Permalink:  ../auwYtm6qM3fPltNF@bdtpg/
Also on:    postgresql.org/message-id/auwYtm6qM3fPltNF@bdtpg

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: bertranddrouvot.pg@gmail.com, i.staroverov@ftdata.ru
  Subject: Re: VACUUM/ANALYZE double-count the backend's own pending table stats
  In-Reply-To: <auwYtm6qM3fPltNF@bdtpg>
  References: <1DC9D815-8754-4A76-B2B1-99C1A614A55A@localhost.localdomain> <auwYtm6qM3fPltNF@bdtpg>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox