Corrupt indexes in PG12, how do I fix?

If a concurrent REINDEX fails because the table has invalid data, you need to:

  1. Fix the invalid data, like it was done here.

  2. List the invalid indexes using SELECT pg_class.relname FROM pg_class, pg_index WHERE pg_index.indisvalid = false AND pg_index.indexrelid = pg_class.oid;

  3. Drop each invalid index listed above using DROP INDEX <indexname>;

  4. Try the REINDEX again.

7 Likes