페이지 트리

이 문서는 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 생성 및 스키마 생성


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;


connection method 변경

[root@playground data]# vi /var/lib/pgsql/9.3/data/pg_hba.conf


// METHOD를 md5로 변경


# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 ident


사용자 접속 확인

[root@playground opt]# psql -U sonaruser -d sonar
Password for user sonaruser:

sonar=>


PostgreSQL 서비스 재시작

systemctl restart sonarqube


sonar.properties 복사 및 변경

현재 사용중인 properties 이름 변경 및 복사 

mv <install dir>/conf/sonar.properties sonar-MySQL.properties
cp sonar-MySQL.properties soanr.properties


복사한 properties를 PostgreSQL 구성에 맞게 변경

vi sonar.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


SonarQube 서비스 시작 ( Migration 전 PostgreSQL에 SonarQube 테이블 생성 필요 )

systemctl start 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


  • 해당 상황은 Data 폴더 내 정보 삭제를 하지 않았을 경우 발생되며, 아래 내용으로 조치
  1. SonarQube 서비스 종료
  2. Data 정보 삭제

    cd <install dir>/data
    rm -rf es5 // SonarQube 버전별로 폴더명 다를수 있음 es5, es6 ...
  3. SonarQube 서비스 시작
  • 레이블 없음