ubuntu machine had postgresql folder blown away manually - can't install or remove any packages

Solution 1:

Have you tried to just purge the packages left from the failed removal attempt manually?

sudo apt-get purge postgresql-client-9.4 postgresql-client-common postgresql-common

Then:

sudo apt-get update install postgresql

The removal obviously fails because postgresql is not installed, but the reinstallation might be failing because something is wrong with what has been left from the previous installation.

Solution 2:

In the plethora of attempts to delete using aptitude and also apt-get remove/purge, I was getting a message that it couldn't delete postgresql-9.3 because the directories /var/lib/postgresql and /var/log/postgresql were not empty.

So I blew them away and then did the sudo apt-get purge... which sort of worked. And then I did aptitude purge and it worked.

Now I can install packages again on this box without errors.