pg_upgrade --link로 메이저 버전 업그레이드(end-to-end runbook)
PostgreSQL업그레이드명령어
# As the postgres user, in a writable directory; example 16 -> 17
export OLD_BIN=/usr/pgsql-16/bin NEW_BIN=/usr/pgsql-17/bin
export OLD_DATA=/var/lib/pgsql/16/data NEW_DATA=/var/lib/pgsql/17/data
# 0) initdb the new cluster with the same encoding/locale and checksum setting as the old one (-k if the old cluster has checksums)
# 1) Compatibility check (can run while the old cluster is up, changes no data):
$NEW_BIN/pg_upgrade --old-bindir=$OLD_BIN --new-bindir=$NEW_BIN --old-datadir=$OLD_DATA --new-datadir=$NEW_DATA --check
# 2) Stop the old cluster and upgrade with hard links:
$OLD_BIN/pg_ctl -D $OLD_DATA stop -m fast
$NEW_BIN/pg_upgrade --old-bindir=$OLD_BIN --new-bindir=$NEW_BIN --old-datadir=$OLD_DATA --new-datadir=$NEW_DATA --link --jobs=4
# 3) Carry postgresql.conf/pg_hba.conf customizations over to the new cluster, start it:
$NEW_BIN/pg_ctl -D $NEW_DATA -l /tmp/pg17_start.log start
# 4) Gather statistics, run generated scripts if any:
$NEW_BIN/vacuumdb --all --analyze-in-stages
# psql -X -f update_extensions.sql (if pg_upgrade generated it)
# 5) After validation and a fresh backup, delete the old cluster:
./delete_old_cluster.sh하는 일
먼저 --check로 호환성을 검증한 후, 이전 클러스터의 데이터 파일을 복사하지 않고 새 버전에 hard link하여 데이터 크기와 관계없이 몇 분 안에 메이저 업그레이드를 수행한다. 이후 단계적으로 통계를 수집하고 이전 클러스터를 제거한다.
사용 시점
대형 클러스터를 허용 가능한 짧은 중단(몇 분)으로 제자리에서 새 메이저 버전으로 옮기기 위해.
주의
--link를 사용하면 새 클러스터를 시작한 이후에는 이전 클러스터를 더 이상 안전하게 사용할 수 없다. 되돌리는 유일한 방법은 업그레이드 전에 받은 백업이다. 이전과 새 데이터 디렉터리는 같은 파일 시스템에 있어야 한다. analyze가 끝날 때까지 새 클러스터의 계획이 나쁠 수 있다. pgBackRest를 사용한다면 stanza-upgrade를 실행하고 즉시 새 full 백업을 받는다. 이전 버전의 백업은 새 클러스터로 복원할 수 없다.