본문 바로가기
엑셈 경쟁력/DB 인사이드

DB 인사이드 | PostgreSQL Setup - Minor Upgrade

by EXEM 2022. 9. 28.

※ 목차 ※
Upgrade PostgreSQL Minor Version on Linux
Upgrade PostgreSQL Minor Version on Windows

 

Upgrade PostgreSQL Minor Version on Linux 목차

PostgreSQL의 Minor버전 릴리즈는 Major버전의 아키텍처를 변경(변형) 하지 않는 선에서 자주 발생하는 버그, 보안 및 데이터 손상 문제에 대해서만 수정된 내용을 제공합니다. Major버전 내부 아키텍처 변경이 없기 때문에 Minor버전 간의 호환성을 유지할 수 있습니다.
Linux에서 Minor Version Upgrade는 세가지 방법이 존재합니다.
첫 번째로, yum, apt를 통한 Minor Upgrade가 있습니다. 인터넷이 연결되어 있고, PostgreSQL Repository 등록이 되어 있어야 합니다. 업그레이드 시에 자동으로 서비스(Systemd)가 갱신됨에 따라 자동으로 PostgreSQL Server가 재기동됩니다.(정확히는 종료 → Upgrade → 기동 순으로 작동합니다.)
두 번째로, 인터넷이 연결되지 않은 서버에서 사용할 수 있는 rpm, dpkg를 통한 Minor Upgrade가 있습니다. 앞서 언급한 yum, apt를 통한 업그레이드와 진행 절차는 동일하며, 서버가 외부 인터넷 연결 가능 여부에 따라 설치 파일 준비 방법 차이만 있습니다.
세 번째로, Source File을 이용한 방법이 있습니다.

  yum rpm apt dpkg Source File
설치파일 Repository 개별준비 Repository 개별준비 개별준비
설치버전 Major별 최신 Minor 선택 Major별 최신 Minor 선택 선택
업그레이드 방법 yum install -y postgresql{VERSION}-server rpm -Uvh {Package} apt install -y --only-upgrade postgresql* dpkg -i {Package}  

이번 단락에서는 Linux Platform에서 Minor Version Upgrade에 대한 내용을 다루며, ①설치 파일 준비, ②PostgreSQL 설치 여부 확인, ③PostgreSQL 업그레이드, ④PostgreSQL 업그레이드 확인 순으로 기술됩니다. Linux Platform은 CentOS 7.9, Ubuntu 22.04로 진행하며, PostgreSQL 14.2에서 14.5로 업그레이드하는 내용을 기술합니다.
업그레이드 성공 여부를 확인하기 위해 postgres Database에 exem_tab 테이블을 조회합니다.

-- 테스트 테이블 생성
CREATE TABLE exem_tab ( no integer ,
                        in_date text not null default now() ) ;
INSERT INTO exem_tab VALUES (1) ;
INSERT INTO exem_tab VALUES (2) ;
INSERT INTO exem_tab VALUES (3) ;

 

1. 설치 파일 준비

업그레이드 방법에 따라서 설치 파일을 준비합니다.

업그레이드 방법 설명
yum 인터넷 연결이 가능해야 하며, PostgreSQL yum Repository 등록 필요.
PostgreSQL Setup - Installation > Install PostgreSQL on Linux (CentOS - yum) 문서 참고
rpm yum.postgresql.org/packages에서 다운로드 가능.
PostgreSQL Setup - Installation > Install PostgreSQL on Linux (CentOS - rpm) 문서 참고
apt 인터넷 연결이 가능해야 하며, PostgreSQL apt Repository 등록 필요.
PostgreSQL Setup - Installation > Install PostgreSQL on Linux (Ubuntu - apt) 문서 참고
dpkg apt.postgresql.org/pub/repos/apt/pool/main/p/에서 다운로드 가능
PostgreSQL Setup - Installation > Install PostgreSQL on Linux (Ubuntu- dpkg) 문서 참고
Source File www.postgresql.org/ftp/source에서 다운로드 가능
PostgreSQL Setup - Installation > Install PostgreSQL on Linux (Source File) 문서 참고

 

2. PostgreSQL 설치 여부 확인

CentOS (RedHat계열)

## CentOS
yum list installed | grep postgresql
rpm -qa | grep postgresql
더보기
[root@centos ~]# yum list installed | grep postgresql
postgresql14.x86_64                         14.2-1PGDG.rhel7           installed
postgresql14-libs.x86_64                    14.2-1PGDG.rhel7           installed
postgresql14-server.x86_64                  14.2-1PGDG.rhel7           installed

