-
Ubuntu에서 PostgreSQL 설치 및 데이터 저장 위치 변경하기DB 2021. 10. 26. 22:27
먼저 아래 명령어를 통해 PostgreSQL을 설치한다.
sudo apt update sudo apt upgrade -y sudo apt install postgresql-12
위 명령어는 아래 공식 문서에서 확인하였다.
https://www.postgresql.org/download/linux/ubuntu/
PostgreSQL: Linux downloads (Ubuntu)
Linux downloads (Ubuntu) PostgreSQL is available in all Ubuntu versions by default. However, Ubuntu "snapshots" a specific version of PostgreSQL that is then supported throughout the lifetime of that Ubuntu version. Other versions of PostgreSQL are availab
www.postgresql.org
설치가 완료되면 디폴트 데이터 저장 디렉토리 경로를 확인해본다.
psql에서 아래 명령어를 통해 확인할 수 있다.
# psql 접속 sudo -u postgres psql postgres # psql postgres=# show data_directory; >>> /var/lib/postgresql/버전/main
데이터를 저장할 디렉토리를 생성하고, postgres 사용자 계정에 소유자 권한을 부여한다.
mkdir /postgres-data sudo chown postgres:postgres /postgres-data
"/postgres-data"라는 디렉토리를 생성했다고 가정한다.
이제 데이터 저장 경로를 변경하기 위해 PostgreSQL 서비스를 종료한다.
sudo service postgresql stop
기존 데이터 디렉토리를 새 디렉토리로 이동한다.
sudo mv /var/lib/postgresql/버전/main /postgres-data
postgresql.conf 파일에서 data_direcotry를 새 경로로 수정한다.
postgresql.conf 파일은 일반적으로 "/etc/postgresql/버전/main/postgresql.conf" 경로에 위치한다.
sudo vim /etc/postgresql/버전/main/postgresql.conf data_directory = '/postgres-data/main'
PostgreSQL 서비스를 재시작하면 작업이 완료된다.
sudo service postgresql start
출처
https://cloud.google.com/community/tutorials/setting-up-postgres-data-disk
Setting up a new persistent disk for PostgreSQL data
[{ "type": "thumb-down", "id": "hardToUnderstand", "label":"Hard to understand" },{ "type": "thumb-down", "id": "incorrectInformationOrSampleCode", "label":"Incorrect information or sample code" },{ "type": "thumb-down", "id": "missingTheInformationSamples
cloud.google.com
'DB' 카테고리의 다른 글
PostgreSQL 외부 접속 허용 및 IP주소 제한 (0) 2021.11.07 다중 태그 검색 SQL문 (0) 2021.10.31 데이터베이스별 boolean 데이터 타입(PostgreSQL, MySQL, Oracle) (0) 2021.10.15 PostgreSQL timestamp vs timestamptz (0) 2021.10.14 [SQL] UPDATE 시 LIKE 조건에 컬럼 이름 사용하기 (0) 2021.07.12