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 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.
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:
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 postgresql@9.5-main.service I get:

   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*":

| 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)
  • 1
    please post dpkg -l "postgresql*" to check what's leftover. – ubfan1 Jan 17 '17 at 22:30
  • 1
    I use the same package with 14.04 successfully and it doesn't use systemd (which is not even installed) to start. I suspect that you have parts of systemd installed, so that the postgresql package tries to use it and fails. – Daniel Vérité Jan 19 '17 at 17:45

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)
    ERRMSG=$(pg_ctlcluster "$2" "$name" $1 2>&1)

/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)
    ERRMSG=$(pg_ctlcluster --skip-systemctl-redirect "$2" "$name" $1 2>&1)

Or you can add $skip_systemctl_redirect = 1; before $skip_systemctl_redirect is checked in /usr/bin/pg_ctlcluster.

  • 2
    As far as I know, Ubuntu 14.04 is not using systemd – Zanna Jan 29 '17 at 8:43
  • @Zanna Well, I did investigate my server which has systemd installed. The main dependency was "upower" and I managed to removed all unnecessary packages dependant of "upower". Everything goes fine again. – Rui Andrada Apr 5 '17 at 3:03

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


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",

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:

  1. Switch back to upstart for init management
  2. Write your own systemd startup script for postgresql-9.5

...and I'm out of ideas ;)

  • I don't quite understand those links relate to this issue. The download instructions for Ubuntu recommend deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main. Is there some way to infer that it is pulling from that pool/9.5/p/postgresql-9.5/ directory when trying to install postgresql-9.5? I did try installing postgresql-9.6 after uninstalling everything else and unfortunately it didn't get any further. – Shaun Jan 18 '17 at 4:34
  • The repository contains a bunch of different files for various different purposes. The actual deb packages themselves sit in the pool/ dir under the http:// url part that you posted (try going there with a web browser). Is there any reason you're not using the postgresql packages provided by ubuntu/canonical themselves? – cleary Jan 18 '17 at 21:55
  • Thank you for the clarification. The Ubuntu 14.04 repositories don't contain the latest PostgreSQL version, I don't remember which one they are on, but we need at least 9.4 for some of the extensions we are using. – Shaun Jan 19 '17 at 16:48
  • ok, I was completely mistaken, it looks like that repo may be a bit of a mess. There's a main/ subdir and there's 9.5 packages under there. I tried installing them here and it went through fine. Updated my post with new information - – cleary Jan 24 '17 at 22:41
  • Thanks for looking into it some more. I couldn't figure out how to repair postgresql so we just cloned a similar VM and will rebuild from that. I will have to run through the 12.04 to 14.04 upgrade again, so I'll try to keep track of the upgrade log and identify things related to systemd or postgresql. This seems like the most probable answer, I'll post any new information if I learn anything from the logs. – Shaun Jan 25 '17 at 1:42

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 
9.5 main    5433 down   postgres /var/lib/postgresql/9.5/main 
9.6 main    5434 down   postgres /var/lib/postgresql/9.6/main 

Trying to start postgresql keep showing:

sudo pg_ctlcluster 9.4 main start
Redirecting start request to systemctl
Failed to issue method call: Unit postgresql@9.4-main.service failed to load: No such file or directory. See system logs and 'systemctl status postgresql@9.4-main.service' 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.