Friday, March 6, 2015

How to Remove PostgreSQL from Server

At work we have a reporting server that was setup by an employee here who deemed himself the foremost expert at Linux. Needless to say, if you are touting your Linux skills, you had better be able to back them up. Turns out that he wasn't quite up to snuff with his skills, and after following a tutorial he put together for setting up a server, I found myself unsure of what PostgreSQL server I was actually using. Somehow I had both 9.1 and 9.2 running.

I was in the process of cleaning up the reporting server and decided that it would be good to only have one server of PostgreSQL running, so I discovered how to do it. In the process of cleaning it up, I also discovered that the server version you are using stores databases by default in the same parent directory as the server itself is located. In other words, if you follow this tutorial, be aware that you will lose your data if the default storage location had not been changed. Luckily it was data that really didn't need to be kept around for a long time so it wasn't that big of a deal. But be aware that it does destroy data doing this method.

First, run the command

sudo /etc/init.d/postgresql stop

If two versions of the server pop up, then it means you are running two instances of PostgreSQL. Decide which one you want to remove and then run the following command:

sudo apt-get purge postgresql-x.x

where the x.x stands for the major.minor version number.

If you are purging a server from multiple different servers being used, then you will need to restart the server:

sudo /etc/init.d/postgresql start

The server is now up and running and ready to be used.

No comments:

Post a Comment