-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reindex corrupted discovery indexes (#6865)
- Loading branch information
1 parent
95f6286
commit 8785ac9
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
packages/discovery-provider/ddl/migrations/0041_repair_indexes.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
CREATE EXTENSION IF NOT EXISTS amcheck; | ||
|
||
DO $$ | ||
DECLARE | ||
rec RECORD; | ||
BEGIN | ||
FOR rec IN SELECT indexrelid::regclass AS index_name FROM pg_index WHERE indisvalid LOOP | ||
RAISE NOTICE 'Checking index: %', rec.index_name; | ||
BEGIN | ||
-- Attempt to check the index | ||
PERFORM bt_index_check(rec.index_name); | ||
EXCEPTION WHEN OTHERS THEN | ||
-- If an error occurs (indicating a potentially invalid index), reindex it | ||
RAISE NOTICE 'Reindexing due to error in index: %', rec.index_name; | ||
EXECUTE 'REINDEX INDEX ' || rec.index_name; | ||
-- Log that reindexing is complete | ||
RAISE NOTICE 'Reindexing completed for index: %', rec.index_name; | ||
END; | ||
END LOOP; | ||
END; | ||
$$ LANGUAGE plpgsql; |