将 Ubuntu 12.04 升级到 14.04 后,PostgreSQL 无法重新安装

Sha*_*aun 7 upgrade postgresql 12.04 14.04

我跑着do-release-upgrade将 Ubuntu 12.04 服务器更新到 Ubuntu 14.04。它似乎进行得很顺利,但是当我apt-get update升级后,我注意到 PostgreSQL 包仍在查看精确的存储库而不是可信赖的存储库。我按照此处说明添加了可信赖的存储库,并将.list包含精确存储库的文件移动到临时目录作为备份。在我这样做之后,sudo apt-get upgrade失败了,即使在恢复精确之后我也无法让它再次完全运行回购。我没有碰巧抓住错误消息。由于这是一个开发服务器,所有数据都不是必需的,我决定重新安装 PostgreSQL。在多次尝试清除我们可能在服务器上拥有的我认为可能会干扰的任何自定义配置后,这反复失败。我能够sudo apt-get install postgresql-common成功,但如果我尝试sudo apt-get install postgresql-9.5失败,会出现以下情况:

Setting up postgresql-9.5 (9.5.5-1.pgdg14.04+1) ...
Creating new cluster 9.5/main ...
  config /etc/postgresql/9.5/main
  data   /var/lib/postgresql/9.5/main
  locale en_US.UTF-8
  socket /var/run/postgresql
  port   5432
update-alternatives: using /usr/share/postgresql/9.5/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode
 * Starting PostgreSQL 9.5 database server                                                                                             
 * Failed to issue method call: Unit postgresql@9.5-main.service failed to load: No such file or directory. See system logs and 'systemctl status postgresql@9.5-main.service' for details.
                                                                                                                               [fail]
invoke-rc.d: initscript postgresql, action "start" failed.
dpkg: error processing package postgresql-9.5 (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of postgresql-contrib-9.5:
 postgresql-contrib-9.5 depends on postgresql-9.5 (= 9.5.5-1.pgdg14.04+1); however:
  Package postgresql-9.5 is not configured yet.

dpkg: error processing package postgresql-contrib-9.5 (--configure):
 dependency problems - leaving unconfigured
Setting up sysstat (10.2.0-1) ...
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          update-alternatives: using /usr/bin/sar.sysstat to provide /usr/bin/sar (sar) in auto mode
Processing triggers for libc-bin (2.19-0ubuntu6.9) ...
Errors were encountered while processing:
 postgresql-9.5
 postgresql-contrib-9.5
E: Sub-process /usr/bin/dpkg returned an error code (1)

Jan 17 15:31:31 beta kernel: [    4.029504] systemd-journald[543]: Failed to resolve 'systemd-journal' group: No such process
Run Code Online (Sandbox Code Playgroud)

如果我尝试systemctl status postgresql@9.5-main.service我得到:

postgresql@9.5-main.service
   Loaded: error (Reason: No such file or directory)
   Active: inactive (dead)
Run Code Online (Sandbox Code Playgroud)

/var/log/postgresql/postgresql-9.5-main.log日志文件是空的,所以我不知道还有什么地方检查日志。安装失败后,我会按照此处的步骤进行完全卸载。我不知道这是 PostgreSQL 还是升级后的服务器的问题。

更新:输出dpkg -l "postgresql*"

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                         Version             Architecture        Description
+++-============================-===================-===================-==============================================================
un  postgresql-7.4               <none>              <none>              (no description available)
un  postgresql-8.0               <none>              <none>              (no description available)
un  postgresql-9.1               <none>              <none>              (no description available)
iF  postgresql-9.5               9.5.5-1.pgdg14.04+1 amd64               object-relational SQL database, version 9.5 server
un  postgresql-client            <none>              <none>              (no description available)
ii  postgresql-client-9.5        9.5.5-1.pgdg14.04+1 amd64               front-end programs for PostgreSQL 9.5
ii  postgresql-client-common     178.pgdg14.04+1     all                 manager for multiple PostgreSQL client versions
ii  postgresql-common            178.pgdg14.04+1     all                 PostgreSQL database-cluster manager
iU  postgresql-contrib-9.5       9.5.5-1.pgdg14.04+1 amd64               additional facilities for PostgreSQL
un  postgresql-doc-9.5           <none>              <none>              (no description available)
Run Code Online (Sandbox Code Playgroud)

Shi*_*tya 12

我遇到了同样的问题,将 Ubuntu 12.04 升级到 14.04。不知道,但它也使用 systemd。在检查/etc/init.d/postgresql文件时,它使用/usr/share/postgresql-common/init.d-functions.

该文件执行 /usr/bin/pg_ctlcluster 来启动和停止 postgresql 服务器。

if [ "$1" = "stop" ] || [ "$1" = "restart" ]; then
    ERRMSG=$(pg_ctlcluster --force "$2" "$name" $1 2>&1)
else
    ERRMSG=$(pg_ctlcluster "$2" "$name" $1 2>&1)
fi
Run Code Online (Sandbox Code Playgroud)

/usr/bin/pg_ctlclusterfile 接受--skip-systemctl-redirect在没有systectl 的情况下启动或停止postgresql 的选项。

所以,你需要添加--skip-systemctl-redirect/usr/share/postgresql-common/init.d-functions在do_ctl_all()函数。所以它看起来像这样。

if [ "$1" = "stop" ] || [ "$1" = "restart" ]; then
    ERRMSG=$(pg_ctlcluster --skip-systemctl-redirect --force "$2" "$name" $1 2>&1)
else
    ERRMSG=$(pg_ctlcluster --skip-systemctl-redirect "$2" "$name" $1 2>&1)
fi
Run Code Online (Sandbox Code Playgroud)

或者您可以$skip_systemctl_redirect = 1;$skip_systemctl_redirect签入之前添加/usr/bin/pg_ctlcluster

  • 据我所知,Ubuntu 14.04 没有使用 `systemd` (2认同)

小智 7

Ubuntu 上的相同问题从 12.04 升级到 14.04

通过添加行修复

alias pg_ctlcluster="pg_ctlcluster --skip-systemctl-redirect"
Run Code Online (Sandbox Code Playgroud)

/usr/share/postgresql-common/init.d-functions 之后

init_functions=/lib/lsb/init-functions
Run Code Online (Sandbox Code Playgroud)

在木偶中它看起来像这样

  package { 'postgresql-common': ensure => 'installed' }
  file_line { 'Patch 1 /usr/share/postgresql-common/init.d-functions':
    path => '/usr/share/postgresql-common/init.d-functions',
    line => 'alias pg_ctlcluster="pg_ctlcluster --skip-systemctl-redirect"',
    after => "init_functions=/lib/lsb/init-functions",
  }
Run Code Online (Sandbox Code Playgroud)