Uninstall an specific version of PostgreSQL

I have Postgresql 9.1.1 in my Ubuntu 12.04 which got installed due to automatic upgrades and whenever I uninstall it using the command:

sudo apt-get --purge remove postgresql-9.1.1

I get an error saying:

E: Unable to locate package postgresql-9.1.1
E: Couldn't find any package by regex 'postgresql-9.1.1

Can somebody tell me how to uninstall this package completely so that I can install the other lower version - 8.4.7


Solution 1:

The version 9.1.1 of PostgerSQL is located in the package postgresql-9.1. So you should remove this package:

sudo apt-get purge postgresql-9.1

The second part of your question is already answered here: How do I downgrade PostgreSQL?

Solution 2:

If you want to uninstall postgresql and any related package, you should use autoremove:

sudo apt-get --purge autoremove postgresql*

This will select any package starting with postgresql and remove any automatic dependency that these packages installed efectivelly removing any version of postgresql. If you only want to remove the client or the server, your bet should be on apt-cache search postgresql | grep client or server.

Solution 3:

Try:

sudo apt-get --purge remove postgresql-9.1

Also you can install 8.4.7 and stop the server postgresql-9.1.