[root@centos ~]# rpm -qa | grep postgresql
postgresql14-14.2-1PGDG.rhel7.x86_64
postgresql14-libs-14.2-1PGDG.rhel7.x86_64
postgresql14-server-14.2-1PGDG.rhel7.x86_64
## [postgres] PostgreSQL 버전 확인 및 데이터 확인
su - postgres
psql -c "SELECT VERSION()"
psql -c "SELECT * FROM exem_tab"
더보기
[root@centos ~]# su - postgres

-bash-4.2$ psql -c "SELECT VERSION()"
                                                 version
---------------------------------------------------------------------------------------------------------
 PostgreSQL 14.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
(1 row)

-bash-4.2$ psql -c "SELECT * FROM exem_tab"
 no |            in_date
----+-------------------------------
  1 | 2022-09-07 15:18:28.445582+09
  2 | 2022-09-07 15:18:30.516606+09
  3 | 2022-09-07 15:18:32.743652+09
(3 rows)

 

Ubuntu (Debian계열)

## Ubuntu
apt list --installed | grep postgresql
dpkg --get-selections | grep postgresql
더보기
root@ubuntu:~# apt list --installed | grep postgresql
postgresql-14/now 14.2-1.pgdg22.04+1+b1 amd64 [installed,upgradable to: 14.3-1.pgdg22.04+1]
postgresql-client-14/now 14.2-1.pgdg22.04+1+b1 amd64 [installed,upgradable to: 14.3-1.pgdg22.04+1]
postgresql-client-common/jammy-pgdg,now 241.pgdg22.04+1 all [installed]
postgresql-common/jammy-pgdg,now 241.pgdg22.04+1 all [installed]

root@ubuntu:~# dpkg --get-selections | grep postgresql
postgresql-14                                   install
postgresql-client-14                            install
postgresql-client-common                        install
postgresql-common                               install
## [postgres] PostgreSQL 버전 확인 및 데이터 확인
su - postgres
psql -c "SELECT VERSION()"
psql -c "SELECT * FROM exem_tab"
더보기
root@ubuntu:~# su - postgres
postgres@ubuntu:~$ psql -c "SELECT VERSION()"
                                                      version
---------------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 14.2 (Ubuntu 14.2-1.pgdg22.04+1+b1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.2.0-16ubuntu1) 11.2.0, 64-bit
(1 row)

postgres@ubuntu:~$ psql -c "SELECT * FROM exem_tab"
 no |            in_date
----+-------------------------------
  1 | 2022-09-07 05:51:04.669347+00
  2 | 2022-09-07 05:51:08.348246+00
  3 | 2022-09-07 05:51:12.156604+00
(3 rows)

 

Source File

## PostgreSQL Process 확인
ps -ef | grep postgres
더보기
[postgres@centos ~]$ ps -ef | grep postgres
postgres 20576     1  0 16:35 ?        00:00:00 /home/postgres/PostgreSQL_Engine/bin/postgres -D /home/postgres/PostgreSQL_Data
postgres 20578 20576  0 16:35 ?        00:00:00 postgres: checkpointer
postgres 20579 20576  0 16:35 ?        00:00:00 postgres: background writer
postgres 20580 20576  0 16:35 ?        00:00:00 postgres: walwriter
postgres 20581 20576  0 16:35 ?        00:00:00 postgres: autovacuum launcher
postgres 20582 20576  0 16:35 ?        00:00:00 postgres: stats collector
postgres 20583 20576  0 16:35 ?        00:00:00 postgres: logical replication launcher
## [postgres] PostgreSQL 버전 확인 및 데이터 확인
/home/postgres/PostgreSQL_Engine/bin/psql -c "SELECT VERSION()"
/home/postgres/PostgreSQL_Engine/bin/psql -c "SELECT * FROM exem_tab"
더보기
[postgres@centos ~]$ /home/postgres/PostgreSQL_Engine/bin/psql -c "SELECT VERSION()"
                                                 version
---------------------------------------------------------------------------------------------------------
 PostgreSQL 14.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
(1 row)

[postgres@centos ~]$ /home/postgres/PostgreSQL_Engine/bin/psql -c "SELECT * FROM exem_tab"
 no |            in_date
----+-------------------------------
  1 | 2022-09-07 16:36:38.275461+09
  2 | 2022-09-07 16:36:42.46244+09
  3 | 2022-09-07 16:36:45.221768+09
