DB/AWS
[AWS] 샘플 데이터 적재
chantant sous la pluie
2025. 5. 26. 16:26
* 학습용 샘플 데이터
1. 실습 환경 구성
EC2 사용 : 포트 22 허용
RDS에는 pg_restore 직접 실행이 안됨.
포트 22 설정 난 안해놨어서 다시 설정해줬다.
2. EC2에 SSH 접속
git bash에서 실행
* SSH : 리눅스 서버에 원격으로 접속할 수 있는 보안 프로토콜
chmod 400 song-key.pem
ssh -i song-key.pem ec2-user@<EC2 퍼블릭 IP>
3. PostgreSQL 클라이언트 도구 설치
pg_restore, psql 등 명령어 도구들을 위한 클라이언트 도구
sudo dnf install -y postgresql15
4. 샘플 데이터 준비
https://neon.tech/postgresql/postgresql-getting-started/postgresql-sample-database
PostgreSQL Sample Database
This tutorial introduces you to a PostgreSQL sample database that you can use for learning and practicing with PostgreSQL.
neon.tech
dvdrental.zip 파일 다운
5. EC2로 파일 전송
로컬에서 실행
*scp (Secure Copy Protocol ) : 로컬에서 EC2로 파일을 전송하는 명령어
scp -i song-key.pem dvdrental.tar ec2-user@<EC2 퍼블릭 IP>:/home/ec2-user/
6. RDS에 DB생성
EC2에서 psql 로 접속하거나 DBeaver에서 접속해서 실행
CREATE DATABASE dvdrental;
7. pg_restore로 데이터 넣기
unzip하고 데이터 넣기
PGPASSWORD='pw' PGSSLMODE=require pg_restore \
-h <RDS 엔드포인트> \
-U <user> \
-d dvdrental \
-p 5432 \
-v dvdrental.tar