Re: empty a database

Поиск
Список
Период
Сортировка
От Christopher Browne
Тема Re: empty a database
Дата
Msg-id m3y8dpodn7.fsf@knuth.knuth.cbbrowne.com
обсуждение исходный текст
Ответ на empty a database  (Dick Davies <rasputnik@hellooperator.net>)
Ответы Re: empty a database  (Dick Davies <rasputnik@hellooperator.net>)
Список 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

В списке pgsql-admin по дате отправления:

Предыдущее
От: "Joel Fradkin"
Дата:
Сообщение: who is best for support?
Следующее
От: Scott Marlowe
Дата:
Сообщение: Re: who is best for support?