(3 rows)

 

 

3. PostgreSQL 업그레이드

CentOS (RedHat계열) - Using yum

## CentOS Using yum
## syntax : yum install -y postgresql{VERSION}-server
yum install -y postgresql14-server
더보기
[root@centos ~]# yum install -y postgresql14-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.kakao.com
 * extras: mirror.kakao.com
 * updates: mirror.kakao.com
Resolving Dependencies
--> Running transaction check
---> Package postgresql14-server.x86_64 0:14.2-1PGDG.rhel7 will be updated
---> Package postgresql14-server.x86_64 0:14.5-1PGDG.rhel7 will be an update
--> Processing Dependency: postgresql14-libs(x86-64) = 14.5-1PGDG.rhel7 for package: postgresql14-server-14.5-1PGDG.rhel7.x86_64
--> Processing Dependency: postgresql14(x86-64) = 14.5-1PGDG.rhel7 for package: postgresql14-server-14.5-1PGDG.rhel7.x86_64
--> Running transaction check
---> Package postgresql14.x86_64 0:14.2-1PGDG.rhel7 will be updated
---> Package postgresql14.x86_64 0:14.5-1PGDG.rhel7 will be an update
---> Package postgresql14-libs.x86_64 0:14.2-1PGDG.rhel7 will be updated
---> Package postgresql14-libs.x86_64 0:14.5-1PGDG.rhel7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================
 Package                              Arch                    Version                            Repository               Size
===============================================================================================================================
Updating:
 postgresql14-server                  x86_64                  14.5-1PGDG.rhel7                   pgdg14                  5.5 M
Updating for dependencies:
 postgresql14                         x86_64                  14.5-1PGDG.rhel7                   pgdg14                  1.5 M
 postgresql14-libs                    x86_64                  14.5-1PGDG.rhel7                   pgdg14                  270 k

Transaction Summary
===============================================================================================================================
Upgrade  1 Package (+2 Dependent packages)

Total download size: 7.3 M
Downloading packages:
No Presto metadata available for pgdg14
(1/3): postgresql14-libs-14.5-1PGDG.rhel7.x86_64.rpm                                                    | 270 kB  00:00:02
(2/3): postgresql14-14.5-1PGDG.rhel7.x86_64.rpm                                                         | 1.5 MB  00:00:02
(3/3): postgresql14-server-14.5-1PGDG.rhel7.x86_64.rpm                                                  | 5.5 MB  00:00:02
-------------------------------------------------------------------------------------------------------------------------------
Total                                                                                          1.6 MB/s | 7.3 MB  00:00:04
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Updating   : postgresql14-libs-14.5-1PGDG.rhel7.x86_64                                                                   1/6
  Updating   : postgresql14-14.5-1PGDG.rhel7.x86_64                                                                        2/6
  Updating   : postgresql14-server-14.5-1PGDG.rhel7.x86_64                                                                 3/6
  Cleanup    : postgresql14-server-14.2-1PGDG.rhel7.x86_64                                                                 4/6
  Cleanup    : postgresql14-14.2-1PGDG.rhel7.x86_64                                                                        5/6
  Cleanup    : postgresql14-libs-14.2-1PGDG.rhel7.x86_64                                                                   6/6
  Verifying  : postgresql14-14.5-1PGDG.rhel7.x86_64                                                                        1/6
  Verifying  : postgresql14-server-14.5-1PGDG.rhel7.x86_64                                                                 2/6
  Verifying  : postgresql14-libs-14.5-1PGDG.rhel7.x86_64                                                                   3/6
  Verifying  : postgresql14-14.2-1PGDG.rhel7.x86_64                                                                        4/6
  Verifying  : postgresql14-libs-14.2-1PGDG.rhel7.x86_64                                                                   5/6
  Verifying  : postgresql14-server-14.2-1PGDG.rhel7.x86_64                                                                 6/6

Updated:
  postgresql14-server.x86_64 0:14.5-1PGDG.rhel7

Dependency Updated:
  postgresql14.x86_64 0:14.5-1PGDG.rhel7                      postgresql14-libs.x86_64 0:14.5-1PGDG.rhel7

Complete!

 

CentOS (RedHat계열) - Using rpm

## CentOS Using rpm
## syntax : rpm -Uvh {Pacakge}
rpm -Uvh postgresql14-libs-14.5-1PGDG.rhel7.x86_64.rpm \
         postgresql14-server-14.5-1PGDG.rhel7.x86_64.rpm \
         postgresql14-14.5-1PGDG.rhel7.x86_64.rpm
