How do I reinstall PostgreSQL 9.5 on Ubuntu Xenial (16.04.1)?

I've experimented with PostgreSQL config files on my workstation and then decided to revert them to the initial state by reinstalling the package. I've deleted the entire config directory for PostgreSQL (rm -Rf /etc/postgresql), then uninstalled all the PostgreSQL packages.

Now, when I do sudo apt-get install postgresql, it gets installed, but /etc/postgresql directory is not re-created and I can't start the server.

What's gone wrong and how do I re-install PostgreSQL completely from scratch?

1 Answer

I've finally managed to resolve the problem. The installer failed to create a config, because the previous data directory was present (it's not deleted by the uninstall command).

So, in order to completely reinstall the PostgreSQL do the following:

  • sudo apt-get --purge remove postgresql-*
  • sudo rm -Rf /etc/postgresql /var/lib/postgresql
  • sudo apt-get install postgresql

It should install the shiny new cluster for you with clean data and config files.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like