From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
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 16:34:11 |
Message-ID: | CAKFQuwa8MBs_jMnBixw+GDf-OCsB8cdYbOiPC-GdF-O-a5NnuQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Wed, Jan 17, 2018 at 9:10 AM, Graham Leggett <minfrin(at)sharp(dot)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.
From | Date | Subject | |
---|---|---|---|
Next Message | Graham Leggett | 2018-01-17 16:39:09 | Re: Is there a "right" way to test if a database is empty? |
Previous Message | Tom Lane | 2018-01-17 16:33:09 | Re: master make check fails on Solaris 10 |