Post

Postgresql 마운트 경로 변경

postgresql 데이터베이스의 마운트 경로를 변경하는 방법을 기록.

Postgresql 마운트 경로 변경
  • postgresql 데이터가 저장되는 경로는 postgresql 서비스가 설치된 경로에 따라 달라진다.
  • centos 기준으로 postgresql 서비스가 설치된 경로는 /var/lib/psql/{version}/data 이다.

마운트 경로 변경 순서

  1. postgresql 서비스 중지
    1
    
    sudo systemctl stop postgresql
    
  2. 기존 데이터 디렉토리 이동
    1
    
    sudo mv /var/lib/psql/{version}/data {new-mount-path}
    
  3. 마운트 경로 변경 서비스 파일을 수정하여 postgresql 데이터 디렉토리의 마운트 경로를 변경한다.
1
2
// file: /usr/lib/systemd/system/postgresql-{version}.service
Environment=PGDATA={new-mount-path} # Environment=PGDATA=/var/lib/psql/{version}/data  // 기존 경로 주석 처리
  1. postgresql 서비스 시작
    1
    
    sudo systemctl start postgresql
    
  2. postgresql 서비스 상태 확인
    1
    
    sudo systemctl status postgresql
    

6. 데이터 디렉토리 경로 확인

1
2
// su - postgres
psql -U postgres -c "SHOW data_directory;"
This post is licensed under CC BY 4.0 by the author.