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

From: hubert depesz lubaczewski <depesz(at)depesz(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-18 11:04:24
Message-ID: 20180118110424.GA1012@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jan 17, 2018 at 05:47:16PM +0200, Graham Leggett wrote:
> 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.
> What is the correct postgresql way to do this?

There is none, because it highly depends on how you'll define empty.

Please note that even directly after "create database x;" your db might
not be empty, if you had some things created earlier in template1.

Best regards,

depesz

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2018-01-18 11:14:51 Re: [HACKERS] Planning counters in pg_stat_statements
Previous Message Amit Langote 2018-01-18 10:56:47 Re: [Sender Address Forgery]Re: [Sender Address Forgery]Re: [Sender Address Forgery]Re: [HACKERS] path toward faster partition pruning