Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 94273B5DBF9 for ; Wed, 25 May 2011 13:54:37 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 46871-07 for ; Wed, 25 May 2011 16:54:30 +0000 (UTC) X-Greylist: delayed 00:28:24.079302 by SQLgrey-1.7.6 Received: from mail-yw0-f46.google.com (mail-yw0-f46.google.com [209.85.213.46]) by mail.postgresql.org (Postfix) with ESMTP id E618AB5DBF8 for ; Wed, 25 May 2011 13:54:29 -0300 (ADT) Received: by ywe9 with SMTP id 9so2938732ywe.19 for ; Wed, 25 May 2011 09:54:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=Hxa6akxGwNVq+MwUggE9ECu1/MCWb42X7QkMJb4ucOo=; b=lffrC43PWCRzAlGtbSAzOKmnfc+vl2GdfE+nMYygf09CcEP+qY+NX77qfGHYONxCCX EkKn08mBq9qn7TCnkycb0IWVprvmZLC4Gn61P/xhsaY4erfqoCdLxuZTE9GbRIsdQVAx rmpaDuHp+V0yI1HvD2+n7QQS4jm+eOKd/0G+Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=ad4qjYJ6bI6EqObfkU5eyOSaAqMtNzOg9Y7vgBhalvR27XjHAsklEr9+crgoDvD4lq LFjLB4D25JTJsqvAFc/lALKrcf5JvHUMWnZfkmZ4XY27OSgnHGCb0s0vwGyZC8M2IyWU Vx0CoIy1PJFYU0acHU5H7YZv+Wx2ruiExETYg= MIME-Version: 1.0 Received: by 10.236.105.210 with SMTP id k58mr7145121yhg.273.1306342469538; Wed, 25 May 2011 09:54:29 -0700 (PDT) Received: by 10.236.105.180 with HTTP; Wed, 25 May 2011 09:54:28 -0700 (PDT) In-Reply-To: <22497.1306341699@sss.pgh.pa.us> References: <4DD28F73.6010108@25th-floor.com> <25017.1306291669@sss.pgh.pa.us> <4DDCA801.70805@25th-floor.com> <19738.1306338472@sss.pgh.pa.us> <22497.1306341699@sss.pgh.pa.us> Date: Wed, 25 May 2011 12:54:28 -0400 Message-ID: Subject: Re: [ADMIN] pg_class reltuples/relpages not updated by autovacuum/vacuum From: Robert Haas To: Tom Lane Cc: Florian Helmberger , pgsql-hackers@postgresql.org, Alvaro Herrera Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.898 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001 X-Spam-Level: X-Archive-Number: 201105/1281 X-Sequence-Number: 188315 On Wed, May 25, 2011 at 12:41 PM, Tom Lane wrote: > Yeah, I had been thinking about the latter point. =A0We 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). =A0But that has its own problems > when the table contents *do* change. =A0What 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. =A0That is, the calculation goes something like > > old_density =3D old_reltuples / old_relpages > new_density =3D counted_tuples / scanned_pages > reliability =3D scanned_pages / new_relpages > updated_density =3D old_density + (new_density - old_density) * reliabili= ty > new_reltuples =3D 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. =A0That might be > overdoing it, though. I don't know. That's maybe better, but I'd be willing to wager that in some cases it will just slow down the rate at which we converge to a completely incorrect value, while in other cases it'll fail to update the data when it really has changed. I am wondering, though, why we're not just inserting a special-purpose hack for TOAST tables. Your email seems to indicate that regular tables are already handled well enough, and certainly if we only whack around the TOAST behavior it's much less likely to fry anything. --=20 Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company