더보기
[root@centos ~]# rpm -Uvh postgresql14-libs-14.5-1PGDG.rhel7.x86_64.rpm \
>          postgresql14-server-14.5-1PGDG.rhel7.x86_64.rpm \
>          postgresql14-14.5-1PGDG.rhel7.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:postgresql14-libs-14.5-1PGDG.rhel################################# [ 17%]
   2:postgresql14-14.5-1PGDG.rhel7    ################################# [ 33%]
   3:postgresql14-server-14.5-1PGDG.rh################################# [ 50%]
Cleaning up / removing...
   4:postgresql14-server-14.2-1PGDG.rh################################# [ 67%]
   5:postgresql14-14.2-1PGDG.rhel7    ################################# [ 83%]
   6:postgresql14-libs-14.2-1PGDG.rhel################################# [100%]

 

Ubuntu (Debian계열) - Using apt

## Ubuntu Using apt
apt install -y --only-upgrade postgresql*
더보기
root@ubuntu:~# apt install -y --only-upgrade postgresql*
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
... 중략 ...
Suggested packages:
  postgresql-doc-14
Recommended packages:
  sysstat
The following packages will be upgraded:
  libpq5 postgresql-14 postgresql-client-14 postgresql-client-common postgresql-common
5 upgraded, 0 newly installed, 0 to remove and 93 not upgraded.
Need to get 18.5 MB of archives.
After this operation, 364 kB of additional disk space will be used.
Get:1 http://apt.postgresql.org/pub/repos/apt jammy-pgdg/main amd64 libpq5 amd64 14.5-1.pgdg22.04+1 [172 kB]
Get:2 http://apt.postgresql.org/pub/repos/apt jammy-pgdg/main amd64 postgresql-common all 242.pgdg22.04+1 [230 kB]
Get:3 http://apt.postgresql.org/pub/repos/apt jammy-pgdg/main amd64 postgresql-client-common all 242.pgdg22.04+1 [92.2 kB]
Get:4 http://apt.postgresql.org/pub/repos/apt jammy-pgdg/main amd64 postgresql-client-14 amd64 14.5-1.pgdg22.04+1 [1,615 kB]
Get:5 http://apt.postgresql.org/pub/repos/apt jammy-pgdg/main amd64 postgresql-14 amd64 14.5-1.pgdg22.04+1 [16.4 MB]
Fetched 18.5 MB in 7s (2,841 kB/s)
Preconfiguring packages ...
(Reading database ... 75389 files and directories currently installed.)
Preparing to unpack .../libpq5_14.5-1.pgdg22.04+1_amd64.deb ...
Unpacking libpq5:amd64 (14.5-1.pgdg22.04+1) over (14.2-1.pgdg22.04+1+b1) ...
Preparing to unpack .../postgresql-common_242.pgdg22.04+1_all.deb ...
Leaving 'diversion of /usr/bin/pg_config to /usr/bin/pg_config.libpq-dev by postgresql-common'
Unpacking postgresql-common (242.pgdg22.04+1) over (241.pgdg22.04+1) ...
Preparing to unpack .../postgresql-client-common_242.pgdg22.04+1_all.deb ...
Unpacking postgresql-client-common (242.pgdg22.04+1) over (241.pgdg22.04+1) ...
Preparing to unpack .../postgresql-client-14_14.5-1.pgdg22.04+1_amd64.deb ...
Unpacking postgresql-client-14 (14.5-1.pgdg22.04+1) over (14.2-1.pgdg22.04+1+b1) ...
Preparing to unpack .../postgresql-14_14.5-1.pgdg22.04+1_amd64.deb ...
Unpacking postgresql-14 (14.5-1.pgdg22.04+1) over (14.2-1.pgdg22.04+1+b1) ...
Setting up postgresql-client-common (242.pgdg22.04+1) ...
Setting up libpq5:amd64 (14.5-1.pgdg22.04+1) ...
Setting up postgresql-client-14 (14.5-1.pgdg22.04+1) ...
Setting up postgresql-common (242.pgdg22.04+1) ...
Setting up postgresql-14 (14.5-1.pgdg22.04+1) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3) ...
needrestart is being skipped since dpkg has failed

 

Ubuntu (Debian계열) - Using dpkg

