Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 945BA9FBDEF for ; Tue, 15 May 2007 20:39:06 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 87060-02 for ; Tue, 15 May 2007 20:38:58 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 015D39FBD8C for ; Tue, 15 May 2007 20:39:02 -0300 (ADT) Received: by noel.decibel.org (Postfix, from userid 1001) id 716C45645B; Tue, 15 May 2007 18:38:59 -0500 (CDT) Received: (hashcash-sendmail, from uid 1001); Tue, 15 May 2007 18:38:56 -0500 Date: Tue, 15 May 2007 18:38:56 -0500 From: "Jim C. Nasby" To: Tom Lane Cc: Y Sidhu , Bill Moran , pgsql-performance@postgresql.org Subject: Re: pg_stats how-to? Message-ID: <20070515233855.GC20707@nasby.net> References: <20070514174558.GS69517@decibel.org> <20070514183615.GW69517@nasby.net> <20070514190748.GY69517@nasby.net> <20070514170959.a951eefc.wmoran@collaborativefusion.com> <1623.1179188449@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1623.1179188449@sss.pgh.pa.us> X-Operating-System: FreeBSD 6.1-RELEASE-p10 amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.13 (2006-08-11) X-Hashcash: 1:20:070515:tgl@sss.pgh.pa.us::PGyE8rtP/uJn3m8N:00000000000000000000 0000000000000000000000000FmP X-Hashcash: 1:20:070515:ysidhu@gmail.com::dYBUL5wLudtiBhVp:00MzW X-Hashcash: 1:20:070515:wmoran@collaborativefusion.com::VTtcIPLUxOpFL4PL:0000000 0000000000000000000000000DHa X-Hashcash: 1:20:070515:pgsql-performance@postgresql.org::kx/Yx3ayiEighGGi:00000 0000000000000000000000006u5V X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/279 X-Sequence-Number: 24669 On Mon, May 14, 2007 at 08:20:49PM -0400, Tom Lane wrote: > "Y Sidhu" writes: > > it may be table fragmentation. What kind of tables? We have 2 of them which > > experience lots of adds and deletes only. No updates. So a typical day > > experiences record adds a few dozen times on the order of 2.5 million. And > > deletes once daily. Each of these tables has about 3 btree indexes. > > With an arrangement like that you should vacuum once daily, shortly > after the deletes --- there's really no point in doing it on any other > schedule. Note "shortly" not "immediately" --- you want to be sure that > any transactions old enough to see the deleted rows have ended. Also, think about ways you might avoid the deletes altogether. Could you do a truncate instead? Could you use partitioning? If you are using deletes then look at CLUSTERing the table some time after the deletes (but be aware that prior to 8.3 CLUSTER doesn't fully obey MVCC). To answer your original question, a way to take a look at how bloated your tables are would be to ANALYZE, divide reltuples by relpages from pg_class (gives how many rows per page you have) and compare that to 8k / average row size. The average row size for table rows would be the sum of avg_width from pg_stats for the table + 24 bytes overhead. For indexes, it would be the sum of avg_width for all fields in the index plus some overhead (8 bytes, I think). An even simpler alternative would be to install contrib/pgstattuple and use the pgstattuple function, though IIRC that does read the entire relation from disk. -- Jim Nasby decibel@decibel.org EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)