본문 바로가기
데이터베이스/Postgresql

[PostgreSql] 설치후 초기 데이터 구축

by cbwstar 2021. 12. 14.
728x90
반응형

1. 사용자 계정 생성

create user test password 'test2021' superuser;

 

2. 데이터 베이스 생성

create database naqs owner test;

 

3. 테이블 스페이스 저정될 폴더를 먼저 생성한다.

mkdir -p /postgre_db/com_dat

mkdir -p /postgre_db/com_idx

소유권을 변경한다.

chown -R postgrs:postgres /postgre_db

 

4. 테이블 스페이스 생성

CREATE TABLESPACE naqscom_tbl owner test LOCATION '/postgre_db/com_dat';

CREATE TABLESPACE naqscom_idx owner test LOCATION '/postgre_db/com_idx';

 

5. 테이블 스페이스 확인

\db

 

6. 스키마 생성

CREATE SCHEMA IF NOT EXISTS test AUTHORIZATION test;

 

7. 스키마 삭제

DROP SCHEMA test cascade;

 

8. 스키마 생성 확인

\dn

 

9. db 전체 백업

pg_dump --file "full.dump" --host "localhost" --port "5432" --username "test" --no-password --verbose --format=c --section=pre-data --section=data --section=post-data --column-inserts --encoding "UTF8" "naqs"

 

10. db스키마별 백업

pg_dump --file "com.dump" --host "localhost" --port "5432" --username "test" --no-password --verbose --format=c --section=pre-data --section=data --section=post-data --column-inserts --encoding "UTF8" --schema "test" "naqs"

 

11. db전체복원

pg_restore --host "localhost" --port "5432" --username "test" --no-password --dbname "naqs" --section=pre-data --section=data --section=post-data --verbose "full.dump"

 

12. db스키마별 복원

pg_restore --host "localhost" --port "5432" --username "test" --no-password --dbname "naqs" --section=pre-data --section=data --section=post-data --verbose --schema "test" "full.dump"

 

13. 테이블 백업

pg_dump.exe --file "test_member.dump" --host "localhost" --port "5432" --username "postgres" --no-password --verbose --format=c --blobs --section=pre-data --section=data --section=post-data --column-inserts --encoding "UTF8" --table "public.test_member" "naqs"

 

14. 테이블 복원 

pg_restore.exe --host "localhost" --port "5432" --username "postgres" --no-password --dbname "naqs" --section=pre-data --section=data --section=post-data --data-only --verbose --schema "test" --table "test_member" "test_member.dump"

 

 

728x90
반응형

댓글



"이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다."

loading