Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id B44761337B4A for ; Thu, 24 Feb 2011 14:13:27 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 17152-09 for ; Thu, 24 Feb 2011 18:13:20 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.17.9]) by mail.postgresql.org (Postfix) with ESMTP id C162A133798E for ; Thu, 24 Feb 2011 14:13:19 -0400 (AST) Received: from [192.168.1.6] (mail.highperformancepostgresql.com [71.179.240.8]) by mrelayeu.kundenserver.de (node=mreu0) with ESMTP (Nemesis) id 0Lxrpw-1Q4iLd2HRs-015LMu; Thu, 24 Feb 2011 19:13:14 +0100 Message-ID: <4D669FB8.8010001@2ndquadrant.com> Date: Thu, 24 Feb 2011 13:13:12 -0500 From: Greg Smith User-Agent: Thunderbird 2.0.0.24 (X11/20100317) MIME-Version: 1.0 To: sthomas@peak6.com CC: Benjamin Krajmalnik , "pgsql-performance@postgresql.org" Subject: Re: Unused indices References: <4D65795C.20404@2ndquadrant.com> <4D666A4F.1060205@peak6.com> In-Reply-To: <4D666A4F.1060205@peak6.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:Ju2CCW86B6z4qpCYLASCGbBcxjKgscXcW88zWUxSl/G unsijwM8y4JB044vWeWgW3jKJCMaYM8Aq0ID2I+qMJPw+gooka 1N8mgRZ3kVSeA9XTcWPvTwC2SIUm3M8iPaJtmARhxutV4af1q4 9gHRfsyXu4joCnASiX+2WjLVPj1mVDxl5BB4VERtbTsPCxfziq rTI72IxvplEXfWEXLqHa3hepadgOC/t8BiuAJQ0yoA= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201102/472 X-Sequence-Number: 42610 Shaun Thomas wrote: > I noticed with our database that without the indisprimary clause, we > had another 4GB of unused indexes. That's not quite the right filter. You want to screen out everything that isn't a unique index, not just the primary key ones. You probably can't drop any of those without impacting database integrity. Also, as a picky point, you really should use functions like pg_relation_size instead of doing math on relpages. Your example breaks on PostgreSQL builds that change the page size, and if you try to compute bytes that way it will overflow on large tables unless you start casting things to int8. Here's the simplest thing that does something useful here, showing all of the indexes on the system starting with the ones that are unused: SELECT schemaname, relname, indexrelname, idx_scan, pg_size_pretty(pg_relation_size(i.indexrelid)) AS index_size FROM pg_stat_user_indexes i JOIN pg_index USING (indexrelid) WHERE indisunique IS false ORDER BY idx_scan,relname; -- Greg Smith 2ndQuadrant US greg@2ndQuadrant.com Baltimore, MD PostgreSQL Training, Services, and 24x7 Support www.2ndQuadrant.us "PostgreSQL 9.0 High Performance": http://www.2ndQuadrant.com/books