SUMMARY

[DB] RDS PostgreSQL pg_dump 트러블 슈팅

grammiboii 2025. 6. 6. 01:52

배경

RDS DB를 로컬 sql 파일로 덤프해야 하는 상황!

Copy codepg_dump: error: server version: 17.2; pg_dump version: 14.17 (Homebrew)
pg_dump: error: aborting because of server version mismatch

로컬과 RDS 환경 postgresql 버전이 불일치해서 버전을 변경해야 했다

pg_upgrade

항상 한번에 되는게 없다
바이너리 파일 위치랑 data 위치에 주의해야한다.

https://ivdl.co.za/2024/09/28/upgrading-from-postgresql-16-to-17-installed-with-homebrew-on-an-apple-silicon-mac/

Copy codebrew install postgresql@17
Copy codepg_upgrade -b /opt/homebrew/Cellar/postgresql@14/14.17/bin -d /opt/homebrew/var/postgresql@14 -B /opt/homebrew/Cellar/postgresql@17/17.4_1/bin -D /opt/homebrew/var/postgresql@17

이렇게 시도했을때

Copy codecheck for "/opt/homebrew/Cellar/postgresql@17/17.4_1/bin/postgres" failed: incorrect version: found "postgres (PostgreSQL) 17.4 (Homebrew)", expected "postgres (PostgreSQL) 14.17 (Homebrew)"
Failure, exiting

pg_upgrade 명령어를 14버전으로 실행해서 그랬다.
명시적으로 17버전 pg_upgrade를 실행해야 한다.

Copy code(base) leo@leo-MacBookAir bin % /opt/homebrew/Cellar/postgresql@17/17.4_1/bin/pg_upgrade \
  --old-bindir=/opt/homebrew/Cellar/postgresql@14/14.17/bin \
  --new-bindir=/opt/homebrew/Cellar/postgresql@17/17.4_1/bin \
  --old-datadir=/opt/homebrew/var/postgresql@14 \
  --new-datadir=/opt/homebrew/var/postgresql@17

이렇게 뜨면 성공

Copy codepg_upgrade 작업에서는 최적화기를 위한 통계 정보까지 업그레이드
하지는 않습니다. 새 서버가 실행 될 때, 다음 명령을 수행하길 권합니다:
    /opt/homebrew/Cellar/postgresql@17/17.4_1/bin/vacuumdb --all --analyze-in-stages
아래 스크립트를 실행하면, 옛 클러스터 자료를 지울 것입니다:
    ./delete_old_cluster.sh

이거 그대로 따라하고

Copy code(base) leo@leo-MacBookAir bin % echo 'export PATH="/opt/homebrew/opt/postgresql@17/bin:$PATH"' >> ~/.zshrc
(base) leo@leo-MacBookAir bin % source ~/.zshrc
(base) leo@leo-MacBookAir bin % psql --version
psql (PostgreSQL) 17.4 (Homebrew)

환경변수 설정하면 성공

Copy code(base) leo@leo-MacBookAir bin % pg_dump -h {RDS} -U postgres -f 25_4_30_yumst.sql yumst_db

성공!