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 1hE4ZM-00018S-OO for pgsql-general@arkaria.postgresql.org; Wed, 10 Apr 2019 04:10:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hE4ZL-0004iF-Gt for pgsql-general@arkaria.postgresql.org; Wed, 10 Apr 2019 04:10:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hE4ZL-0004i2-3z for pgsql-general@lists.postgresql.org; Wed, 10 Apr 2019 04:10:39 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hE4ZI-0006k1-Ny for pgsql-general@lists.postgresql.org; Wed, 10 Apr 2019 04:10:37 +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 x3A4AXrD001936; Wed, 10 Apr 2019 00:10:33 -0400 From: Tom Lane To: Sherrylyn Branchaw cc: pgsql-general@lists.postgresql.org Subject: Re: Does pg_stat_get_live_tuples() matter? In-reply-to: References: Comments: In-reply-to Sherrylyn Branchaw message dated "Tue, 09 Apr 2019 12:45:52 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1934.1554869432.1@sss.pgh.pa.us> Date: Wed, 10 Apr 2019 00:10:32 -0400 Message-ID: <1935.1554869432@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Sherrylyn Branchaw writes: > If a table has 1.8M rows in reality, yet pg_stat_get_live_tuples() returns > 1.8K, does it matter to the performance of the database, as long as > pg_class.reltuples is the right order of magnitude? Hmmm ... what was in reltuples again? Looking at the current code, it looks like vacuum or autovacuum should set reltuples and n_live_tuples to the same thing. n_live_tuples gets adjusted incrementally by subsequent transactions, and it wouldn't be too surprising if it drifted away from reality, but it's a bit hard to believe that it could get to be off by 1000X. Have you suppressed autovacuum on this table? We have fooled around with the logic that maintains these numbers, so maybe it was different in 9.6.9. Anyway, to answer your question, I don't see anything in the current core code that pays attention to n_live_tuples. reltuples definitely does matter to the planner, and some of the sibling counters like n_dead_tuples drive autovacuum, but nothing is examining n_live_tuples AFAICS. regards, tom lane