Re: Unused indices

From: Greg Smith <greg(at)2ndquadrant(dot)com>
To: sthomas(at)peak6(dot)com
Cc: Benjamin Krajmalnik <kraj(at)servoyant(dot)com>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Unused indices
Date: 2011-02-24 18:13:12
Message-ID: 4D669FB8.8010001@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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(at)2ndQuadrant(dot)com Baltimore, MD
PostgreSQL Training, Services, and 24x7 Support www.2ndQuadrant.us
"PostgreSQL 9.0 High Performance": http://www.2ndQuadrant.com/books

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Vik Reykja 2011-02-24 19:33:00 Re: Pushing IN (subquery) down through UNION ALL?
Previous Message Dave Johansen 2011-02-24 16:38:56 Re: Pushing IN (subquery) down through UNION ALL?