- Linux полное удаление postgresql
- How to Uninstall PostgreSQL (Linux, Mac, and Windows)
- 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 the postgresql
- Uninstall the PostgreSQL on Ubuntu 22.04
- Prerequisites:
- Conclusion
- About the author
- Sidratul Muntaha
Linux полное удаление postgresql
PostgreSQL is among the most popular open-source relational databases that provide a wide range of advantages, including security, stability, extensibility, etc. Users can safely store vast amount of complex data using Postgres. However, when PostgreSQL is no longer needed, you can uninstall it from your Ubuntu operating system.
This blog post will demonstrate how to uninstall Postgres completely from the ubuntu operating system. So, let’s get started!
How to Uninstall Postgres From Ubuntu?
PostgreSQL may need to be uninstalled from a system at some point for various reasons, such as cleaning up the disk space, not needing it anymore, etc. So it’s crucial to understand how to uninstall the PostgreSQL database completely(along with its dependent packages) from your system.
Uninstalling Postgres from Ubuntu can be done using various ways. In this write-up, we are going to discuss a couple of them!
Method 1: Using ‘sudo apt remove postgresql’
This section describes the simplest way of uninstalling Postgres from ubuntu. For that purpose, follow the steps provided below:
Step 1: Uninstall Postgres
To uninstall Postgres from your Ubuntu operating system, open the terminal and run the command below:
sudo apt remove postgresql postgresql-contrib
The above snippet demonstrates that Postgres has been removed from Ubuntu.
Step 2: Uninstall Dependent Packages
Some additional(dependent) packages are automatically installed on Ubuntu when you install Postgres. However, when you remove Postgres from ubuntu, these dependent/additional packages are no longer needed. So, to uninstall these dependent packages, the below-mentioned command is used in ubuntu:
Type “y” and hit the “Enter” button to remove Postgres from Ubuntu:
The whole process will take some time to remove Postgres and its dependent packages completely from ubuntu.
Method 2: Using ‘purge remove postgresql’
If the above method is not working for some reasons, then nothing to worry about! We have explained another very convenient method to uninstall Postgres from your Ubuntu operating system.
Step 1: List Postgres Packages
Run the below-provided command to see the list of Postgres packages currently installed on your ubuntu operating system:
The above snippet shows the list of Postgres packages installed on our machine.
Step 2: Uninstall Postgres
Remove Postgres from your system by running the remove purge command followed by the name of all the packages related to Postgres:
sudo apt-get –purge remove postgresql postgresql-14 postgresql-client-common postgresql-common postgresql-contrib
Type “y” and hit the “Enter” button to continue the uninstallation process of Postgres:
The following window will appear during the uninstallation, asking you to remove Postgres directories when the package is purged:
Hit the “Yes” button, and it will take a few minutes to complete the uninstallation.
Step 3: Verify Uninstallation
Let’s execute the below statement one more time to verify the uninstallation of Postgres from ubuntu:
The above snippet proves that postgres has been uninstalled completely from Ubuntu.
That’s all from this Postgres guide!
To uninstall Postgres from your Ubuntu operating system, open the terminal and run the “sudo apt remove postgresql postgresql-contrib” command. To uninstall the dependent packages from the ubuntu operating system, use the “sudo apt autoremove” command. Another way of removing postgres from ubuntu is by using the “sudo apt-get –purge remove” command followed by the name of packages to be removed. Through practical demonstration, this Postgres blog has explained how to uninstall PostgreSQL from the ubuntu operating system.
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.
- 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)
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.
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.
- 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:
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.
How to uninstall the postgresql
The simplest way to do this is open a terminal and type:
sudo apt-get --purge remove postgresql
This will remove the postgresql package. There may be chances that additional packages are also installed so you can search them by typing:
and purge all those packages by sudo apt-get —purge remove .
Thanks! But still i got some left. Is there a possible way i can delete the postgresql «folder by folder»
To completely uninstall PostgreSQL
sudo apt-get purge postgres.*
I just want to add that any packages installed using apt, apt-get or from .deb files for example, can be uninstalled using:
sudo apt-get purge package_name.*
List package and all of its dependencies to check what are being uninstalled:
dpkg --list | grep package_name.*
.* after package_name is very important to regex match all possible dependencies associated with a package.
To completely remove Postgres with dependent packages, I used the following commands on my Ubuntu 20.04.
First check the postgres installed version
dpkg -l | grep postgresThen use the following command to remove all dependencies. Use your version number.
$ sudo apt-get --purge remove postgresql-12 postgresql-client-12 postgresql-client-common postgresql-common
Uninstall the PostgreSQL on Ubuntu 22.04
PostgreSQL is one of the most popular database management systems. It’s a free and open-source software which is renowned for stability, performance, scalability, and security. Many applications and programming languages (Python, JavaScript, Ruby, C/C++, and more) support the PostgreSQL integration. Learn more about PostgreSQL.
In this guide, we will take a quick look at removing the PostgreSQL on Ubuntu 22.04.
Prerequisites:
To perform the steps in this guide, you need the following components:
- A properly-configured Ubuntu system. Learn more about installing Ubuntu 22.04.
- A proper installation of PostgreSQL. Learn more about installing PostgreSQL properly on Ubuntu 22.04.
- Access to a non-root user with sudo Learn more about managing sudo privilege on Ubuntu.
Step 1: Finding the Installed PostgreSQL Packages
The default method of installing PostgreSQL on Ubuntu is through the APT package manager. The package source can be either the official Ubuntu package repo or the official PostgreSQL APT repo.
First, we check the list of installed packages that contains the term, postgres:
Step 2: Uninstalling PostgreSQL Altogether
Notice that all the packages that are related to PostgreSQL start with the term, postgresql. Using this pattern, we can specify what packages to uninstall to the APT package manager.
Using the following command, we can easily remove all the PostgreSQL packages:
- The APT package manager uninstalls any installed package that matches the described pattern.
- All the associated dependency packages that are no longer used are also uninstalled at the same time.
Note that it removes all the installed versions of PostgreSQL. If you want to remove a specific version of PostgreSQL, we have to follow a more specific method.
Step 3: Uninstalling a Specific Version
Certain cluster setups may utilize multiple versions of PostgreSQL for compatibility reasons. In such an environment, removing all the PostgreSQL packages may not be suitable. In that case, we can remove a specific version of PostgreSQL.
By checking the list of installed PostgreSQL packages, we can easily determine the versions that are currently installed:
- We grab the list of installed packages from APT.
- The output is piped to grep and is filtered using the regular expression.
For reference, the release notes page lists all the available versions of PostgreSQL.
Now that we have a target, we can uninstall it using the following command:
Conclusion
We explored the various ways of uninstalling PostgreSQL on Ubuntu. We demonstrated on how to uninstall a specific version as well as uninstall PostgreSQL altogether from the system.
Interested in learning more about PostgreSQL? If you intend to use multiple versions of PostgreSQL on the same machine, you have to assign different ports for each database server. It’s also possible to integrate the PostgreSQL in Java apps using JDBC.
About the author
Sidratul Muntaha
Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.