Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to bring postgresql back to its original empty state.

On Ubuntu:

$ sudo service postgresql stop
$ sudo apt-get purge postgresql*

Followed by

$ sudo apt-get install postgresql

Does what I want, but is there any less brutal way of doing the same thing?

What I actually want to do is to check that I can re-create my database from scratch.

share|improve this question

3 Answers 3

up vote 4 down vote accepted

Use initdb, creates a new PostgreSQL database cluster. That includes postgresql.conf and pg_hba.conf as well.

share|improve this answer
    
Frank is right, that's the postgres way to reset the system. +1 –  lynxman Feb 9 '11 at 16:34
    
This looks good, but the command doesn't seem to exist in ubuntu! –  John Lawrence Aspden Feb 9 '11 at 19:54
1  
It's under /usr/lib/postgresql/x.y/bin/. –  Peter Eisentraut Feb 9 '11 at 21:48

Like Khaled said, you could just issue drop database, drop user, etc. Statements to clean up all changes made to the initial Database.

For the Database Configuration you might be interested in just putting the files under version control (git,svn &co).

For Subversion you could do something like this:

Install Subversion

$ sudo apt-get install subversion

Setup the Repository

$ mkdir ~/pgsqlsvn
$ svnadmin create 

Stop the Service

$ sudo service postgresql stop

Initially fill the repository:

$ cd /etc/postgresql
$ sudo svn co file:///home/you/pgsqlsvn ./
$ sudo svn add * 
$ sudo svn commit 

Reverting the Configuration Afterwards

Everytime you need to reset to the initital Database configuration you can just

$ sudo svn update /etc/postgresql -r 1
share|improve this answer

First, I have to guess what you mean by "reset"!

If you mean the data, you can just drop all databases using the known SQL statement drop database.

If you mean the configuration, I think it is a good way to remove and re-install it with a fresh config files unless you have an old backup.

share|improve this answer

Your Answer

 
discard

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.