Maron's DATA Log

[Mac-PostgreSQL] psql & pgAdmin 이용해 Sample DB (dvdrental.tar) 연결하기 본문

SQL

[Mac-PostgreSQL] psql & pgAdmin 이용해 Sample DB (dvdrental.tar) 연결하기

maron2ee 2020. 11. 12. 16:30

1. PostgreSQL sample DB 다운 받기

 

sp.postgresqltutorial.com/wp-content/uploads/2019/05/dvdrental.zip

  • dvdrental.tar

 

 

2. psql tool을 이용해 Sample DB 생성하기 

 

#psql 실행

> psql

#dvdrental DB 생성하기

CREATE DATABASE dvdrental;

 

 

# pg_restore : -pg_dump에 의해 생성 된 아카이브 파일에서 PostgreSQL 데이터베이스 복원 (~/ dvdrental.tar 이 있는 경로 입력)

pg_restore -d dvdrental -U postgres ~/Desktop/dvdrental.tar/ 

 

#-U postgres : PostgreSQL 데이터베이스 서버에 로그인 할 postgresuser 지정 

#-d dvdrental : 로드 할 대상 데이터베이스 지정

 

#현재 PostgreSQL database server 내 모든 databases 나열

\l

 

#dvdrental 에 연결 

\c dvdrental

 

 

 

3. pgAdmin 이용해 Sample DB (dvdrental) 로드하기 - Restore the Databases

 

Servers > PostgreSQL 13 > Databases > dvdrental > (오른쪽 버튼 클릭) Restore...

Filename   오른쪽 ... 클릭해 dvdrental.tar 경로 찾아 select 

Restore options 클릭해 

Sections > Pre-data, Data, Post-data 모두 Yes 로 변경 후

Restore

 

dvdrental 데이터베이스 사용 가능

Comments