Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iDqfd-0002z7-3C for pgsql-general@arkaria.postgresql.org; Fri, 27 Sep 2019 13:52:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iDqfb-000100-MC for pgsql-general@arkaria.postgresql.org; Fri, 27 Sep 2019 13:52:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iDqfb-0000zt-Cg for pgsql-general@lists.postgresql.org; Fri, 27 Sep 2019 13:52:27 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iDqfY-0003Ts-Ir for pgsql-general@postgresql.org; Fri, 27 Sep 2019 13:52:26 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x8RDqMoN020078; Fri, 27 Sep 2019 09:52:22 -0400 From: Tom Lane To: Luca Ferrari cc: pgsql-general Subject: Re: incoherent dead tuples between pg_stat_user_tables and pgstattuple? In-reply-to: References: Comments: In-reply-to Luca Ferrari message dated "Fri, 27 Sep 2019 12:37:08 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <20076.1569592342.1@sss.pgh.pa.us> Date: Fri, 27 Sep 2019 09:52:22 -0400 Message-ID: <20077.1569592342@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Luca Ferrari writes: > running 11.5 I've some misconception about pgstatuple: it seems it > lags behind normal statistics. n_live_tup/n_dead_tup should not be thought to be better than approximations. Most operations adjust them only incrementally, and messages to the stats collector can get dropped entirely under heavy load, causing deltas to go missing. There are also race conditions involved in some update scenarios. > Even after running an ANALYZE, pgstattuple provides the same results. > After a VACUUM FULL ANALYZE the world is as I would expect it to be: VACUUM FULL is one of very few operations that reset those counters to guaranteed-correct values (and I'm not sure the guarantee is ironclad even in that case). It's very hard to improve on this without giving up the desirable ability to have concurrent table updates. If you really want an accurate row count, COUNT(*) or pgstattuples will give you a more reliable estimate ... at much higher cost, of course. regards, tom lane