How to thoroughly purge and reinstall postgresql on ubuntu? [closed] How to thoroughly purge and reinstall postgresql on ubuntu? [closed] postgresql postgresql

How to thoroughly purge and reinstall postgresql on ubuntu? [closed]


Option A

If your install isn't already damaged, you can drop unwanted PostgreSQL servers ("clusters") using pg_dropcluster. Use that in preference to a full purge and reinstall if you just want to restart with a fresh PostgreSQL instance.

$ pg_lsclustersVer Cluster Port Status Owner    Data directory              Log file11  main    5432 online postgres /var/lib/postgresql/11/main /var/log/postgresql/postgresql-11-main.log$ sudo systemctl stop postgresql@11-main$ sudo pg_dropcluster --stop 11 main$ sudo pg_createcluster --start 11 main

Option B

If you really need to do a full purge and reinstall, first make sure PostgreSQL isn't running. ps -C postgres should show no results.

Now run:

apt-get --purge remove postgresql\*

to remove everything PostgreSQL from your system. Just purging the postgres package isn't enough since it's just an empty meta-package.

Once all PostgreSQL packages have been removed, run:

rm -r /etc/postgresql/rm -r /etc/postgresql-common/rm -r /var/lib/postgresql/userdel -r postgresgroupdel postgres

You should now be able to:

apt-get install postgresql

or for a complete install:

apt-get install postgresql-8.4 postgresql-contrib-8.4 postgresql-doc-8.4


I had a similar situation: I needed to purge postgresql 9.1 on a debian wheezy ( I had previously migrated from 8.4 and I was getting errors ).

What I did:

First, I deleted config and database

$ sudo pg_dropcluster --stop 9.1 main

Then removed postgresql

$ sudo apt-get remove --purge postgresql postgresql-9.1 

and then reinstalled

$ sudo apt-get install postgresql postgresql-9.1

In my case I noticed /etc/postgresql/9.1 was empty, and running service postgresql start returned nothing

So, after more googling I got to this command:

$ sudo pg_createcluster 9.1 main

With that I could start the server, but now I was getting log-related errors. After more searching, I ended up changing permissions to the /var/log/postgresql directory

$ sudo chown root.postgres /var/log/postgresql$ sudo chmod g+wx /var/log/postgresql

That fixed the issue, Hope this helps


Steps that worked for me on Ubuntu 8.04.2 to remove postgres 8.3

  1. List All Postgres related packages

    dpkg -l | grep postgresii  postgresql                            8.3.17-0ubuntu0.8.04.1           object-relational SQL database (latest versiii  postgresql-8.3                        8.3.9-0ubuntu8.04                object-relational SQL database, version 8.3ii  postgresql-client                     8.3.9-0ubuntu8.04                front-end programs for PostgreSQL (latest veii  postgresql-client-8.3                 8.3.9-0ubuntu8.04                front-end programs for PostgreSQL 8.3ii  postgresql-client-common              87ubuntu2                        manager for multiple PostgreSQL client versiii  postgresql-common                     87ubuntu2                        PostgreSQL database-cluster managerii  postgresql-contrib                    8.3.9-0ubuntu8.04                additional facilities for PostgreSQL (latestii  postgresql-contrib-8.3                8.3.9-0ubuntu8.04                additional facilities for PostgreSQL
  2. Remove all above listed

    sudo apt-get --purge remove postgresql postgresql-8.3  postgresql-client  postgresql-client-8.3 postgresql-client-common postgresql-common  postgresql-contrib postgresql-contrib-8.3
  3. Remove the following folders

    sudo rm -rf /var/lib/postgresql/sudo rm -rf /var/log/postgresql/sudo rm -rf /etc/postgresql/