Occasionally, during software installation, interruptions or incomplete downloads can occur, leaving you with partial files and empty directories. In such cases, you may need to completely uninstall recently installed software. This tutorial provides a step-by-step guide on safely removing PostgreSQL from an Ubuntu 16.04 server.
Important: Backup First
Before initiating the uninstallation process, it is crucial to back up any databases you may need to prevent data loss.
How to Remove PostgreSQL
-
Step 1: List the PostgreSQL Packages
Use the dpkg tool to list the packages associated with the PostgreSQL setup:
dpkg -l | grep postgresThis command will display all PostgreSQL-related packages installed on your system.
-
Step 2: Uninstall PostgreSQL Packages
Building on the package list obtained in Step 1, you can efficiently remove all associated software packages with a single command. Utilize the
apt-get --purge removecommand followed by the names of each identified package separated by a space.For example, if you have the following installed packages:
- pgdg-keyring
- postgresql-10
- postgresql-client-10
- postgresql-client-common
- postgresql-common
The purge remove command would appear as follows:
sudo apt-get --purge remove pgdg-keyring postgresql-10 postgresql-client-10 postgresql-client-common postgresql-common -
Step 3: Verify PostgreSQL Deletion
After executing the removal command, attempting to access the PostgreSQL environment should be unsuccessful. Confirm this by rerunning the
dpkg -l | grep postgrescommand and searching for 'postgres.'If the uninstallation was successful, there should be no output from the command, indicating that PostgreSQL has been completely removed.