Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I simply don't understand what's going on.

sudo apt-get remove postgresql

results in:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'postgresql' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 35 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up postgresql-9.1 (9.1.10-0ubuntu13.04) ...
 * Starting PostgreSQL 9.1 database server                                                                                                                                                            * The PostgreSQL server failed to start. Please check the log output:
2013-11-05 12:40:58 PST FATAL:  could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": Permission denied
invoke-rc.d: initscript postgresql, action "start" failed.
dpkg: error processing postgresql-9.1 (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
E: Sub-process /usr/bin/dpkg returned an error code (1)

I mean, why is it trying to start the server. Right I'm a bit of a unix noob and a huge postgres noob so bear with me, but randomly starting the server while I'm trying to uninstall it seems so random. Just don't get it.

How can I completely and utterly uninstall postgresql?

share|improve this question
up vote 8 down vote accepted

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
share|improve this answer
Ah yes, I think that got it! you know if there are any lingering dependencies or anything regarding postgres? Also, what have I don't wrong, and what does the dpkg command do in this context? – Starkers Nov 5 '13 at 21:03
@Starkers the dependencies problems (if any) are being take care off by sudo apt-get -f install as I wrote in my answer. I don't understand the second question, and dpkg just purge the package directly. – Braiam Nov 5 '13 at 21:08
Okay, cool. What do you mean exactly by first installation kept uncertain? – Starkers Nov 5 '13 at 21:18
The package wasn't either installed or removed, something in between. – Braiam Nov 5 '13 at 21:26

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)

share|improve this answer

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.

share|improve this answer
Although your answer is 100% correct, it's also 100% useless for a beginning user who doesn't know the difference between a terminal and a GUI. :-( Therefore, please edit your answer, and add the relevant steps needed into your answer, thereby guaranteeing your answer to be useful to 100% of our users. – Fabby Feb 25 '15 at 21:23
Sure, you're right. It's updated now. – bitcraft Feb 26 '15 at 22:44
Fantastic answer now! (and an upvote!) ;-) – Fabby Feb 27 '15 at 11:37
Thanks. One is glad to be of service :) – bitcraft Feb 27 '15 at 19:43

Probably your install or deinstall was interrupted recently, leaving the packetsystem in an uncertain state.

sudo apt-get clean && sudo apt-get autoremove 

sudo apt-get -f install

sudo dpkg --configure -a

this should fix it

share|improve this answer
sudo apt-get clean && sudo apt-get autoremove results in the same error..trying to start the server, can't start the server because I don't have permission, even though it's a sudo command. Really weird and annoying – Starkers Nov 5 '13 at 20:54
try only the "sudo apt-get -f install" then, and let me know what it returns – thom Nov 5 '13 at 20:58

I had the same problem, and it turned out to be a permissions issue with /var/run/postgresql. It was owned by root but needed to be owned by postgres

sudo chown -R postgres:postgres /var/run/postgresql solved it, followed up with sudo service postgresql restart

Thanks to

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.