PostgreSQL fails to reinstall after upgrading Ubuntu 12.04 to 14.04
I ran do-release-upgrade
to update an Ubuntu 12.04 server to Ubuntu 14.04. It seemed to go smoothly, but when I did apt-get update
after the upgrade I notice the PostgreSQL packages were still looking at the precise repos instead of the trusty repos. I followed the instructions here to add the trusty repos and moved the .list
file containing the precise repos to a temporary directory as a backup. After I did that, sudo apt-get upgrade
failed and I was not able to get it to run completely again even after restoring the precise repos. I did not happen to grab the error messages. Since this is a development server and all the data is non-essential, I decided just to re-install PostgreSQL. This repeatedly failed after several attempts to clear out any custom configuration we may have had on the server that I thought might be interfering. I am able to do sudo apt-get install postgresql-common
successfully, but if I try sudo apt-get install postgresql-9.5
it fails with the following:
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 [email protected] failed to load: No such file or directory. See system logs and 'systemctl status [email protected]' 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
If I try systemctl status [email protected]
I get:
[email protected]
Loaded: error (Reason: No such file or directory)
Active: inactive (dead)
The /var/log/postgresql/postgresql-9.5-main.log
log file is empty, so I'm not sure where else to check for logs. After failing to install, I go through the steps here to do a complete uninstallation. I can't tell if this an issue with PostgreSQL or the upgraded server.
UPDATE: The output of 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)
Solution 1:
I had the same problem, upgraded Ubuntu 12.04 to 14.04. Don't know but it also using systemd. While checking /etc/init.d/postgresql
file it uses /usr/share/postgresql-common/init.d-functions
.
This file executes /usr/bin/pg_ctlcluster to start and stop postgresql server.
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
/usr/bin/pg_ctlcluster
file accepts --skip-systemctl-redirect
option to start or stop postgresql without systectl.
So you need to add --skip-systemctl-redirect
in /usr/share/postgresql-common/init.d-functions
in do_ctl_all() function.
So it will look like this.
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
Or you can add $skip_systemctl_redirect = 1;
before $skip_systemctl_redirect
is checked in /usr/bin/pg_ctlcluster
.
Solution 2:
The same issue on Ubuntu upgraded from 12.04 to 14.04
Fixed by adding the line
alias pg_ctlcluster="pg_ctlcluster --skip-systemctl-redirect"
in /usr/share/postgresql-common/init.d-functions
after
init_functions=/lib/lsb/init-functions
in puppet it looks like this
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",
}
Solution 3:
re-edit: Ubuntu 14.04 doesn't use systemd by default for service/init management. For some reason, your install is using systemd (do you know why?), but it should be using upstart with a wrapper for legacy sysV startup scripts.
The postgresql-9.5 package does not provide a systemd startup unit file, instead it provides a sysV script which upstart handles fine (just tested here).
Possible options:
- Switch back to upstart for init management
- Write your own systemd startup script for postgresql-9.5
...and I'm out of ideas ;)
Solution 4:
After search while, I came to this post because my server have multiple versions of Postgresql 9.4, 9.5, 9.6 and got the same behavior.
sudo pg_lsclusters 9.4 main status
Ver Cluster Port Status Owner Data directory Log file
9.4 main 5432 down postgres /var/lib/postgresql/9.4/main
/var/log/postgresql/postgresql-9.4-main.log
9.5 main 5433 down postgres /var/lib/postgresql/9.5/main
/var/log/postgresql/postgresql-9.5-main.log
9.6 main 5434 down postgres /var/lib/postgresql/9.6/main
/var/log/postgresql/postgresql-9.6-main.log
Trying to start postgresql keep showing:
sudo pg_ctlcluster 9.4 main start
Redirecting start request to systemctl
Failed to issue method call: Unit [email protected] failed to load: No such file or directory. See system logs and 'systemctl status [email protected]' for details.
After read all answers, I like more the answer: https://askubuntu.com/a/877472/130195
But if wants to keep systemd
installed which is not fully supported by Ubuntu 14.04 follow that hack.
But I think we don't needs systemd
and I've used aptitude to know whats is demands to install systemd
version 204, on my system was upower
, I don't need upower
either.
Removing anything I don't needed anymore and all three versions of postgresql is working again.
I think just a simple sudo apt-get purge systemd && sudo apt-get autoremove
resolve better the problem by remove systemd
package.
WARNING: Please, be carefully before remove any package, pay attention to what will remove with very carefully.