## Ubuntu Using dpkg
dpkg -i libpq5_14.5-1.pgdg22.04+1_amd64.deb \
        postgresql-14_14.5-1.pgdg22.04+1_amd64.deb \
        postgresql-client-14_14.5-1.pgdg22.04+1_amd64.deb \
        postgresql-client-common_242.pgdg22.04+1_all.deb \
        postgresql-common_242.pgdg22.04+1_all.deb
더보기
root@ubuntu:~# dpkg -i libpq5_14.5-1.pgdg22.04+1_amd64.deb \
        postgresql-14_14.5-1.pgdg22.04+1_amd64.deb \
        postgresql-client-14_14.5-1.pgdg22.04+1_amd64.deb \
        postgresql-client-common_242.pgdg22.04+1_all.deb \
        postgresql-common_242.pgdg22.04+1_all.deb
(Reading database ... 75389 files and directories currently installed.)
Preparing to unpack libpq5_14.5-1.pgdg22.04+1_amd64.deb ...
Unpacking libpq5:amd64 (14.5-1.pgdg22.04+1) over (14.2-1.pgdg22.04+1+b1) ...
Preparing to unpack postgresql-14_14.5-1.pgdg22.04+1_amd64.deb ...
Unpacking postgresql-14 (14.5-1.pgdg22.04+1) over (14.2-1.pgdg22.04+1+b1) ...
Preparing to unpack postgresql-client-14_14.5-1.pgdg22.04+1_amd64.deb ...
Unpacking postgresql-client-14 (14.5-1.pgdg22.04+1) over (14.2-1.pgdg22.04+1+b1) ...
Preparing to unpack postgresql-client-common_242.pgdg22.04+1_all.deb ...
Unpacking postgresql-client-common (242.pgdg22.04+1) over (241.pgdg22.04+1) ...
Preparing to unpack postgresql-common_242.pgdg22.04+1_all.deb ...
Leaving 'diversion of /usr/bin/pg_config to /usr/bin/pg_config.libpq-dev by postgresql-common'
Unpacking postgresql-common (242.pgdg22.04+1) over (241.pgdg22.04+1) ...
Setting up libpq5:amd64 (14.5-1.pgdg22.04+1) ...
Setting up postgresql-client-common (242.pgdg22.04+1) ...
Setting up postgresql-common (242.pgdg22.04+1) ...
Setting up postgresql-client-14 (14.5-1.pgdg22.04+1) ...
Setting up postgresql-14 (14.5-1.pgdg22.04+1) ...
Processing triggers for libc-bin (2.35-0ubuntu3) ...
Processing triggers for man-db (2.10.2-1) ...

 

Using Source File

최초 설치방법과 같은 방법으로 업그레이드 버전 PostgreSQL을 설치합니다.

## [postgres] 업그레이드 버전 PostgreSQL 압축해제 (Version : 14.5)
tar -zxvf postgresql-14.5.tar.gz
mkdir PostgreSQL_14.5
cd PostgreSQL_14.5

## [postgres] 업그레이드 버전 PostgreSQL 설정 (Version : 14.5)
/home/postgres/postgresql-14.5/configure --prefix=/home/postgres/PostgreSQL_14.5 --without-readline --without-zlib
make && make install

설치가 완료되면, 기동 중인 PostgreSQL을 종료한 후 디렉토리명을 변경하여 다시 기동 합니다.

## [postgres] 기동중인 PostgreSQL 종료 (Version : 14.2)
/home/postgres/PostgreSQL_Engine/bin/pg_ctl -D /home/postgres/PostgreSQL_Data stop
## [postgres] PostgreSQL 14.2 엔진 디렉토리명 변경
mv /home/postgres/PostgreSQL_Engine /home/postgres/PostgreSQL_Engine_bak

## [postgres] PostgreSQL 14.5 엔진 디렉토리명 변경
mv /home/postgres/PostgreSQL_14.5 /home/postgres/PostgreSQL_Engine
## [postgres] PostgreSQL 기동 (Version : 14.5)
/home/postgres/PostgreSQL_Engine/bin/pg_ctl -D /home/postgres/PostgreSQL_Data start
더보기
[postgres@centos ~]$ /home/postgres/PostgreSQL_Engine/bin/pg_ctl -D /home/postgres/PostgreSQL_Data start
waiting for server to start....2022-09-07 16:45:57.626 KST [32167] LOG:  starting PostgreSQL 14.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
2022-09-07 16:45:57.627 KST [32167] LOG:  listening on IPv6 address "::1", port 5432
2022-09-07 16:45:57.627 KST [32167] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2022-09-07 16:45:57.629 KST [32167] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2022-09-07 16:45:57.632 KST [32168] LOG:  database system was shut down at 2022-09-07 16:45:33 KST
2022-09-07 16:45:57.633 KST [32167] LOG:  database system is ready to accept connections
 done
