Re: n_ins_since_vacuum stats for aborted transactions

Euler Taveira <euler@eulerto.com>

From: "Euler Taveira" <euler@eulerto.com>
To: "Sami Imseih" <samimseih@gmail.com>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-04-09T18:07:19Z
Lists: pgsql-hackers
On Wed, Apr 9, 2025, at 1:57 PM, Sami Imseih wrote:
> I came across what appears to be incorrect behavior in the
> pg_stat_all_tables.n_ins_since_vacuum
> counter after a rollback.

This is *not* an oversight. It is by design. See commit b07642dbcd8d. The
documentation says

  Estimated number of rows inserted since this table was last vacuumed

Those rows were actually inserted. They are physically in the data files. And
that's what matters for the autovacuum algorithm.


--
Euler Taveira
EDB   https://www.enterprisedb.com/

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Add code comment explaining ins_since_vacuum and aborted inserts

  2. Trigger autovacuum based on number of INSERTs