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 90E4E6AA-392B-4DA1-B10D-873A0CE6031E@sharp.fm
обсуждение исходный текст
Ответ на 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?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-hackers
On 17 Jan 2018, at 5:47 PM, Graham Leggett <minfrin@sharp.fm> wrote:

I need to test whether a database is empty, in other words “createdb” has been executed but no data of any kind appears in that database.

What is the correct postgresql way to do this?

Is there a pg_isempty command or equivalent somewhere?

Does this query look right?

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?

Regards,
Graham

Вложения

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

Предыдущее
От: Konstantin Knizhnik
Дата:
Сообщение: Builtin connection polling
Следующее
От: Petr Jelinek
Дата:
Сообщение: Re: [PATCH] session_replication_role = replica with TRUNCATE