X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D706352896 for ; Fri, 17 Jun 2005 00:47:43 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 86145-04 for ; Fri, 17 Jun 2005 03:47:35 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id E1D9C5281E for ; Fri, 17 Jun 2005 00:47:34 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j5H3lY7e015402; Thu, 16 Jun 2005 23:47:34 -0400 (EDT) To: ken shaw Cc: pgsql-performance@postgresql.org Subject: Re: How to determine whether to VACUUM or CLUSTER In-reply-to: <20050616180442.8983.qmail@web33703.mail.mud.yahoo.com> References: <20050616180442.8983.qmail@web33703.mail.mud.yahoo.com> Comments: In-reply-to ken shaw message dated "Thu, 16 Jun 2005 11:04:41 -0700" Date: Thu, 16 Jun 2005 23:47:33 -0400 Message-ID: <15401.1118980053@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.005 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/345 X-Sequence-Number: 12982 ken shaw writes: > It looks to me as if the only way to determine whether to issue a > VACUUM (on a non-clustered table) or a CLUSTER (on a clustered table) > is to query the table "pg_index", much like view "pg_indexes" does, > for the column "indisclustered". Is this right? indisclustered is certainly the ground truth here, and [ ... digs around in the source code ... ] it doesn't look like there are any views that present the information in a different fashion. So yup, that's what you gotta do. > Also, how expensive is CLUSTER compared to VACUUM? Well, it's definitely expensive compared to plain VACUUM, but compared to VACUUM FULL the case is not clear-cut. I would say that if you had a seriously bloated table (where VACUUM FULL would have to move all or most of the live tuples in order to compact the table completely) then CLUSTER will be faster --- not to mention any possible future benefits from having the table more or less in order with respect to the index. As near as I can tell, VACUUM FULL was designed to work nicely when you had maybe 10%-25% free space in the table and you want it all compacted out. In a scenario where it has to move all the tuples it is certainly not faster than CLUSTER; plus the end result is much worse as far as the state of the indexes goes, because VACUUM FULL does *nothing* for compacting indexes. regards, tom lane