Can't uninstall postgresql package due failing to start service?

Solution 1:

Your first installation was kept uncertain, this will nuke it:

sudo dpkg --purge postgresql-9.1

Now you can reinstall the package:

sudo apt-get -f install
sudo apt-get install postgresql-9.1

Solution 2:

I managed to purge postgres (apt-get purge) by purging 2 other packages first: the contrib package and the postgresql package (seems to be a small 'virtual' package). At least, that is what I think...

Then I could purge the postgresql-9.1 package (around 11 MB)

Solution 3:

I had a similar problem and solved it using aptitude to completely remove the previous installation (apt-get didn't remove all the dependencies).

Next, I'm proving a description on how to do it in a shell terminal (GUI is out of scope in this answer).

Start by launching interactive package manager:

sudo aptitude

A friendly text only user interface will opens. You can use the keyboard Up and Down to navigate and Enter to open items. The mouse can also be used to navigate.

You'll see a top menu (Actions / Undo / ...) from where you can command aptitude. Without a mouse, press CTRL+T to open the menu. The menus also show the keyboard shortcuts you can use.

If you know what to remove, go to Installed Packages and navigate to the package. For example, to remove PostgreSQL, go Installed Packages \ main and you'll see the postgresql* packages. The installed packages have the letter i at its left hand side. Use, for example, the Down key to highlight the first package and press the - key to mark it for removal. You can undo the action through the Undo menu or by pressing the + key.

Notice that by pressing the + key in a uninstalled packaged it will be marked for installation.

When all the packages you want to remove are marked for removal, go to the Actions menu and choose the command Install/remove packages. It'll show a preview of what will be done. Broken packages and not used packages will also be automatically selected. Use the + and - keys to add/keep or remove the packages. Notice the change of color to reflect the action (magenta = remove package, green=install package).

When you are happy with the selection, go again to the Actions menu and choose the command Install/remove packages to perform the action.

After it finishes, press Enter to return to the user interface. You can search packages (see the Search Menu, where the keyboard shortcuts are also displayed).

Press the ? key for an on-line help.

Press the q to quit.