From: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
---|---|
To: | Graham Leggett <minfrin(at)sharp(dot)fm> |
Cc: | PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Is there a "right" way to test if a database is empty? |
Date: | 2018-01-17 18:06:31 |
Message-ID: | 20180117180631.zu6lj6b5u4ftsawn@alvherre.pgsql |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Ivan Novick | 2018-01-17 18:16:52 | Re: Builtin connection polling |
Previous Message | Emre Hasegeli | 2018-01-17 17:59:30 | Re: [HACKERS] [PATCH] Improve geometric types |