ubuntu 机器的 postgresql 文件夹手动被删除了 - 无法安装或删除任何软件包

ubuntu 机器的 postgresql 文件夹手动被删除了 - 无法安装或删除任何软件包

我有一台机器,其中用户从命令行删除了他们的 postgresql 文件夹以尝试卸载 postgres。现在,当我们尝试安装任何其他软件包 - 即使是不相关的软件包 - 我们不断收到有关 postgresql-common 的错误消息。

我尝试通过命令行手动卸载与 postgresql-9.3 和 postgresql-9.4 相关的所有内容,但这不起作用。

当我尝试时,会发生以下情况:

jj@testdev:~/Documents/svc_core_design/svc_core_git/svc-core-docs/net-svc$ sudo apt-get purge postgresql-client-9.3
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'postgresql-client-9.3' is not installed, so not removed
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 postgresql-9.3 : Depends: postgresql-client-9.3 but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
jj@testdev:~/Documents/svc_core_design/svc_core_git/svc-core-docs/net-svc$ 

为了查看他还有哪些 postgresql 组件,我运行了以下命令:

sudo dpkg --get-selections | grep -v deinstall

postgresql-9.3                                  purge
postgresql-client-9.4                           install
postgresql-client-common                        install
postgresql-common                               install

如果可能的话,我想删除所有与 postgresql 相关的项目,或者重新安装以使其正常工作。(如果我们重新安装,则不需要两个版本。只需 9.4 就可以了。)你能告诉我如何通过命令行执行此操作吗?

编辑1

以下是尝试运行不带任何包名称的“sudo apt-get -f install”的结果:

