서버/DB
postgresql dump & restore
아카이sun
2023. 2. 16. 11:08
- 자주 사용하는 postgresql dump 및 restore 명령어
-d DB명
-h : DB주소
-p : port번호
-U : 유저명
-F : 백업 포맷 지정 (p: plain-text, c: custom-format, d: directory, t: tar)
-f : 백업 파일명
-t : 특정 테이블명
-j : Backup시 병렬처리 여부 및 그 정도
-v : 진행 과정 표시
- 이외의 다른 명령어들은 공식 홈페이지를 참조
https://www.postgresql.org/docs/current/app-pgdump.html
pg_dump 예시
pg_dump -h localhost -p 5432 -d testdb -U postgres -v -F t > /backup/test_backup.tar
위의 명령어는 다음의 의미를 가지고 있다.
localhost의 5432포트에 postgres유저로 접속하여 testdb를 '/backup/test_backup.tar'파일에 상세과정을 표시하며 백업한다.
pg_restore 예시
pg_restore -h localhost -p 5432 -d targetdb -U postgres -v "C:/backup/test_backup.tar"
위의 명령어는 다음의 의미를 가지고 있다.
localhost의 5432포트에 postgres유저로 접속하여 targetdb에 '/backup/test_backup.tar' 파일을 상세과정을 표시하며 복원한다.