Getting tables with no rows without counting
I got a huge PostgreSQL database with lots of tables. I want learn all empty tables without counting each tables for performance reasons (Some of the tables have several millions 开发者_StackOverflowrows).
This query will give you an approximate result, but does not include counting table rows.
SELECT relname FROM pg_class JOIN pg_namespace ON (pg_class.relnamespace = pg_namespace.oid) WHERE relpages = 0 AND pg_namespace.nspname = 'public';
This will work best after a VACUUM ANALYZE
.
as per http://wiki.postgresql.org/wiki/Slow_Counting , one solution is to first find the tables with small 'reltuples' via
select relname from pg_class where reltuples < X
and then test for emptiness only those.
so u want to see table structure, right? try pg admin
u can open table and see all structure eg datatype, index, function and etc
精彩评论