Categories: Ubuntu

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.

Table of Contents

Toggle

Prerequisites:

To perform the steps in this guide, you need the following components:

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:

$ apt list –installed | grep 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:

$ sudo apt autoremove –purge postgresql*

Here,

Sponsored
  • 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:

$ apt list –installed | grep postgresql-[09]

Here,

  • 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:

$ sudo apt remove postgresql-<version> postgresql-client-<version>

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.

Ubuntu Server Admin

Recent Posts

Canonical announces 12 year Kubernetes LTS

Canonical’s Kubernetes LTS (Long Term Support) will support FedRAMP compliance and receive at least 12…

19 hours ago

Ubuntu Weekly Newsletter Issue 878

Welcome to the Ubuntu Weekly Newsletter, Issue 878 for the week of February 2 –…

2 days ago

How your feedback shapes the way we support open source software

At Canonical, we firmly believe that delivering an outstanding, customer-centric support experience is impossible without…

2 days ago

How To Install osTicket v1.14 On Ubuntu 20.04

I want to share how to install osTicket v1.14 for Ubuntu 20.04 server. osTicket written…

3 days ago

How To Install WordPress On Ubuntu 20.04

Now I want to share how to install WordPress on ubuntu 20.04 server. WordPress is…

3 days ago

How To Install DNS Server (Bind9) On Ubuntu 20.04

Now I want to share the DNS server installation process on your Ubuntu 20.04 server.…

3 days ago