Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have messed around with the template1 database, and would like to reset everything as it was.

Hence I have done a sudo apt-get purge postgresql

However the next time I reinstalled it, the databases are still there. Why? Nothing has been reset.

share|improve this question
Possible Duplicate:… – Mitch Jul 7 '12 at 9:16
up vote 3 down vote accepted

When you create your databases, the datafiles for this databases are created. These are (of course) not being purged by apt purge.

If /etc/postgresql/8.4/main/postgresql.conf (presumably it is not 8.4 - use your version`) still exists, you can find a line like

data_directory = '/var/lib/postgresql/8.4/main' # use data in another directory

There you can find the datafiles for your created databases. If you created your own data directories, I believe you remember where they were.

Does the user postgresql still exist? This is the owner of the database files. Delete this user with searching for all his files (use sth like deluser --remove-all-files, man deluser helps you). If this user does not exist, find all files in your filesystem that don't have an associated user and maybe delete them. (Use find / -nouser -nogroup - and again, read man find:-) )

For more information, consult the wonderful postgresql documentation.

share|improve this answer

You don't need to puge and re-install PostgreSQL for that.

sudo -u postgres psql postgres
drop database template1;
create database template1 template template0;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.