Re: N_live_tup value is less than actual row count in a table

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Teja Jakkidi <teja(dot)jakkidi05(at)gmail(dot)com>
Cc: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: N_live_tup value is less than actual row count in a table
Date: 2022-06-10 20:46:58
Message-ID: 2730997.1654894018@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Teja Jakkidi <teja(dot)jakkidi05(at)gmail(dot)com> writes:
> I have a test table with 100000 rows and I deleted 20000 rows. So the current rows are 80000 and dead tuples should be 20000. After autovacuum completed, the dead tuples were gone.
> When querying the pg_stat_all_tables, it returned n_live_tup value as 63945. Why is it less than actual row count 80000?

The pg_stats counters are only approximate. In the first place, they're
updated using a simplistic model that can't 100% account for the effects
of concurrent transactions, and in the second place, it's possible for
the stats mechanism to drop update messages altogether under load.
With so few details it's impossible to speculate about just why your
counter was so far off ... but no, you should not expect exactness.

regards, tom lane

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Kristjan Mustkivi 2022-06-13 14:04:25 Pgbouncer pool_mode and application behavior
Previous Message Teja Jakkidi 2022-06-10 20:23:26 N_live_tup value is less than actual row count in a table