Re: Function to total reset a schema - Mailing list pgsql-sql

From Thomas Kellerer
Subject Re: Function to total reset a schema
Date
Msg-id irsu3s$4b9$1@dough.gmane.org
Whole thread Raw
In response to Function to total reset a schema  (Surfing <onlinesurfing@gmail.com>)
Responses Re: Function to total reset a schema
List pgsql-sql
Surfing wrote on 29.05.2011 09:38:
> Hi all,
> I need to write a function that totally empty a schema.
>
> So I have written a TRUNCATE statement for each table and set to 0 each sequence.
> Btw, it could be good to execute a vacuum statement on each table, but from within the function this is not allowed.
>
> Is there a way to obtain the same result in another way (without using the vacuum)?
>

If you are only using a single schema in your database, you could create an empty database with all your tables that
youthen use as the template database when creating a new one:
 

Then each time you want to reset your schema (=database) you do a

drop database real_database;
create database real_database template template_database;

Then you don't need to adjust your "reset" script if your database changes (you only maintain the template database
usingyour SQL scripts)
 

Thomas



pgsql-sql by date:

Previous
From: Scott Marlowe
Date:
Subject: Re: Function to total reset a schema
Next
From: Surfing
Date:
Subject: Re: Function to total reset a schema