Uninstall PostgreSQL 17(Source Installation)
Table of Contents
1. Stop the PostgreSQL Service
[root@pgdb02 ~]# systemctl stop postgresql-17
[root@pgdb02 ~]# systemctl disable postgresql-17
Removed "/etc/systemd/system/multi-user.target.wants/postgresql-17.service".
[root@pgdb02 ~]#
2. Remove the systemd Service File (if created)
[root@pgdb02 ~]# ls -l /etc/systemd/system/postgresql-17.service
-rw-r--r--. 1 root root 588 Jun 19 21:20 /etc/systemd/system/postgresql-17.service
[root@pgdb02 ~]#
[root@pgdb02 ~]# rm -f /etc/systemd/system/postgresql-17.service
[root@pgdb02 ~]#
[root@pgdb02 ~]# systemctl daemon-reload
[root@pgdb02 ~]#
3. Force Remove the Entire PostgreSQL Directory
WARNING: This permanently deletes all binaries, libraries, and data. Ensure your data is backed up before this step.
[root@pgdb02 ~]# rm -rf /pgBin/*
[root@pgdb02 ~]#
4. Remove Leftover Temporary Files if any
rm -f /tmp/.s.PGSQL.*
rm -f /tmp/.s.PGSQL.*.lock
5. Remove the postgres OS User (Optional)
[root@pgdb02 ~]# userdel -r postgres
[root@pgdb02 ~]# groupdel postgres
groupdel: group 'postgres' does not exist
[root@pgdb02 ~]#
6. Refresh the Library Cache
[root@pgdb02 ~]# ldconfig
[root@pgdb02 ~]#
Rebuilds the OS shared library cache to remove stale references to deleted PostgreSQL libraries.
The files are gone but the OS cache still remembers them. ldconfig clears that memory — it's a one-second cleanup that prevents broken library reference errors for any app that linked against libpq.
7. Verify Complete Removal
[root@pgdb02 ~]# ps -ef | grep postgres
root 4818 3561 0 19:44 pts/1 00:00:00 grep --color=auto postgres
[root@pgdb02 ~]# systemctl status postgresql-17
Unit postgresql-17.service could not be found.
[root@pgdb02 ~]#
[root@pgdb02 ~]# find /usr/local -name "*pgsql*" 2>/dev/null
[root@pgdb02 ~]# ss -tulpn | grep 543
[root@pgdb02 ~]#
Note: No need to run
make uninstall— therm -rfin Step 3 already handles complete removal of all installed files.
Caution: Your use of any information or materials on this website is entirely at your own risk. It is provided for educational purposes only. It has been tested internally, however, we do not guarantee that it will work for you. Ensure that you run it in your test environment before using.
Thank you,
Rajasekhar Amudala
Email: br8dba@gmail.com
Linkedin: https://www.linkedin.com/in/rajasekhar-amudala/