Skip to content

Commit 4b68987

Browse files
authored
Create duplicate_indexes.sql
1 parent 95f78a2 commit 4b68987

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

indexes/duplicate_indexes.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
\o /tmp/duplicate-indexes.txt
3+
4+
-- check for exact matches
5+
SELECT indrelid::regclass
6+
, array_agg(indexrelid::regclass)
7+
FROM pg_index
8+
GROUP BY indrelid
9+
, indkey
10+
HAVING COUNT(*) > 1;
11+
12+
-- check for matches on only the first column of the index
13+
-- requires some human eyeballing to verify
14+
SELECT indrelid::regclass
15+
, array_agg(indexrelid::regclass)
16+
FROM pg_index
17+
GROUP BY indrelid
18+
, indkey[0]
19+
HAVING COUNT(*) > 1;
20+
21+
\o

0 commit comments

Comments
 (0)