X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D47578BA326 for ; Tue, 15 Feb 2005 20:16:29 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 11517-04 for ; Tue, 15 Feb 2005 20:16:24 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id 227138BA1DE for ; Tue, 15 Feb 2005 20:16:24 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.13.1/8.13.1) with ESMTP id j1FKGJRB039680 for ; Tue, 15 Feb 2005 20:16:21 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.13.1/8.13.1/Submit) id j1FJo9Nu034127 for pgsql-admin@postgresql.org; Tue, 15 Feb 2005 19:50:09 GMT (envelope-from news) From: Christopher Browne X-Newsgroups: pgsql.admin Subject: Re: empty a database Date: Tue, 15 Feb 2005 13:56:44 -0500 Organization: cbbrowne Computing Inc Lines: 53 Message-ID: References: <20050215155148.GZ63378@eris.tenfour> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.hub.org X-message-flag: Outlook is rather hackable, isn't it? X-Home-Page: http://www.cbbrowne.com/info/ X-Affero: http://svcs.affero.net/rm.php?r=cbbrowne User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4 (Corporate Culture, linux) Cancel-Lock: sha1:JnPWZaUDDTX4Pzg4yB9rH+hSjns= To: pgsql-admin@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Archive-Number: 200502/128 X-Sequence-Number: 16296 Clinging to sanity, rasputnik@hellooperator.net (Dick Davies) mumbled into her beard: > Is there a neat way to clean out a database via SQL commands? > > i.e. get rid of tables, sequences, integers, etc. > > At present I'm using dropdb/createdb, but thats' far from ideal > and I think it's causing postgres to do more mork than it needs to... If you truly need for all of the objects to go away, dropping the database seems like a reasonable way to do this. I'm not sure what work you are imagining is "too much" or "unnecessary." If you're regularly recreating a not-totally-empty database, containing some set of "fresh" tables/sequences/views/such, then I'd think you're doing the right thing, but need to take a further step... If you're recreating a database that has some non-zero "initial configuration," then what you might do is to set up a 'template' database, let's call it "mytemplate" that contains that configuration. Then you can do the following: $ createdb --template=mytemplate mydatabase CREATE DATABASE $ do_some_work_with mydatabase $ dropdb mydatabase DROP DATABASE $ createdb --template=mytemplate mydatabase CREATE DATABASE $ do_some_work_with mydatabase $ dropdb mydatabase DROP DATABASE $ createdb --template=mytemplate mydatabase CREATE DATABASE $ do_some_work_with mydatabase $ dropdb mydatabase DROP DATABASE $ createdb --template=mytemplate mydatabase CREATE DATABASE $ do_some_work_with mydatabase $ dropdb mydatabase DROP DATABASE $ createdb --template=mytemplate mydatabase CREATE DATABASE $ do_some_work_with mydatabase $ dropdb mydatabase DROP DATABASE -- If this was helpful, rate me http://linuxdatabases.info/~cbbrowne/slony.html "Wintel: A Wasteland of Useless Software - If the bazillions of programs out there actually amount to something, why is everyone using MICROS~1 Office, Word, Excel, PowerPoint, Access, ..." -- cbbrowne@hex.net