시스템
Postgresql database 백업
JihwanGo
2020. 9. 18. 15:22
반응형
Postgresql database 백업
-
pg_dump --dbname=myDB --host=127.0.0.1 --port=5432 --username=myID --password --format=p --file=./myDB.sql
-
option
- dbname: 대상 데이터베이스 이름
- host: 대상 DB 서버의 ip address 혹은 FQDN(Fully Qulified Domain Name)
- ex) www.naver.com
- port: 대상 DB 서버의 포트 번호
- username: 대상 DB에 접속할 DB user id
- password: 이 옵션이 있어야 명령어 실행 후 username에 대한 password를 입력을 할 수 있음
- format: p or c or d or t
- p: plain - SQL 스크립트 파일 형태로 저장
- c: custom - 바이너리 파일 형태로 저장
- d: directory - 1개 테이블 당 1개 BLOB(Binary Large OBject) 형식 파일들과 그 파일들을 pg_restore 시 잘 읽어들일수 있도록하는 table of contents 파일을 지정한 디렉토리에 저장
- t: tar - tar 압축 파일 형태로 저장
- file: 백업 결과를 저장할 파일 혹은 디렉토리(format을 d로 지정했을 때) 경로 지정
postgresql database 복원
- 목적지 서버의 DB에 myDB 생성한 후에
- psql "postgresql://myID:myPassword@127.0.0.1:5432/myDB" -f [백업파일 디렉토리 경로]/myDB.sql
참고(9.6버전 기준.. 아래 페이지 들어가면 참고할 버전은 변경 가능)
PostgreSQL: Documentation: 9.6: pg_dump
반응형