server started

 

 

4. PostgreSQL 업그레이드 확인

CentOS (RedHat계열)

## CentOS
yum list installed | grep postgresql
rpm -qa | grep postgresql
더보기
[root@centos ~]# yum list installed | grep postgresql
postgresql14.x86_64                     14.5-1PGDG.rhel7               @pgdg14
postgresql14-libs.x86_64                14.5-1PGDG.rhel7               @pgdg14
postgresql14-server.x86_64              14.5-1PGDG.rhel7               @pgdg14

[root@centos ~]# rpm -qa | grep postgresql
postgresql14-server-14.5-1PGDG.rhel7.x86_64
postgresql14-libs-14.5-1PGDG.rhel7.x86_64
postgresql14-14.5-1PGDG.rhel7.x86_64
## [postgres] PostgreSQL 버전 확인 및 데이터 확인
su - postgres
psql -c "SELECT VERSION()"
psql -c "SELECT * FROM exem_tab"
더보기
[root@centos ~]# su - postgres

-bash-4.2$ psql -c "SELECT VERSION()"
                                                 version
---------------------------------------------------------------------------------------------------------
 PostgreSQL 14.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
(1 row)

-bash-4.2$ psql -c "SELECT * FROM exem_tab"
 no |            in_date
----+-------------------------------
  1 | 2022-09-07 15:18:28.445582+09
  2 | 2022-09-07 15:18:30.516606+09
  3 | 2022-09-07 15:18:32.743652+09
(3 rows)

 

Ubuntu (Debian계열)

## Ubuntu
apt list --installed | grep postgresql
dpkg --get-selections | grep postgresql
더보기
root@ubuntu:~# apt list --installed | grep postgresql
postgresql-14/jammy-pgdg,now 14.5-1.pgdg22.04+1 amd64 [installed]
postgresql-client-14/jammy-pgdg,now 14.5-1.pgdg22.04+1 amd64 [installed]
postgresql-client-common/jammy-pgdg,now 242.pgdg22.04+1 all [installed]
postgresql-common/jammy-pgdg,now 242.pgdg22.04+1 all [installed]

root@ubuntu:~# dpkg --get-selections | grep postgresql
postgresql-14                                   install
postgresql-client-14                            install
postgresql-client-common                        install
postgresql-common                               install
## [postgres] PostgreSQL 버전 확인 및 데이터 확인
su - postgres
psql -c "SELECT VERSION()"
psql -c "SELECT * FROM exem_tab"
더보기
root@ubuntu:~# su - postgres
postgres@ubuntu:~$ psql -c "SELECT VERSION()"
                                                           version
