Question
Is there a way to completely reset a PostgreSQL installation on Linux, so it is in the same state as when I installed it?
Idea
I have considered
rm -rf /var/lib/pgsql/*
rm -rf /var/lib/pgsql/backups/*
rm -rf /var/lib/pgsql/data/*
but perhaps that is not a recommended method.
Purpose
This would be handy to get rid of left overs from previous programs that have used it.
It all depends on how it was installed.
Ubuntu, from packages (built-in or apt.postgresql.org)
Use
pg_wrapper
. See the Ubuntu docs for PostgreSQL. You want topg_dropcluster
all existing Pg clusters, thenpg_createcluster
a clean new one.Do not just delete the data dir and re-initdb.
CentOS/RH/Fedora, built-in packages
I don't have this installed and can't easily test right now. From memory I think it's safe to just stop the server and delete the data dir.
CentOS/RH/Fedora, yum.postgresql.org packages
See
/usr/share/doc/postgresql??-?.?.?/README.rpm-dist
.Stop the server with
systemctl
or theservice
wrapper command, delete the data dir, then run/usr/pgsql-9.3/bin/postgresql93-setup initdb
(adjusting paths as appropriate for your version).Any distro, from EDB installer
Stop the server, delete the data dir and
initdb
a new cluster. See the installer docs.From source
Stop server, delete data dir, re-initdb.
OS X
Homebrew:
brew uninstall postgresql; brew cleanup; brew install postgresql
Postgres.app? EDB installer? MacPorts?
Find a beer. Drink the beer. Repeat. If this doesn't make the pain go away, get something stronger.
Windows
runas.exe
as the postgres user (pre-9.2) orNETWORKSERVICE
(9.2+). Or just change the ownership afterwards.That should do it - just make sure first that the current configuration actually does store the files in those directories.
Once it's done, re-initiate the database:
Isn't it best to just remove and reinstall?
That way you'll get the latest version and update any dependences along the way.
Run: sudo apt-get --purge remove postgresql
Then: sudo apt-get install postgresql