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

25,369

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.

Share:
25,369

Related videos on Youtube

Slava Fomin II
Author by

Slava Fomin II

Updated on September 18, 2022

Comments

  • Slava Fomin II
    Slava Fomin II over 1 year

    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?

  • rho
    rho over 2 years
    if so frustrated with ubuntu, if it was'nt my server i would have removed it completely.