Re: Is there a "right" way to test if a database is empty? - Mailing list pgsql-hackers

From David G. Johnston
Subject Re: Is there a "right" way to test if a database is empty?
Date
Msg-id CAKFQuwba99R+y9VOEfS-yFV4p_vDos4bx5CQakuHP1jCWP2Ecw@mail.gmail.com
Whole thread Raw
In response to Re: Is there a "right" way to test if a database is empty?  (Graham Leggett <minfrin@sharp.fm>)
List pgsql-hackers
On Wed, Jan 17, 2018 at 9:39 AM, Graham Leggett <minfrin@sharp.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.

pgsql-hackers by date:

Previous
From: Graham Leggett
Date:
Subject: Re: Is there a "right" way to test if a database is empty?
Next
From: Tom Lane
Date:
Subject: Re: Unnecessary static variable?