postgres 卸载失败

postgres 卸载失败

尝试卸载 postgresql 时

sudo apt-get remove postgresql

我收到以下错误消息

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)

当我尝试清除 postgres 时也发生了同样的情况,这里发生了什么,我该如何正确地删除 postgres?

答案1

你的问题

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

我的解决方案

捷径

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

或者很长的路要走

  • 打开文件/var/lib/dpkg/info/postgresql-common.postinst

    sudo nano /var/lib/dpkg/info/postgresql-common.postinst
    
  • 使用启动命令搜索该行:

    if [ -x "/etc/init.d/postgresql" ] || [ -e "/etc/init/postgresql.conf" ]; then
            invoke-rc.d postgresql start || exit $?
    fi
    
  • 注释掉该块

    # if [ -x "/etc/init.d/postgresql" ] || [ -e "/etc/init/postgresql.conf" ]; then
    #        invoke-rc.d postgresql start || exit $?
    # fi
    
  • 再次移除包裹。

    sudo apt-get remove postgresql
    

解释

在删除期间postgresql,将调用该脚本postgresql-common.postinst。该脚本尝试启动服务postgresql,但会失败invoke-rc.d postgresql start(不要问我为什么)。

必须防止这种情况发生。要么通过改变代码执行的条件。要么通过删除代码本身。

相关内容