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

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема Re: Is there a "right" way to test if a database is empty?
Дата
Msg-id 20180117180631.zu6lj6b5u4ftsawn@alvherre.pgsql
обсуждение исходный текст
Ответ на Is there a "right" way to test if a database is empty?  (Graham Leggett <minfrin@sharp.fm>)
Список pgsql-hackers
Graham Leggett wrote:
> Hi all,
> 
> 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.

Why do you want to know?

Depends on how you define empty.  If a few functions exist but no
tables, is the database empty?  I'd say no.  One possible approach is:
if no relations (pg_class rows) exist in namespaces other than
pg_catalog, pg_toast, information_schema; and no functions (pg_proc
rows) exist in any schema other than those three, then the database is
empty.  There are a few object types you could create without any
relation and without any function (such as casts, or schemas, or text
search objects) but you probably don't care.

Maybe make sure no extensions are installed also.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


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

Предыдущее
От: Emre Hasegeli
Дата:
Сообщение: Re: [HACKERS] [PATCH] Improve geometric types
Следующее
От: Ivan Novick
Дата:
Сообщение: Re: Builtin connection polling