------------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 14.5 (Ubuntu 14.5-1.pgdg22.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0, 64-bit
(1 row)

postgres@ubuntu:~$ psql -c "SELECT * FROM exem_tab"
 no |            in_date
----+-------------------------------
  1 | 2022-09-07 05:51:04.669347+00
  2 | 2022-09-07 05:51:08.348246+00
  3 | 2022-09-07 05:51:12.156604+00
(3 rows)

 

Source File

## PostgreSQL Process 확인
ps -ef | grep postgres
더보기
[postgres@centos ~]$ ps -ef | grep postgres
postgres 32167     1  0 16:45 ?        00:00:00 /home/postgres/PostgreSQL_Engine/bin/postgres -D /home/postgres/PostgreSQL_Data
postgres 32169 32167  0 16:45 ?        00:00:00 postgres: checkpointer
postgres 32170 32167  0 16:45 ?        00:00:00 postgres: background writer
postgres 32171 32167  0 16:45 ?        00:00:00 postgres: walwriter
postgres 32172 32167  0 16:45 ?        00:00:00 postgres: autovacuum launcher
postgres 32173 32167  0 16:45 ?        00:00:00 postgres: stats collector
postgres 32174 32167  0 16:45 ?        00:00:00 postgres: logical replication launcher
## [postgres] PostgreSQL 버전 확인 및 데이터 확인
/home/postgres/PostgreSQL_Engine/bin/psql -c "SELECT VERSION()"
/home/postgres/PostgreSQL_Engine/bin/psql -c "SELECT * FROM exem_tab"
더보기
[postgres@centos ~]$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/postgres/PostgreSQL_Engine/lib
[postgres@centos ~]$ /home/postgres/PostgreSQL_Engine/bin/psql -c "SELECT VERSION()"
                                                 version
---------------------------------------------------------------------------------------------------------
 PostgreSQL 14.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
(1 row)

[postgres@centos ~]$ /home/postgres/PostgreSQL_Engine/bin/psql -c "SELECT * FROM exem_tab"
 no |            in_date
----+-------------------------------
  1 | 2022-09-07 16:36:38.275461+09
  2 | 2022-09-07 16:36:42.46244+09
  3 | 2022-09-07 16:36:45.221768+09
(3 rows)
📢 psql 접속 시 libpq.so.5 라이브러리 관련 에러발생
** 문제
error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory
** 해결방법
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/postgres/PostgreSQL_Engine/lib

 

Upgrade PostgreSQL Minor Version on Windows 목차

Windows에서 Minor Version Upgrade는 두 가지 방법이 존재합니다.
첫 번째로, PostgreSQL 설치 파일(exe File)을 통한 Minor Upgrade가 있습니다. PostgreSQL Install 과정과 동일하며(PostgreSQL Setup - Installation > Install PostgreSQL on Windows - 설치 관리자 참고), 설치 관리자가 기존에 설치된 폴더를 인식하여 업그레이드를 진행합니다. 서비스 종료 → 서비스 삭제 → 업그레이드 → 서비스 등록 → 서비스 시작 순으로 업그레이드를 수행합니다. 따라서, 업그레이드(설치) 소요시간만큼 다운타임이 발생합니다.
두 번째로, Binary File(Zip Archive)를 통한 Minor Upgrade가 있습니다. 이 방법도 PostgreSQL Install 과정과 동일하며(PostgreSQL Setup - Installation > Install PostgreSQL on Windows - Binary File 참고), 압축해제 후 폴더명만 변경하여 업그레이드를 할 수 있습니다. 압축해제 → 서비스 종료 → 폴더명 변경 → 서비스 시작 순으로 업그레이드를 수행하며, 업그레이드에 다운타임을 최소한으로 가져갈 수 있습니다.
이번 단락에서는 Windows Platform에서 Minor Version Upgrade에 대한 내용을 다루며, 아래 순서로 기술됩니다. 세부내용으로 ①설치 파일 준비, ②PostgreSQL 설치 여부 확인, ③PostgreSQL 업그레이드, ④PostgreSQL 업그레이드 확인 순으로 기술됩니다. Windows 10 Platform에서 PostgreSQL 14.2를 14.5로 업그레이드하는 내용을 기술합니다.
업그레이드 성공 여부를 확인하기 위해 postgres Database에 exem_tab 테이블을 조회합니다.

-- 테스트 테이블 생성
CREATE TABLE exem_tab ( no integer ,
                        in_date text not null default now() ) ;
INSERT INTO exem_tab VALUES (1) ;
INSERT INTO exem_tab VALUES (2) ;
INSERT INTO exem_tab VALUES (3) ;

 

1. 설치 파일 준비

업그레이드 방법에 따라서 설치 파일을 준비합니다.

업그레이드 방법 설명
exe File www.enterprisedb.com/downloads/postgres-postgresql-downloads에서 최신 Minor 버전에 대해서만 다운로드 가능.
Binary File https://www.enterprisedb.com/download-postgresql-binaries에서 최신 Minor 버전에 대해서만 다운로드 가능.

 

 

2. PostgreSQL 설치 여부 확인

## 명령 프롬프트에서 아래 명령줄 수행
CMD> C:\PostgreSQL_Engine\bin\psql -U postgres -c "SELECT VERSION()"
CMD> C:\PostgreSQL_Engine\bin\psql -U postgres -c "SELECT * FROM exem_tab"
더보기
C:\Users\admin>C:\PostgreSQL_Engine\bin\psql -U postgres -c "SELECT VERSION()"
postgres 사용자의 암호:
                          version
------------------------------------------------------------
 PostgreSQL 14.2, compiled by Visual C++ build 1914, 64-bit
(1개 행)

C:\Users\admin>C:\PostgreSQL_Engine\bin\psql -U postgres -c "SELECT * FROM exem_tab"
postgres 사용자의 암호:
 no |            in_date
----+-------------------------------
  1 | 2022-09-08 10:45:51.975903+09
  2 | 2022-09-08 10:46:04.124803+09
  3 | 2022-09-08 10:46:09.153465+09
(3개 행)

 

 

3. PostgreSQL 업그레이드

 

설치관리자

더보기

Step 1. PostgreSQL 설치 파일을 실행합니다.(파일명 : postgresql-14.5-1-windows-x64.exe

더보기

Step 2. 설치할 구성요소를 선택(or 선택해제) 후 Next 버튼 클릭

  - PostgreSQL Server : PostgreSQL Database Server 포함

  - pgAdmin4 : PostgreSQL GUI Management Tool 포함

  - Stack Builder : Management, integration, Migration, Replication, Geospatial 등 포함

  - Command Line Tools : psql, pg_dump, pg_restore와 같은 Command Line Interface 포함

더보기

Step 3. 기존에 설치된 PostgreSQL이 존재하며, 이를 Upgrade 할지 여부 확인. Next 버튼 클릭

더보기

Step 4. 기존에 사용중이던 PostgreSQL Data 경로 및 Port를 사용할 건지 확인. Next 버튼 클릭

더보기

Step 5. Step 3부터 Step 5까지 설정 한 내용 확인 후 Next 버튼 클릭

더보기

Step 6. Next 버튼 클릭 하여 설치 실행

더보기

Step 7. PostgreSQL Server가 기동 중일 경우 경고창 발생. OK를 클릭하여 계속 Upgrade 진행

📢 PostgreSQL Server가 기동 중일 때 Minor Upgrade 순서
PostgreSQL Server 서비스 종료 → PostgreSQL Server 서비스 삭제 → 경고창 발생 → OK → Upgrade 시작 → Upgrade 완료 → PostgreSQL Server 서비스 등록 → PostgreSQL Server 서비스 기동
더보기

Step 8. Stack Builder를 실행할지 여부 선택 후 Finish 버튼 클릭

 

Binary File

더보기

Step 1. 다운로드한 Binary File 압축 해제(파일명 : postgresql-14.5-1-windows-x64-binaries.zip)

더보기

Step 2. PostgreSQL 서비스 종료(명령 프롬프트 관리자 권한으로 실행)

## 등록되어 있는 서비스 종료 (GUI환경에서 postgresql-x64-14 서비스 종료)
CMD> NET STOP postgresql-x64-14

C:\Users\admin\Desktop>NET STOP postgresql-x64-14
postgresql-x64-14 서비스를 멈춥니다..
postgresql-x64-14 서비스를 잘 멈추었습니다.
더보기

Step 3. PostgreSQL Engine 폴더명 변경

기존에 운영중이던 폴더명 변경 : PostgreSQL_Engine → PostgreSQL_Engine_bak
업그레이드 버전 폴더명 변경 : pgsql → PostgreSQL_Engine

더보기

Step 4. PostgreSQL 서비스 시작(명령 프롬프트 관리자 권한으로 실행)

## 등록되어 있는 서비스 시작 (GUI환경에서 postgresql-x64-14 서비스 시작)
CMD> NET START postgresql-x64-14

C:\Users\admin\Desktop>NET START postgresql-x64-14
postgresql-x64-14 서비스를 시작합니다..
postgresql-x64-14 서비스가 잘 시작되었습니다.

 

 

4. PostgreSQL 업그레이드 확인

## 명령 프롬프트에서 아래 명령줄 수행
CMD> C:\PostgreSQL_Engine\bin\psql -U postgres -c "SELECT VERSION()"
CMD> C:\PostgreSQL_Engine\bin\psql -U postgres -c "SELECT * FROM exem_tab"
더보기
C:\Users\admin>C:\PostgreSQL_Engine\bin\psql -U postgres -c "SELECT VERSION()"
postgres 사용자의 암호:
                          version
------------------------------------------------------------
 PostgreSQL 14.5, compiled by Visual C++ build 1914, 64-bit
(1개 행)

C:\Users\admin>C:\PostgreSQL_Engine\bin\psql -U postgres -c "SELECT * FROM exem_tab"
postgres 사용자의 암호:
 no |            in_date
----+-------------------------------
  1 | 2022-09-08 10:45:51.975903+09
  2 | 2022-09-08 10:46:04.124803+09
  3 | 2022-09-08 10:46:09.153465+09
(3개 행)

 

 

 

기획 및 글 | 기술기획팀

 

 

 

 

댓글