Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 98C6F133655C for ; Thu, 24 Feb 2011 10:25:28 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 60938-05 for ; Thu, 24 Feb 2011 14:25:22 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp2.peak6.com (smtp2.peak6.com [38.98.137.9]) by mail.postgresql.org (Postfix) with ESMTP id C93711336971 for ; Thu, 24 Feb 2011 10:25:20 -0400 (AST) X-AuditID: 0a02cb1e-b7bf8ae00000096d-4c-4d666a50b9f5 Message-ID: <4D666A4F.1060205@peak6.com> Date: Thu, 24 Feb 2011 08:25:19 -0600 From: Shaun Thomas Reply-To: sthomas@peak6.com Organization: Peak6 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.7) Gecko/20100720 Lightning/1.0b2 Thunderbird/3.1.1 MIME-Version: 1.0 To: Greg Smith CC: Benjamin Krajmalnik , "pgsql-performance@postgresql.org" Subject: Re: Unused indices References: <4D65795C.20404@2ndquadrant.com> In-Reply-To: <4D65795C.20404@2ndquadrant.com> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed content-transfer-encoding: 7bit X-Brightmail-Tracker: AAAAAQAAAZE= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201102/467 X-Sequence-Number: 42605 On 02/23/2011 03:17 PM, Greg Smith wrote: > Yes. The block usage you're seeing there reflects the activity from > maintaining the index. But since it isn't ever being used for > queries, with zero scans and zero rows it's delivered to clients, Nice to know. To that end, here's a query that will find every unused index in your database: SELECT i.schemaname, i.relname, i.indexrelname, c.relpages*8 indsize FROM pg_stat_user_indexes i JOIN pg_class c on (i.indexrelid=c.oid) JOIN pg_index ix ON (i.indexrelid=ix.indexrelid) WHERE i.idx_scan = 0 AND i.idx_tup_read = 0 AND i.schemaname NOT IN ('zzz', 'archive') AND NOT ix.indisprimary AND c.relpages > 0 ORDER BY indsize DESC; I noticed with our database that without the indisprimary clause, we had another 4GB of unused indexes. Clearly we need to look at those tables in general, but this will find all the "safe" indexes for removal. -- Shaun Thomas OptionsHouse | 141 W. Jackson Blvd. | Suite 800 | Chicago IL, 60604 312-676-8870 sthomas@peak6.com ______________________________________________ See http://www.peak6.com/email_disclaimer.php for terms and conditions related to this email