How to drop automatically some databases?

Поиск
Список
Период
Сортировка
От Andreas
Тема How to drop automatically some databases?
Дата
Msg-id 553B839F.2040503@gmx.net
обсуждение исходный текст
Ответы Re: How to drop automatically some databases?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-admin
I've got a developer PC (Windows) that hosts copies of a production
database so I can tinker with it without causing damage to the
production database.

Every night a script fetches a dump of the production database.
Then it renames the test-db on my PC, creates a new test-db and imports
the dump.

The current version is named "db_test".
The older copies are named "db_test_yymmdd_hhmm". The name is extended
with the timestamp of the import.

Now I'd like to keep just 3 older copies in case I want to look up
structural moifications I've made the day before.
Older copies should get dropped.


This would show the names to drop.

select  datname
from    (
             select      datname
             from        pg_database
             where       datname ilike 'db_test_%'
             order by    datname
         )   as  x

EXCEPT
select  datname
from    (
             select      datname
             from        pg_database
             where       datname ilike 'db_test_%'
             order by    datname     desc
             limit       3
         )   as  y;


I tried to run this

drop database ( ... the select above ... )

in the DB "postgres" but it didn't work.
After a couple of seconds I get a syntax error.

What now?   :}


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

Предыдущее
От: danny
Дата:
Сообщение: Re: server doesn't listen postgresql 9.1 after service change
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: How to drop automatically some databases?