1. PostgreSQL 버전 확인

# /usr/bin/postgres --version
postgres (PostgreSQL) 9.2.24

 

2. PostgreSQL 9.2.24 서비스 삭제하기

# systemctl list-unit-files --type=service | grep postgre
postgresql.service                          enabled 

# service postgresql stop
Redirecting to /bin/systemctl stop  postgresql.service

# systemctl disable postgresql
Removed symlink /etc/systemd/system/multi-user.target.wants/postgresql.service.

# systemctl list-unit-files --type=service | grep postgre
postgresql.service                          disabled

# ls -al /usr/lib/systemd/system | grep postgre
-rw-r--r--   1 root root  1986 Feb  5 01:33 postgresql.service

 

3. PostgreSQL 데이터 파일 삭제

# ls -al /var/lib | grep postgre
drwx------   4 postgres       postgres         68 May 14 14:27 pgsql
# rm -rf /var/lib/pgsql
# ls -al /var/lib | grep postgre

 

4. 계정과 그룹 삭제

# cat /etc/passwd | grep postgres
postgres:x:26:26:PostgreSQL Server:/var/lib/pgsql:/bin/bash
# cat /etc/group | grep postgres
postgres:x:26:
 
# userdel postgres
# groupdel postgres
groupdel: group 'postgres' does not exist

# cat /etc/passwd | grep postgres
# cat /etc/group | grep postgres

 

5. 패키지 삭제

# yum remove *postgres*
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package postgresql.x86_64 0:9.2.24-2.el7_7 will be erased
---> Package postgresql-contrib.x86_64 0:9.2.24-2.el7_7 will be erased
---> Package postgresql-devel.x86_64 0:9.2.24-2.el7_7 will be erased
---> Package postgresql-docs.x86_64 0:9.2.24-2.el7_7 will be erased
---> Package postgresql-libs.x86_64 0:9.2.24-2.el7_7 will be erased
---> Package postgresql-server.x86_64 0:9.2.24-2.el7_7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================
 Package                                           Arch                                  Version                                          Repository                               Size
========================================================================================================
Removing:
 postgresql                                        x86_64                                9.2.24-2.el7_7                                   @updates                                 16 M
 postgresql-contrib                                x86_64                                9.2.24-2.el7_7                                   @updates                                1.8 M
 postgresql-devel                                  x86_64                                9.2.24-2.el7_7                                   @updates                                4.0 M
 postgresql-docs                                   x86_64                                9.2.24-2.el7_7                                   @updates                                7.1 M
 postgresql-libs                                   x86_64                                9.2.24-2.el7_7                                   @updates                                667 k
 postgresql-server                                 x86_64                                9.2.24-2.el7_7                                   @updates                                 16 M

Transaction Summary
========================================================================================================
Remove  6 Packages

Installed size: 46 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Erasing    : postgresql-contrib-9.2.24-2.el7_7.x86_64                                                                  1/6 
  Erasing    : postgresql-server-9.2.24-2.el7_7.x86_64                                                                   2/6 
warning: file /var/lib/pgsql/data: remove failed: No such file or directory
warning: file /var/lib/pgsql/backups: remove failed: No such file or directory
warning: file /var/lib/pgsql/.bash_profile: remove failed: No such file or directory
warning: file /var/lib/pgsql: remove failed: No such file or directory
  Erasing    : postgresql-devel-9.2.24-2.el7_7.x86_64                                                                    3/6 
  Erasing    : postgresql-docs-9.2.24-2.el7_7.x86_64                                                                     4/6 
  Erasing    : postgresql-9.2.24-2.el7_7.x86_64                                                                          5/6 
  Erasing    : postgresql-libs-9.2.24-2.el7_7.x86_64                                                                     6/6 
  Verifying  : postgresql-docs-9.2.24-2.el7_7.x86_64                                                                     1/6 
  Verifying  : postgresql-devel-9.2.24-2.el7_7.x86_64                                                                    2/6 
  Verifying  : postgresql-libs-9.2.24-2.el7_7.x86_64                                                                     3/6 
  Verifying  : postgresql-server-9.2.24-2.el7_7.x86_64                                                                   4/6 
  Verifying  : postgresql-contrib-9.2.24-2.el7_7.x86_64                                                                  5/6 
  Verifying  : postgresql-9.2.24-2.el7_7.x86_64                                                                          6/6 

Removed:
postgresql.x86_64 0:9.2.24-2.el7_7         
postgresql-contrib.x86_64 0:9.2.24-2.el7_7     
postgresql-devel.x86_64 0:9.2.24-2.el7_7     
postgresql-docs.x86_64 0:9.2.24-2.el7_7    
postgresql-libs.x86_64 0:9.2.24-2.el7_7     
postgresql-server.x86_64 0:9.2.24-2.el7_7     

Complete!