Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nzlXB-0000TD-BF for pgsql-admin@arkaria.postgresql.org; Fri, 10 Jun 2022 20:47:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nzlX9-0001F6-RB for pgsql-admin@arkaria.postgresql.org; Fri, 10 Jun 2022 20:47:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nzlX9-0001Ex-Gd for pgsql-admin@lists.postgresql.org; Fri, 10 Jun 2022 20:47:07 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nzlX2-0000iL-Mr for pgsql-admin@lists.postgresql.org; Fri, 10 Jun 2022 20:47:06 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 25AKkw4W2730998; Fri, 10 Jun 2022 16:46:58 -0400 From: Tom Lane To: Teja Jakkidi cc: pgsql-admin@lists.postgresql.org Subject: Re: N_live_tup value is less than actual row count in a table In-reply-to: References: Comments: In-reply-to Teja Jakkidi message dated "Fri, 10 Jun 2022 13:23:26 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2730996.1654894018.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 10 Jun 2022 16:46:58 -0400 Message-ID: <2730997.1654894018@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Teja Jakkidi writes: > I have a test table with 100000 rows and I deleted 20000 rows. So the cu= rrent rows are 80000 and dead tuples should be 20000. After autovacuum com= pleted, the dead tuples were gone. > When querying the pg_stat_all_tables, it returned n_live_tup value as 63= 945. 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