Wednesday, August 30, 2017

PostgreSQL: find non-empty tables

Source: https://stackoverflow.com/questions/24734489/show-all-not-empty-tables-in-postgres
SELECT n.nspname, c.relname                                                                                                                                                                           
FROM pg_class c
INNER JOIN pg_namespace n ON (n.oid = c.relnamespace)
WHERE c.reltuples != 0 AND c.relkind = 'r' and nspname ~ '_db$'