pt-online-schema-change 설치 및 사용 (DB 온라인 DDL 사용 툴)

2020. 7. 29. 17:53util

 

 

1. pt-online-schema-change 설치

  • MAC
  • brew install percona-toolkit
  • Linux
    • ubuntu / Debian
    • apt-get install percona-toolkit
    • Arch Linux
    • pacman -S percona-toolkit perl-dbd-mysql

 

 

2. 작성법

pt-online-schema-change \

--alter "drop index index_5 or add index index_5(brand_id, display_status)" \

D=데이터베이스,t=테이블명,h=호스트IP,u=유저명,p=패스워드,P=포트명 \

--execute \ # alter 를 사용시 필요한 옵션

--chunk-size=500 \ # default가 1000 데이터를 몇개씩 옮길지 양

--no-drop-old-table \ # 성공 후 이전의 테이블을 지우지 않는다 no를 빼면 지움

--no-drop-new-table \ # 실패 후 새로 만들던 테이블을 지우지 않는다. no를 빼면 지움

--sleep=0.003 \ # 로우를 chunk-size만큼 옮기고 0.003초씩 쉰다.

--chunk-index=PRIMARY \ # chunk를 쪼갤 기준의 컬럼을 정한다.

--alter-foreign-keys-method=auto #

===========================================================

pt-online-schema-change --alter "drop index INDEX_5" D=testdb,t=test_table --host=192.168.0.100 --user=root --password=asd123 --port=3306 --execute --chunk-size=500 --no-drop-old-table --no-drop-new-table --sleep=0.003 --chunk-index=PRIMARY --alter-foreign-keys-method=auto

 

 

 

3. 참고 블로그

https://blog.rgbplace.com/393

https://jojoldu.tistory.com/358

https://gywn.net/2017/08/small-talk-pt-osc/

mac에서 설치

https://gist.github.com/takatoshiono/ea84371dfa2ae4529c5f5ba6427b711d

option 정리

https://notemusic.tistory.com/44