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