In this PostgreSQL tutorial, we will learn how to uninstall PostgreSQL from different operating systems. The possible reasons for uninstalling PostgreSQL could be the project is complete and you don’t need PostgreSQL, the software is at fault or broken, unable to update the PostgreSQL so want to reinstall with the latest version, etc.
- How to Uninstall PostgreSQL in Ubuntu
- How to uninstall PostgreSQL in Mac using Brew
- How to Uninstall PostgreSQL in Linux
- How to uninstall PostgreSQL in windows 10
How to Uninstall PostgreSQL in Ubuntu
In this section, we will learn how to completely uninstall PostgreSQL from Ubuntu. Ubuntu is the Debian package of Linux. We are using Ubuntu version 20.04 LTS but this method can be used for Ubuntu 16, 18, and 21.
- We are uninstalling PostgreSQL with all of its dependencies from the Ubuntu operating system. The entire process is divided into three parts.
- Uninstall the PostgreSQL application
- Remove dependencies
- Remove Folders
- Remove users (optional)
- To uninstall the PostgreSQL application we will use
purge
command. The Purge command in Linux removes the packages with configuration files.
sudo apt --purge remove postgresql -y

- Before we can remove PostgreSQL dependencies it is important to have a look on all the dependencies. We are calling this process important because even at this stage you can save things before it is gone forever.

- Dependencies can be removed by passing the name of each file mentioned in the above diagram.
- A screen will prompt asking for confirmation simply click enter for yes.
sudo apt-get --purge remove postgresql postgresql-13 postgresql-client-13 postgresql-client-common postgresql-common

- We have to remove three PostgreSQL folders that are present in lib, var and etc folders.
sudo rm -rf /var/lib/postgresql/
sudo rm -rf /var/log/postgresql/
sudo rm -rf /etc/postgresql/
- The last step in the process is to remove the users created in PostgreSQL. By default, we have Postgres user created while installing PostgreSQL. If you have created any other user you can remove it with the same command just by replacing the Postgres with your username.
sudo deluser postgres
Read: PostgreSQL installation on Linux step by step
How to Uninstall PostgreSQL in Mac using Brew
In this section, we will learn how to uninstall PostgreSQL in Mac using Brew. In our blog Install PostgreSQL on Macintosh (Mac) we have shared the installation of PostgreSQL through the PostgreSQL app. So in this section, we’ll see how to remove the PostgreSQL app in Mac.
- The best and easiest way to uninstall PostgreSQL completely from the Mac is by using the
uninstall-postgres.app. - Navigate to the directory /Library/PostgreSQL/13. Here 13 is the version of PostgreSQL installed in your system.
- There you will see a file uninstall-postgres.app, click to open the file.
- The screen will appear with two options, select Entire application and click the Next button.
- On the next screen, select all the checkboxes under the select components to uninstall and click on the Next button.
- PostgreSQL will be uninstalled from the Mac and a confirmation prompt for the same will appear on the screen.
How to Uninstall PostgreSQL in Linux
In this section, we will cover how to uninstall PostgreSQL in Linux. We have covered How to Uninstall PostgreSQL from Debian Package so now we will see how to uninstall PostgreSQL from the RPM package in Linux.
- RPM package include Red Hat, Centos, Fedora, etc. So if you are using one of these then you can follow the commands provided in this section.
- First step towards uninstalling Postgres in Linux is to view the packages and their dependencies. Below mentioned command will list all the packages and dependencies.
rpm -qa | grep postgres

- Last step in the process is to remove the PostgreSQL from Linux. We are removing all the packages with the command.
# remove all the packages
sudo yum remove postgres\*


How to uninstall PostgreSQL in windows 10
In this section, we will learn how to uninstall PostgreSQL in Windows 10. These steps can be followed on Windows 7 and windows 8, 8.1.
- Open Control Panel
- Right-click on the Postgres 13 and select uninstall
- Select the radio button ‘Entire application‘ and click on Next.
- Select all the checkboxes and click on Next.
- A prompt will appear confirming that PostgreSQL has been uninstalled.
You may like the following PostgreSQL tutorials:
- How to connect to PostgreSQL database
- How to create a table in PostgreSQL [Terminal + pgAdmin]
- How to Restart PostgreSQL (Linux, Windows, Mac)
- PostgreSQL CASE with Examples
In this tutorial, we have learned how to uninstall PostgreSQL from different operating systems. Also, we have covered these topics.
- How to Uninstall PostgreSQL in Ubuntu
- How to Uninstall PostgreSQL in Mac using Brew
- How to Uninstall PostgreSQL in Linux
- How to uninstall PostgreSQL in windows 10
I am Bijay having more than 15 years of experience in the Software Industry. During this time, I have worked on MariaDB and used it in a lot of projects. Most of our readers are from the United States, Canada, United Kingdom, Australia, New Zealand, etc.
Want to learn MariaDB? Check out all the articles and tutorials that I wrote on MariaDB. Also, I am a Microsoft MVP.