pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
empty a database
7+ messages / 5 participants
[nested] [flat]

* empty a database
@ 2005-02-15 15:51  Dick Davies <rasputnik@hellooperator.net>
  0 siblings, 2 replies; 7+ messages in thread

From: Dick Davies @ 2005-02-15 15:51 UTC (permalink / raw)
  To: pgsql-admin


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...

-- 
'My life, and by extension everyone else's, is meaningless.'
		-- Bender
Rasputin :: Jack of All Trades - Master of Nuns



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: empty a database
@ 2005-02-15 16:31  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Dick Davies <rasputnik@hellooperator.net>
  1 sibling, 1 reply; 7+ messages in thread

From: Tom Lane @ 2005-02-15 16:31 UTC (permalink / raw)
  To: Dick Davies <rasputnik@hellooperator.net>; +Cc: pgsql-admin

Dick Davies <rasputnik@hellooperator.net> writes:
> 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...

Well, if you put everything into one or a few schemas then dropping
and recreating those schemas would do it.  I suspect though that this
is *not* faster than dropdb/createdb.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: empty a database
@ 2005-02-15 16:41  Dick Davies <rasputnik@hellooperator.net>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Dick Davies @ 2005-02-15 16:41 UTC (permalink / raw)
  To: pgsql-admin

* Tom Lane <tgl@sss.pgh.pa.us> [0232 16:32]:
> Dick Davies <rasputnik@hellooperator.net> writes:
> > 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...
> 
> Well, if you put everything into one or a few schemas then dropping
> and recreating those schemas would do it.  I suspect though that this
> is *not* faster than dropdb/createdb.

Thanks Tom.

It's not just the speed, it's the constant deletes and creations in
~pgsql/data - as I said the other day, this is recreating a test db from the
production one as part of unit tests, so this happens dozens of times a day...


-- 
'...and then we wrote scripts to write the configs for us, and using
these scripts, we made mistakes in a faster, more automated manner.'
		-- A Gentle Introduction to Cricket, on MRTG configuration
Rasputin :: Jack of All Trades - Master of Nuns



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: empty a database
@ 2005-02-15 17:24  Naomi Walker <nwalke@eldocomp.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Naomi Walker @ 2005-02-15 17:24 UTC (permalink / raw)
  To: Dick Davies <rasputnik@hellooperator.net>; +Cc: pgsql-admin


How about just truncating all the tables?


Dick Davies wrote:
> * Tom Lane <tgl@sss.pgh.pa.us> [0232 16:32]:
> 
>>Dick Davies <rasputnik@hellooperator.net> writes:
>>
>>>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...
>>
>>Well, if you put everything into one or a few schemas then dropping
>>and recreating those schemas would do it.  I suspect though that this
>>is *not* faster than dropdb/createdb.
> 
> 
> Thanks Tom.
> 
> It's not just the speed, it's the constant deletes and creations in
> ~pgsql/data - as I said the other day, this is recreating a test db from the
> production one as part of unit tests, so this happens dozens of times a day...
> 
> 


-- 
-------------------------------------------------------------------------
Naomi Walker                          Chief Information Officer
Eldorado Computing, Inc.              nwalker@eldocomp.com 602-604-3100
-------------------------------------------------------------------------
Courage is the power to let go the familiar.         -Raymond Lindquist
-------------------------------------------------------------------------

-- CONFIDENTIALITY NOTICE --

This message is intended for the sole use of the individual and entity to whom it is addressed, and may contain information that is privileged, confidential and exempt from disclosure under applicable law. If you are not the intended addressee, nor authorized to receive for the intended addressee, you are hereby notified that you may not use, copy, disclose or distribute to anyone the message or any information contained in the message. If you have received this message in error, please immediately advise the sender by reply email, and delete the message. Thank you.



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: empty a database
@ 2005-02-15 18:56  Christopher Browne <cbbrowne@acm.org>
  parent: Dick Davies <rasputnik@hellooperator.net>
  1 sibling, 1 reply; 7+ messages in thread

From: Christopher Browne @ 2005-02-15 18:56 UTC (permalink / raw)
  To: pgsql-admin

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, <http://svcs.affero.net/rm.php?r=cbbrowne; 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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: empty a database
@ 2005-02-15 19:03  Brad Nicholson <bnichols@ca.afilias.info>
  parent: Naomi Walker <nwalke@eldocomp.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Brad Nicholson @ 2005-02-15 19:03 UTC (permalink / raw)
  To: pgsql-admin

If there are any foreign key constraints, you'll have to truncate the 
tables in the appropriate order.  You would also have to reset the 
sequence values as well.

Naomi Walker wrote:

>How about just truncating all the tables?
>
>
>Dick Davies wrote:
>  
>
>>* Tom Lane <tgl@sss.pgh.pa.us> [0232 16:32]:
>>
>>    
>>
>>>Dick Davies <rasputnik@hellooperator.net> writes:
>>>
>>>      
>>>
>>>>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...
>>>>        
>>>>
>>>Well, if you put everything into one or a few schemas then dropping
>>>and recreating those schemas would do it.  I suspect though that this
>>>is *not* faster than dropdb/createdb.
>>>      
>>>
>>Thanks Tom.
>>
>>It's not just the speed, it's the constant deletes and creations in
>>~pgsql/data - as I said the other day, this is recreating a test db from the
>>production one as part of unit tests, so this happens dozens of times a day...
>>
>>
>>    
>>
>
>
>  
>




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: empty a database
@ 2005-02-16 23:15  Dick Davies <rasputnik@hellooperator.net>
  parent: Christopher Browne <cbbrowne@acm.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Dick Davies @ 2005-02-16 23:15 UTC (permalink / raw)
  To: Christopher Browne <cbbrowne@acm.org>; +Cc: pgsql-admin

* Christopher Browne <cbbrowne@acm.org> [0223 20:23]:
> 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."

It just seems a bit extreme, but the alternatives are all a bit gnarly,
so think I'll live with it....

Thanks for all the suggestions, though, everybody.
 
-- 
'The old 'give em a Linux box and they think they're Jean-Luc Picard' syndrome.'
		-- Pete Bentley
Rasputin :: Jack of All Trades - Master of Nuns



^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2005-02-16 23:15 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-02-15 15:51 empty a database Dick Davies <rasputnik@hellooperator.net>
2005-02-15 16:31 ` Tom Lane <tgl@sss.pgh.pa.us>
2005-02-15 16:41   ` Dick Davies <rasputnik@hellooperator.net>
2005-02-15 18:56 ` Christopher Browne <cbbrowne@acm.org>
2005-02-16 23:15   ` Dick Davies <rasputnik@hellooperator.net>
2005-02-15 17:24 Re: empty a database Naomi Walker <nwalke@eldocomp.com>
2005-02-15 19:03 ` Brad Nicholson <bnichols@ca.afilias.info>

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