21.7 pg_stat_user_indexes: Finding Unused Indexes
Right, let’s talk about cleaning up your own mess. You’ve been creating indexes like a kid with a free pass to an all-you-can-eat buffet. Some of them were brilliant ideas that save milliseconds on every query. Others… well, you were probably just guessing and hoping for the best. Every single one of those indexes, even the unused ones, is a tax you pay on every INSERT, UPDATE, and DELETE. They take up space, they slow down writes, and they make the vacuum worker hate you. It’s time to find the dead weight and cut it loose. Our best friend for this job is the pg_stat_user_indexes view.