# 손상된 인덱스로 인해 복원 불가 (손상된 인덱스 해결 방법 힌트 포함)

**URL:** https://meta.discourse.org/t/cant-restore-due-to-corrupt-indexes-with-some-clues-on-how-to-deal-with-corrupt-indexes/137400
**Category:** Self-hosting
**Created:** [12월 30, 2019, 11:22오후 UTC](https://meta.discourse.org/t/cant-restore-due-to-corrupt-indexes-with-some-clues-on-how-to-deal-with-corrupt-indexes/137400 "2019-12-30T23:22:13Z")
**Posts on this page:** 1
**Showing post:** 14

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [1월 6, 2020, 7:07오후 UTC](https://meta.discourse.org/t/cant-restore-due-to-corrupt-indexes-with-some-clues-on-how-to-deal-with-corrupt-indexes/137400/14 "2020-01-06T19:07:35Z")

</div>

이번에도 'shiny-server’는 하나만 일치했지만 '%hiney-server’는 둘 다 일치하는 두 개의 항목이 있었습니다. 이게 제가 이해하는 데 어떻게 도움이 되는지 모르겠지만, 제가 사용하는 `select`가 하나의 결과만 반환되기를 기대하고 인덱스에서 그것을 가져오며 나머지는 무시한다는 말씀인 것 같습니다. 하지만 `%`를 사용하면 필드를 검색하게 되죠.

```plaintext
discourse=> EXPLAIN ANALYZE select * from tags where name='shiny-server'; 
                                                        QUERY PLAN                                                        
--------------------------------------------------------------------------------------------------------------------------
 Index Scan using index_tags_on_name on tags (cost=0.28..8.29 rows=1 width=36) (actual time=0.038..0.040 rows=1 loops=1)
   Index Cond: ((name)::text = 'shiny-server'::text)
 Planning time: 0.129 ms
 Execution time: 0.070 ms
(4 rows)

```

이걸 스스로 알아내지 못하는 사람들이 이걸 유용하게 볼 거라고는 솔직히 의문이 듭니다. 하지만 … 이름이 같은 두 개의 `tag_id`를 찾아서 다음과 같은 작업을 수행해 보았습니다.

```
 TopicTag.where(tag_id: 717).update_all(tag_id: 611)
 Tag.ensure_consistency!
 Tag.find(717) # 어떤 주제에도 포함되지 않는지 확인
 Tag.find(717).destroy

```

그리고 psql에서 `reindex table tags;`를 실행했습니다.

이제 @bartv님이 설명하신 것처럼 `users`에 대해서도 유사한 작업을 해야 할 것 같습니다. 다만 제 경우를 보면 David라는 유저와 david라는 유저, 그리고 `[Mm]ark`도 있습니다.

그것들은 다음과 같이 수정했습니다.

```plaintext
marks=User.where("username similar to '[Mm]+ark'").pluck(:id,:username,:created_at)

```

그 다음 `/admin/users`에서 새로운 mark를 찾아서 거기서 유저 이름을 변경했습니다. 그리고 psql에서 `reindex table users;`를 시도해 보았습니다. (`sudo su - discourse`를 실행한 후 `psql`을 실행합니다).

---

_[View the full topic](https://meta.discourse.org/t/cant-restore-due-to-corrupt-indexes-with-some-clues-on-how-to-deal-with-corrupt-indexes/137400)._
