CS/DBMS

PostgreSQL 인덱스 invisible 변경하기 (invisible index)

뭉치v 2024. 8. 2.
반응형

postgresql invisible index

invisible index??

오라클 DB를 관리하셨다면 인덱스를 삭제하거나 튜닝 등을 할때 invisible index 기능에 익숙하실 겁니다.

 

일반적으로 invisible index를 인덱스를 삭제할때 혹시라도 업무 쿼리의 실행계획에 영향을 끼칠 까봐 삭제하기전에 실행계획에서 제외 시키려고 사용을 하죠.

 

postgresql에서도 오라클의 invislble index 처럼 비슷하게 인덱스를 실행계획에서 제외 시킬 수 있는 방법이 있어 정리해보겠습니다.

 

invisible index로 변경하기

-- 인덱스 조회
select * from pg_index
where indexrelid::regclass = (select oid from pg_class where relname ='index name');

-- invalid 처리
update pg_index set indisvalid = false
where indexrelid::regclass = (select oid from pg_class where relname ='index name');

-- valid 처리
update pg_index set indisvalid = true
where indexrelid::regclass = (select oid from pg_class where relname ='index name');

 

위처럼 `pg_index.indisvalid` 값을 false로 업데이트 치면 이후 해당 인덱스는 쿼리 실행 계획에서 제외됩니다.

 

업무에서 안쓴다고해도 삭제 하기 전에 꼭 invisible 처리 후 눈치보고 삭제하세요~ (아무도 믿으면 안됨.)

 

반응형

댓글

💲 추천 글