Postgresql Docker Image의 메이저 버전 업그레이드

Docker로 Postgresql의 12버전을 사용하고 있었는데 2021-09-30부로 14버전이 발표됐다. 이젠 12를 버리고 13으로 가야겠다 싶어 업그레이드 방법을 정리한다.

# Postgresql Version

Postgresql 메이저 버전은 최근것만 정리하면 다음과 같다.

Release First release Latest minor version Latest release End of life Milestones
11 2018-10-18 11.13 2021-08-12 2023-11-09 Increased robustness and performance for partitioning, transactions supported in stored procedures, enhanced abilities for query parallelism, just-in-time (JIT) compiling for expressions
12 2019-10-03 12.8 2021-08-12 2024-11-14 Improvements to query performance and space utilization; SQL/JSON path expression support; generated columns; improvements to internationalization, and authentication; new pluggable table storage interface.
13 2020-09-24 13.4 2021-08-12 2025-11-13 Space savings and performance gains from de-duplication of B-tree index entries, improved performance for queries that use aggregates or partitioned tables, better query planning when using extended statistics, parallelized vacuuming of indexes, incremental sorting
14 2021-09-30 14.0 2021-09-30 2026-11-12 Added SQL-standard SEARCH and CYCLE clauses for common table expressions, allow DISTINCT to be added to GROUP BY
15 2022-10-13 15.0 2022-10-13 2027-11-11 Implements SQL-standard MERGE statement. PL/Python now only supports current Python 3, and plpythonu means the discontinued

# What’s New in PostgreSQL 13?

12버전도 지원기간은 많이 남았긴 한데.. 새 버전을 써보고 싶으니 업그레이드하기로 했다. 13의 특징은 다음과 같은 게 있다고 하는데 좀 더 구체적인 설명은 What’s New in PostgreSQL 13? 을 참고하자.

  • Space savings and performance gains from de-duplication of B-tree index entries
  • Improved performance for queries that use aggregates or partitioned tables
  • Better query planning when using extended statistics
  • Parallelized vacuuming of indexes
  • Incremental sorting

# Docker Image

Postgresql의 공식 도커이미지는 Docker Hub에서 제공하고 있고, 이미지는 다음과 같은 형식으로 제공되고 있다.

  • 14.0, 14, latest, 14.0-bullseye, 14-bullseye, bullseye
  • 14.0-alpine, 14-alpine, alpine, 14.0-alpine3.14, 14-alpine3.14, alpine3.14

14.0은 마이너 버전까지 고정시켜 만든 것이고 14는 14 릴리즈의 최신버전을 의미한다. latest는 모든 버전중 최신버전을 의미하는데 안정성을 위해 사용은 추천하지 않는다. bullseye는 최신 데비안인 11.0을 기반으로 만들어진 이미지이고, alpine은 용량을 최적화한 알파인 리눅스를 기반으로 만들어진 이미지이다. 개인적으로는 14 형식의 이미지를 사용한다.

각 이미지의 디테일은 깃헙 저장소에서 확인할 수 있다.

# Version upgrade

# pg_upgrade 이용

Postgresql은 pg_upgradepg_upgradecluster라는 명령어를 제공해주는데 이걸 사용하면 업그레이드를 비교적 간단하게 수행할 수 있다. 문제는 이 명령어를 사용하기 위해서는 OS에 현재버전과 업그레이드할 버전이 모두 설치되어 있어야 하기 때문에 도커에서는 사용할 수 없다는 점이다.

다만 이걸 또 도커에서 사용할 수 있게 만들어놓은 사람이 있긴 하다…

# 백업파일 이용

하지만 내생각에 가장 속편한 것은 그냥 이전버전에서 전체 데이터를 덤프받아 다음버전에 올려버리는 것이다. 우선 이전버전과 다음버전 컨테이너를 동시에 띄우고 다음 내용을 따라한다.

  • 도커 컨테이너의 ID 확인
1
docker ps -a
  • 이전버전 컨테이너에서 파일 덤프
1
docker exec -it [이전버전 container ID] /usr/bin/pg_dumpall -U [username] > dumpfile.sql
  • 다음버전 컨테이너에 파일 복원
1
docker exec -it [다음버전 container ID] psql < dumpfile.sql

이 때 the input device is not a TTY 라고 뜨면서 입력이 안되면 다음 명령어로 직접 집어넣으면 된다.

1
cat dumpfile.sql | docker exec -i [다음버전 container ID] psql -U gitea

끗.

Built with Hugo
Theme Stack designed by Jimmy