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

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:49:32
Message-ID: CAKFQuwba99R+y9VOEfS-yFV4p_vDos4bx5CQakuHP1jCWP2Ecw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jan 17, 2018 at 9:39 AM, Graham Leggett <minfrin(at)sharp(dot)fm> wrote:

> 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)
>

​Depends on how you want to define empty. You indicated "after createdb"
and createdb creates the public schema.

David J.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2018-01-17 16:59:41 Re: Unnecessary static variable?
Previous Message Graham Leggett 2018-01-17 16:39:09 Re: Is there a "right" way to test if a database is empty?