jj@testdev:/var/lib/postgresql$ sudo apt-get -f install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libjs-underscore linux-image-3.16.0-25-generic linux-image-3.16.0-33-generic linux-image-extra-3.16.0-25-generic linux-image-extra-3.16.0-33-generic
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up postgresql-common (166.pgdg14.10+1) ...
insserv: warning: script 'mongod' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `mongod'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `mongod'
 * Starting PostgreSQL 9.3 database server                                                                                                                                                                                                 * Error: /var/lib/postgresql/9.3/main is not accessible or does not exist
                                                                                                                                                                                                                                   [fail]
 * Starting PostgreSQL 9.4 database server                                                                                                                                                                                                 * Error: /var/lib/postgresql/9.4/main is not accessible or does not exist
                                                                                                                                                                                                                                   [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
Errors were encountered while processing:
 postgresql-common
E: Sub-process /usr/bin/dpkg returned an error code (1)
jj@testdev:/var/lib/postgresql$ sudo 

我还确保 /var/lib/postgresql 文件夹的所有者是 postgres,以防万一。也许我应该手动创建它抱怨的文件夹结构?

  /var/lib/postgresql/9.3/main

还有其他建议吗?

编辑2

我安装了 aptitude 并尝试清除 postgresql 9.3 和 9.4 但失败了:

jj@testdev:/var/lib/postgresql$ sudo aptitude purge postgresql-9.3
The following packages will be REMOVED:  
  postgresql-9.3{p} 
The following partially installed packages will be configured:
  postgresql-common 
0 packages upgraded, 0 newly installed, 1 to remove and 5 not upgraded.
Need to get 0 B of archives. After unpacking 17.6 MB will be freed.
Do you want to continue? [Y/n/?] Y
(Reading database ... 339475 files and directories currently installed.)
Removing postgresql-9.3 (9.3.5-2.pgdg14.10+1) ...
 * Stopping PostgreSQL 9.3 database server                                                                                                                                                                                     * Error: /var/lib/postgresql/9.3/main is not accessible or does not exist
                                                                                                                                                                                                                       [fail]
invoke-rc.d: initscript postgresql, action "stop" failed.
dpkg: error processing package postgresql-9.3 (--purge):
 subprocess installed pre-removal script returned error exit status 1
Errors were encountered while processing:
 postgresql-9.3
E: Sub-process /usr/bin/dpkg returned an error code (1)
Failed to perform requested operation on package.  Trying to recover:
Setting up postgresql-common (166.pgdg14.10+1) ...
 * Starting PostgreSQL 9.3 database server                                                                                                                                                                                     * Error: /var/lib/postgresql/9.3/main is not accessible or does not exist
                                                                                                                                                                                                                       [fail]
 * Starting PostgreSQL 9.4 database server                                                                                                                                                                                     * Error: /var/lib/postgresql/9.4/main is not accessible or does not exist
                                                                                                                                                                                                                       [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
Errors were encountered while processing:
 postgresql-common

jj@testdev:/var/lib/postgresql$ 

编辑3:

以下是运行命令“sudo apt-get purge postgresql-client-9.4 postgresql-client-common postgresql-common”的结果

Removing postgresql-common (166.pgdg14.10+1) ...
 * Stopping PostgreSQL 9.3 database server                                                                                                                                                                                     * Error: /var/lib/postgresql/9.3/main is not accessible or does not exist
                                                                                                                                                                                                                       [fail]
 * Stopping PostgreSQL 9.4 database server                                                                                                                                                                                     * Error: /var/lib/postgresql/9.4/main is not accessible or does not exist
                                                                                                                                                                                                                       [fail]
invoke-rc.d: initscript postgresql, action "stop" failed.
dpkg: error processing package postgresql-common (--purge):
 subprocess installed pre-removal script returned error exit status 1
 * Starting PostgreSQL 9.3 database server                                                                                                                                                                                     * Error: /var/lib/postgresql/9.3/main is not accessible or does not exist
                                                                                                                                                                                                                       [fail]
 * Starting PostgreSQL 9.4 database server                                                                                                                                                                                     * Error: /var/lib/postgresql/9.4/main is not accessible or does not exist
                                                                                                                                                                                                                       [fail]
invoke-rc.d: initscript postgresql, action "start" failed.
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 1

当我检查安装了什么时:

jj@testdev:/var/lib/postgresql$ sudo dpkg --get-selections | grep -v deinstall | grep post
libreoffice-sdbc-postgresql         install
postgresql-9.3                  purge
postgresql-9.4                  purge
postgresql-common               purge
printer-driver-postscript-hp            install
jj@testdev:/var/lib/postgresql$ 

答案1

您是否尝试过手动清除删除失败后留下的软件包?

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

然后:

sudo apt-get update install postgresql

删除显然会失败,因为postgresql没有安装,但重新安装可能会失败,因为上次安装留下的内容有问题。

答案2

在多次尝试使用aptitude和删除时apt-get remove/purge,我收到一条消息,提示无法删除,postgresql-9.3因为目录/var/lib/postgresql/var/log/postgresql不为空。

于是我把它们吹走了,然后做了sudo apt-get purge……这有点奏效。然后我就这么做了,aptitude purge而且成功了。

现在我可以在此盒子上再次安装软件包而不会出现错误。

答案3

我遇到这个问题是使用 查找所有 postgresql 文件夹whereis postgresql然后手动删除它们。但是当我需要使用 重新安装 postgresqlapt-get install postrgesql-10或执行简单的时apt-get upgrade,我得到了以下错误:

无法打开 /usr/share/postgresql-common/maintscripts-functions

我所做的是从他们的 Github 仓库复制实际文件这里并将其放置在该位置。然后我执行了以下步骤:

  • dpkg -l | grep postgresql- 列出已安装的软件包。这将显示如下结果此截图

  • 使用上述结果中的包名称并将其删除 -sudo apt-get remove <PACKAGE>

  • 接下来,使用以下命令删除所有剩余的包sudo apt-get autoremove

此后重新启动您的机器一次,您就可以开始了!

答案4

此命令将为您提供所有已安装的 postgres 包。

sudo apt list --install | grep postgres

我也遇到了上述问题,但此命令帮助我卸载了所有以前的版本

sudo apt-get autoremove postgresql*

相关内容