Completely reset PostgreSQL to default?

Solution 1:

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 to pg_dropcluster all existing Pg clusters, then pg_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 the service 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

  • Stop service
  • Delete data dir
  • re-run initdb using runas.exe as the postgres user (pre-9.2) or NETWORKSERVICE (9.2+). Or just change the ownership afterwards.

Solution 2:

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:

sudo -U pgsql initdb

Solution 3:

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