Re: Is there a "right" way to test if a database is empty?

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: Is there a "right" way to test if a database is empty?
Дата
Msg-id CAKFQuwa8MBs_jMnBixw+GDf-OCsB8cdYbOiPC-GdF-O-a5NnuQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Is there a "right" way to test if a database is empty?  (Graham Leggett <minfrin@sharp.fm>)
Ответы Re: Is there a "right" way to test if a database is empty?  (Graham Leggett <minfrin@sharp.fm>)
Список pgsql-hackers
On Wed, Jan 17, 2018 at 9:10 AM, Graham Leggett <minfrin@sharp.fm> wrote:

db=# select count(s.nspname) from pg_class c join pg_namespace s on s.oid = c.relnamespace where s.nspname in ('public');
 count 
-------
     0
(1 row)

It is based on the idea that the database is not empty if there are any class entries in the “public” namespace?


​That was my original thought - though comparing the size of template1 to the target database should be reasonably safe...

If you do go for object detection you will want to ensure that no schemas other than public exist in addition to ensuring that public is empty.  That doesn't prevent people from installing stuff to pg_catalog but normally only extensions would end up there.

David J.

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: master make check fails on Solaris 10
Следующее
От: Graham Leggett
Дата:
Сообщение: Re: Is there a "right" way to test if a database is empty?