Indexes are used by your database, specifically, when commands are being executed. A program may connect to your database and use some indexes, but if there are multiple programs connecting to your database, then it is difficult to find out which program is using which index. Yet, this query is detecting the unused indexes, that is, the indexes that are not used by any program:
SELECT INDSCHEMA, INDNAME, TABNAME
FROM SYSCAT.INDEXES
WHERE LASTUSED = '01/01/0001';
You can adjust LASTUSED
to a more recent date, to find indexes that were not used since a given moment that you define.
If you need to find out what indexes are used by a program, then you could do the following:
- export your database
- import your database's copy as a different database
- test your program while being connected to the other database for a (long) while
- do not connect any other program to the database
- do not perform any actions on the database apart from the program's actions
- find the indexes that have been unused since you have imported the copy of your database + 5 minutes (to exclude any index-poking by your import)