이 문서는 SonarQube에서 현재 사용중인 MySQL DB를 PostgreSQL Migration 방법에 대해 공유하기 위해 작성되었다.
관련 URL : https://github.com/SonarSource/mysql-migrator
해당 가이드는 동일한 버전의 SonarQube DB를 MySQL에서 PostgreSQL로 변경하는 방법이다.
Migration 전 준비사항
사용중인 MySQL을 PostgreSQL로 변경하기 위해선 아래 두가지 준비가 필요하다.
1. Migrator
2. PostgreSQL Database 생성
3. 현재 사용중인 SonarQube 서비스 종료
Migrator download
상단 URL에서 1번 Step의 Download 링크 클릭하여 Migrator 다운로드
Database 생성 및 스키마 생성
- PostgreSQL 설치 방법은 해당 페이지 참조 : PostgreSQL 설치
Migration 할 Database를 생성한다
CREATE DATABASE sonar;
계정 생성 및 Database Owner 변경
\c sonar; // 데이터베이스 연결 CREATE ROLE sonaruser; // 계정 생성 ALTER USER sonaruser with PASSWORD 'sonarpass' // 사용자 비밀번호 설정 ALTER DATABASE sonar OWNER TO sonaruser; // 데이터베이스 소유권 변경
스키마 생성 및 search_path 속성 부여
CREATE SCHEMA sonarschema; // 스키마 생성 ALTER USER sonaruser SET search_path to sonarschema;
sonar.properties 복사 및 변경
현재 사용중인 properties 복사
cp <install dir>/conf/sonar.properties sonar-post.properties
복사한 properties를 PostgreSQL 구성에 맞게 변경
vi sonar-post.properties // 아래 MySQL 내용을 주석처리 #sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false // 아래 PostgreSQL 내용을 주석 해제 sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonar
현재 사용중인 Data 정보 삭제
cd <install dir>/data rm -rf es5 // SonarQube 버전별로 폴더명 다를수 있음 es5, es6 ...
SonarQube 서비스 종료
systemctl stop sonarqube
DB Migration
Migrator 압축 해제
unzip mysql-migrator-1.1.0.119 -d .
Migrator 실행
cd mysql-migrator-1.1.0.119/bin/ ./mysql-migrator -source /opt/sonarqube/conf/sonar.properties -target /opt/sonarqube/conf/sonar-post.properties // source는 현재 사용중인 정보(MySQL) target은 사용 할 정보(PostgreSQL)
서비스 실행
systmctl start sonarqube