Received: from maia.hub.org (maia-1.hub.org [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id C491663257E for ; Tue, 27 Apr 2010 21:55:23 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 43400-06 for ; Wed, 28 Apr 2010 00:55:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-iw0-f202.google.com (mail-iw0-f202.google.com [209.85.223.202]) by mail.postgresql.org (Postfix) with ESMTP id 3CC9A632527 for ; Tue, 27 Apr 2010 21:55:13 -0300 (ADT) Received: by iwn40 with SMTP id 40so4566656iwn.1 for ; Tue, 27 Apr 2010 17:55:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=PGn818dvhdMRqDq/eEq+D4HNZfljqtN/yo510dkuESI=; b=YFdGv5BVVQKgG/WnaSr0+wIdfe7/NaBcHw97rLEF7INDFOmkFzyHm94iEwlByKsLKg llB0ofyOBBV16V5uKPPUW+7oWZ4JLLdienVauW4TWoflHnUaYztZYREZuXozcsLpxkl1 KPLWo0wWp2z928ybgShmT0T3kZRVyT5Q0zpFw= 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=E0uNlKcNUi9H7L5fk/2kxrnGVRZjoNsT+2s2SbZb1Gra0BZ1SHZAB0+VStRASYZjP6 GmiDcS+Q5Qe3IKTq0SZmxxhxaGaGAVuW+PsUgKxqX0iW53rWp9Ahpw9fJoyRhDaypBDM j82sITV8RYOU7XYQb7kH9Qvq/6BhCycGGcMXc= MIME-Version: 1.0 Received: by 10.231.183.130 with SMTP id cg2mr2122406ibb.92.1272416111614; Tue, 27 Apr 2010 17:55:11 -0700 (PDT) Received: by 10.231.11.11 with HTTP; Tue, 27 Apr 2010 17:55:11 -0700 (PDT) In-Reply-To: <65d9d15d-41d2-4bfa-8cc3-6148b4fb9022@z3g2000yqz.googlegroups.com> References: <65d9d15d-41d2-4bfa-8cc3-6148b4fb9022@z3g2000yqz.googlegroups.com> Date: Tue, 27 Apr 2010 20:55:11 -0400 Message-ID: Subject: Re: autovacuum strategy / parameters From: Robert Haas To: Rick Cc: pgsql-performance@postgresql.org Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.8 tagged_above=-10 required=5 tests=BAYES_50=0.8 X-Spam-Level: X-Archive-Number: 201004/323 X-Sequence-Number: 38573 On Thu, Apr 22, 2010 at 4:42 PM, Rick wrote: > On Apr 22, 2:55=A0pm, robertmh...@gmail.com (Robert Haas) wrote: >> On Wed, Apr 21, 2010 at 11:06 AM, Rick wrote: >> > I have a DB with small and large tables that can go up to 15G. >> > For performance benefits, it appears that analyze has much less cost >> > than vacuum, but the same benefits? >> >> Err, no. =A0ANALYZE gathers statistics for the query planner; VACUUM >> clears out old, dead tuples so that space can be reused by the >> database system. >> >> > I can=92t find any clear recommendations for frequencies and am >> > considering these parameters: >> >> > Autovacuum_vacuum_threshold =3D 50000 >> > Autovacuum_analyze_threshold =3D 10000 >> > Autovacuum_vacuum_scale_factor =3D 0.01 >> > Autovacuum_analyze_scale_factor =3D 0.005 >> >> > This appears it will result in table analyzes occurring around 10,000 >> > to 85,000 dead tuples and vacuum occuring around 50,000 to 200,000, >> > depending on the table sizes. >> >> > Can anyone comment on whether this is the right strategy and targets >> > to use? >> >> I'm not that familiar with tuning these parameters but increasing the >> default thesholds by a thousand-fold doesn't seem like a good idea. >> Small tables will never get vacuumed or analyzed at all. >> >> ...Robert >> >> -- >> Sent via pgsql-performance mailing list (pgsql-performa...@postgresql.or= g) >> To make changes to your subscription:http://www.postgresql.org/mailpref/= pgsql-performance > > The problem is with the autovacuum formula: > > In a loop, autovacuum checks to see if number of dead tuples > > ((number of live tuples * autovacuum_vacuum_scale_factor) + > autovacuum_vacuum_threshold), and if > so, it runs VACUUM. If not, it sleeps. It works the same way for > ANALYZE. > > So, in a large table, the scale_factor is the dominant term. In a > small > table, the threshold is the dominant term. But both are taken into > account. > > The default values are set for small tables; it is not being run for > large tables. > The question boils down to exactly what is the max number of dead > tuples that should be allowed to accumulate before running analyze? > Since vacuum just recovers space, that doesn't seem to be nearly as > critical for performance? That doesn't really match my experience. Without regular vacuuming, tables and indices end up being larger than they ought to be and contain large amounts of dead space that slows things down. How much of an impact that ends up having depends on how badly bloated they are and what you're trying to do, but it can get very ugly. My guess is that the reason we run ANALYZE more frequently than vacuum (with the default settings) is that ANALYZE is pretty cheap. In many cases, if the statistical distribution of the data hasn't changed much, then it's not really necessary, but it doesn't cost much either. And for certain types of usage patterns, like time series (where the maximum value keeps increasing) it's REALLY important to analyze frequently. But having said that, on the systems I've worked with, I've only rarely seen a problem caused by not analyzing frequently enough. On the other hand, I've seen MANY problems caused by not vacuuming enough. Someone runs a couple of big queries that rewrite a large portion of a table several times over and, boom, problems. 8.3 and higher are better about this because of an optimization called HOT, but there can still be problems. Other people's experiences may not match mine, but the bottom line is that you need to do both of these things, and you need to make sure they happen regularly. In most cases, the CPU and I/O time they consume will be amply repaid in improved query performance. ...Robert