To expand on Frank's answer, I have done the following to reset PostgreSQL on Ubuntu 14.04 LTS:
sudo service postgresql stop
sudo bash # Root permissions to move the data folder
mv /var/lib/postgresql/9.3/main ~ # Move the database for safety
logout
sudo -u postgres bash
mkdir /var/lib/postgresql/9.3/main
/usr/lib/postgresql/9.3/bin/initdb -D /var/lib/postgresql/9.3/main
sudo service postgresql start
Note that initdb
is not in the system path, and if you try to run it, Ubuntu will suggest you need to install an extension package. However, if you have the server itself installed, the command is still available - just hidden.
I expect this can be modified for other versions of PostgreSQL - just tinker a bit with the version number in the paths.
I could probably have shortened this process a bit by logging on as postgres
for both moving the old database and creating the new one. Note that initdb
will refuse to run as root, so running as postgres
makes sense.
(A reset of this kind is useful for folks coming to this database platform from other systems, such as MySQL. Once you've added roles, users, grants, default privs etc, it is hard to remember what command had what effect. Wiping and trying again removes all doubt).