I have done

sudo apt-get remove postgresql-9.4

and then

sudo apt-get install postgesql-9.5 

but I still saw that the service 'postgresql-9.4' was starting at boot in systemctl. Then I tried to play around with the .service files and I must have messed something up because now I see that this service now has status Failed in journalctl. Also, now my Rails app that use Postgres 9.5 by default want to listen on port 5432 however this port is taken by the old installation of Postgres 9.4 so they fail to start. I could fix it in the app config and give them port 5433 but it might be a cumbersome to do this with every app so I should fix this on system level. How do I fix this?

I have this in my journalctl:

Home systemd[1]: Failed to start PostgreSQL Cluster 9.4-main.
Home /usr/lib/snapd/snapd[1210]: snapmgr.go:411: Cannot prepare auto-refresh change: Post https://search.apps.ubuntu.com/api/v1/snaps/metadata: dial tcp: lookup search.apps.ubuntu.com o
Home systemd[1]: [email protected]: Unit entered failed state.
Home /usr/lib/snapd/snapd[1210]: stateengine.go:98: state ensure error: Post https://search.apps.ubuntu.com/api/v1/snaps/metadata: dial tcp: lookup search.apps.ubuntu.com on [::1]:53: r
Home systemd[1]: [email protected]: Failed with result 'exit-code'.
  • postgresql.service comes from postgresql-common, so remove that.
    – muru
    Sep 19, 2017 at 15:53
  • @muru I removed the folder but the Exited service is still there. Any other ideas?
    – jedi
    Sep 20, 2017 at 17:30

1 Answer 1


Presuming you'd already backed up any 9.4 databases, a "purge" instead of the "remove" would have gotten rid of the /etc/postgresql/9.4/main/postgresql.conf file with the "port=5432" line. Since it still existed when you did the 9.5 install, the install used the next port, 5433. Generally, this is done to allow a later version of postgresql to be installed, and checked out, before deleting the old version.

You can edit the /etc/postgresql/9.5/main/postgresql.conf file port to be 5432 and redo the apt-get purge postgresql-9.4 to clean up the old config files.

You can track down any leftover 9.4 files with locate

locate postgresql/9.4 

and remove them manually to keep systemd fromt trying to start the no-longer present service.

  • I have already done "purge" but still see 9.4 is systemctl services so "purge" did not got rid of everything.
    – jedi
    Sep 19, 2017 at 7:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .