Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 5D2A1B5DC5B for ; Wed, 25 May 2011 13:41:52 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 19756-04-2 for ; Wed, 25 May 2011 16:41:44 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id E2394B5DC46 for ; Wed, 25 May 2011 13:41:42 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p4PGfdZa022498; Wed, 25 May 2011 12:41:39 -0400 (EDT) To: Robert Haas cc: Florian Helmberger , pgsql-hackers@postgresql.org, Alvaro Herrera Subject: Re: [ADMIN] pg_class reltuples/relpages not updated by autovacuum/vacuum In-reply-to: References: <4DD28F73.6010108@25th-floor.com> <25017.1306291669@sss.pgh.pa.us> <4DDCA801.70805@25th-floor.com> <19738.1306338472@sss.pgh.pa.us> Comments: In-reply-to Robert Haas message dated "Wed, 25 May 2011 12:17:11 -0400" Date: Wed, 25 May 2011 12:41:39 -0400 Message-ID: <22497.1306341699@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.01 tagged_above=-5 required=5 tests=T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201105/1276 X-Sequence-Number: 188310 Robert Haas writes: > On Wed, May 25, 2011 at 11:47 AM, Tom Lane wrote: >> 2. Revise the vacuum code so that it doesn't skip updating the pg_class >> entries.  We could have it count the number of pages it skipped, rather >> than just keeping a bool, and then scale up the rel_tuples count to be >> approximately right by assuming the skipped pages have tuple density >> similar to the scanned ones. > This approach doesn't seem like a good idea to me. The skipped > portions of the table are the ones that haven't been modified in a > while, so this is or embeds an assumption that the tuples in the hot > and cold portions of the table are the same size. That might be true, > but it isn't hard to think of cases where it might not be. There > could also very easily be sampling error, because it's easy to imagine > a situation where 99% of the table is getting skipped. Yeah, I had been thinking about the latter point. We could be conservative and just keep the reported tuple density the same (ie, update relpages to the new correct value, while setting reltuples so that the density ratio doesn't change). But that has its own problems when the table contents *do* change. What I'm currently imagining is to do a smoothed moving average, where we factor in the new density estimate with a weight dependent on the percentage of the table we did scan. That is, the calculation goes something like old_density = old_reltuples / old_relpages new_density = counted_tuples / scanned_pages reliability = scanned_pages / new_relpages updated_density = old_density + (new_density - old_density) * reliability new_reltuples = updated_density * new_relpages We could slow the moving-average convergence even further when reliability is small; for instance if you were really paranoid you might want to use the square of reliability in line 4. That might be overdoing it, though. regards, tom lane