Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

3 Answers 3

up vote 4 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! Thanks..do 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

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 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

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.