2

while trying to uninstall postgresql with

sudo apt-get remove postgresql

I received the following error message

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'postgresql' is not installed, so not removed
The following packages were automatically installed and are no longer required:
  account-plugin-windows-live libupstart1
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 17 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up postgresql-common (154ubuntu1) ...
 * Starting PostgreSQL 9.3 database server                                                                                                       * The PostgreSQL server failed to start. Please check the log output:
2015-07-08 11:16:50 PDT FATAL:  could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": Permission denied
                                                                                                                                         [fail]
invoke-rc.d: initscript postgresql, action "start" failed.
dpkg: error processing package postgresql-common (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of postgresql-9.3:
 postgresql-9.3 depends on postgresql-common (>= 142~); however:
  Package postgresql-common is not configured yet.

dpkg: error processing package postgresql-9.3 (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 postgresql-common
 postgresql-9.3
E: Sub-process /usr/bin/dpkg returned an error code (1)

the same happens when I try to purge postgres, what is happening here and how can I properly remove postgres?

1 Answer 1

2

Your problem

invoke-rc.d: initscript postgresql, action "start" failed.
dpkg: error processing package postgresql-common (--configure):
 subprocess installed post-installation script returned error exit status 1

My solution

the Short way

sudo rm /etc/init.d/postgresql
sudo rm /etc/init/postgresql.conf
sudo apt-get remove postgresql

or the Long way

  • Open the file /var/lib/dpkg/info/postgresql-common.postinst

    sudo nano /var/lib/dpkg/info/postgresql-common.postinst
    
  • Search the line with the start command:

    if [ -x "/etc/init.d/postgresql" ] || [ -e "/etc/init/postgresql.conf" ]; then
            invoke-rc.d postgresql start || exit $?
    fi
    
  • comment the block out

    # if [ -x "/etc/init.d/postgresql" ] || [ -e "/etc/init/postgresql.conf" ]; then
    #        invoke-rc.d postgresql start || exit $?
    # fi
    
  • Remove the package again.

    sudo apt-get remove postgresql
    

Explanation

During the removal of the postgresql, the script postgresql-common.postinst is called. The script tries to start the service postgresql and will fail invoke-rc.d postgresql start (ask me not why).

This must be prevented. Either by changing the conditions by which the code is executed. Or by the removal of the code itself.

2
  • the short version worked perfectly for me thanks!
    – TCulos
    Jul 8, 2015 at 19:09
  • @TCulos I have added the block Explanation at the end of my answer.
    – A.B.
    Jul 8, 2015 at 19:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .