pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-sql@postgresql.org
Subject: Re: Function to total reset a schema
Date: Sun, 29 May 2011 09:54:41 +0200
Message-ID: <irsu3s$4b9$1@dough.gmane.org> (raw)
In-Reply-To: <4DE1F7DC.3080700@gmail.com>
References: <4DE1F7DC.3080700@gmail.com>

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 you then 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 using your SQL scripts)

Thomas




view thread (6+ messages)  latest in thread

Message-ID: <irsu3s$4b9$1@dough.gmane.org>
Permalink:  ../irsu3s$4b9$1@dough.gmane.org/
Also on:    postgresql.org/message-id/irsu3s$4b9$1@dough.gmane.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: spam_eater@gmx.net
  Subject: Re: Function to total reset a schema
  In-Reply-To: <irsu3s$4b9$1@dough.gmane.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox