Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 183ADB5DBD6 for ; Sun, 29 May 2011 05:03:46 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 60434-03 for ; Sun, 29 May 2011 08:03:38 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mail.postgresql.org (Postfix) with ESMTP id 5081FB5DBD5 for ; Sun, 29 May 2011 05:03:38 -0300 (ADT) Received: by wwc33 with SMTP id 33so2754604wwc.19 for ; Sun, 29 May 2011 01:03:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=G7tZYmGqqqTQCh+Ovh4NM1g1Z9fWA189P4IWexlmXVs=; b=xLRLNDRB2aV40NgMkLUurjqSRI5KGQDbCDHYMuHe734FYotLCVjN50COfrqme6+yad Vlees9HFibgxRKugm8ymF6anKQ/DhtvPBTPYUhPXzOpJfUnT5KsvnGpMwruY3XNlhn40 OpKlksQDh9wAYmiTBbcD7xLBFjd9KLUOZ8ABk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=WWWjl4dmCoReYgBxQDkK/TDspzXCoBrCt3DxuYYmG8JjftCayBqPLAM5NfuqIDgGmg ye+VlGBi/0AfxxCt2KjUM9n/lQF3v2BPcSyFDF56JPsi3hNfEuh99yieMxt4MD5sjrBy 6WY92NUrCfAm5qppCQJq3b+L4WnCZfGLYfR7A= Received: by 10.216.16.32 with SMTP id g32mr1307599weg.0.1306656217726; Sun, 29 May 2011 01:03:37 -0700 (PDT) Received: from [192.168.1.100] (host228-237-dynamic.211-62-r.retail.telecomitalia.it [62.211.237.228]) by mx.google.com with ESMTPS id gb6sm2274407wbb.17.2011.05.29.01.03.36 (version=SSLv3 cipher=OTHER); Sun, 29 May 2011 01:03:37 -0700 (PDT) Message-ID: <4DE1FDD8.2080309@gmail.com> Date: Sun, 29 May 2011 10:03:36 +0200 From: Surfing User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; it; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Function to total reset a schema References: <4DE1F7DC.3080700@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.888 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201105/177 X-Sequence-Number: 35461 I have two schemas, so I can't do that ... @ Scott. You are totally right ... I have just read this on the documentation: "TRUNCATE quickly removes all rows from a set of tables. It has the same effect as an unqualified DELETE on each table, but since it does not actually scan the tables it is faster. Furthermore, it reclaims disk space immediately, rather than requiring a subsequent VACUUM operation. This is most useful on large tables." So the VACUUM should not really be necessary..thanks. Il 29/05/2011 09:54, Thomas Kellerer ha scritto: > 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 > >