Let’s say you were trying to download PostgreSQL and you realize that not all of the program downloaded, leaving you with files and directories that are taking up space on your server, and begs the question: How do you completely uninstall PostgreSQL? In this tutorial, we’ll be safely removing PostgreSQL from our Liquid Web Ubuntu 16.04 server.
Step 1: List the PostgreSQL Packages
Use the dpkg tool to list packages pertaining to the PostgreSQL setup.
dpkg -l | grep postgres
Step 2: Delete the PostgreSQL Packages
In Step 1, you’ll see packages to delete and delete them with one command. Start with apt-get –purge remove followed by each package name separated with a space. For my particular version of PostgreSQL my command looks like this:
sudo apt-get --purge remove postgresql-9.5 postgresql-client-9.5 postgresql-client-common postgresql-common postgresql-contrib postgresql-contrib-9.5
Step 3: Verifying the Deletion of PostgreSQL
Once you remove these packages you should no longer be able to enter into the PostgreSQL environment. You can verify that by trying to switch to PostgreSQL default user (postgres) or enter into a database.