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

Поиск
Список
Период
Сортировка
От Graham Leggett
Тема Re: Is there a "right" way to test if a database is empty?
Дата
Msg-id EC1D397E-6EBF-4E99-B8B8-EB6F79C88655@sharp.fm
обсуждение исходный текст
Ответ на Re: Is there a "right" way to test if a database is empty?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Ответы Re: Is there a "right" way to test if a database is empty?
Список pgsql-hackers
On 17 Jan 2018, at 6:34 PM, David G. Johnston <david.g.johnston@gmail.com> wrote:

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

What led me here was this, which didn’t work for me, although the idea to not just assume the default namespace is valid:


Would it be true to say that if this query returned more than zero rows the database is not empty?

db=# select distinct s.nspname from pg_class c join pg_namespace s on s.oid = c.relnamespace where s.nspname not in ('pg_toast','information_schema','pg_catalog');
 nspname 
---------
 public
(1 row)

Regards,
Graham
--

Вложения

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

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: 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?