How to Uninstall PostgreSQL (Linux, Mac, and Windows)

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.

  1. How to Uninstall PostgreSQL in Ubuntu
  2. How to uninstall PostgreSQL in Mac using Brew
  3. How to Uninstall PostgreSQL in Linux
  4. 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
uninstall PostgreSQL in Ubuntu
Uninstall PostgreSQL
  • 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.
How to Uninstall PostgreSQL
Dependencies of PostgreSQL
  • 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 
How to Uninstall PostgreSQL in Ubuntu
Removing dependencies
  • 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
How to Uninstall PostgreSQL in Mac using Brew
View PostgreSQL packages and dependencies
  • 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\*
uninstall postgres from rpm package in linux
Uninstalling PostgreSQL from RPM package in Linux
Postgresql uninstallation completed in rpm package of Linux
PostgreSQL uninstall completed


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:

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

Leave a Comment